Concurrency message queue in c++ 002

 

Introduction

Previously, I have a speed test for different concurrency message queue. Please find details here. Now, in this post, I would like to have a comparison between different message queue in a special condition --- 1 producer and multiple consumer.

In this speed test, we compare these candidates:

  • MsgQLockFree_1PMC_Linux
  • MsgQOneLock_RingBuf_Linux
  • MsgQTwoLock_RingBuf_Linux
  • MsgQOneLock_RingBuf_Std
  • MsgQTwoLock_RingBuf_Std
  • MsgQOneLock_LinkList_Linux
  • MsgQTwoLock_LinkList_Linux
  • MsgQOneLock_LinkList_Std
  • MsgQTwoLock_LinkList_Std
  • MsgQOneLock_Queue_Linux
  • MsgQOneLock_Queue_Std

Please refer to the previous blog post for the high level description of the message queue. In this blog post, I will only add description for MsgQLockFree_1PMC_Linux.

Implementation

MsgQLockFree_1PMC_Linux

The original lock free message queue only support 1 input thread and 1 output thread. In this implementation, I group multiple queue together so that we are able to support multiple output threads. Each thread has its own message queue in order to reduce the contention.

Result

Compare message queue structure --- ring

Above result is comparing different lock implementation with the same ring buffer. Clearly, 2 locks implementation is better than 1 lock, lock free is the best since we duplicated the queue number in order to reduce the contention issue.

Compare message queue structure --- linklist

We have a similar result. 2 locks implementation is better than 1 lock.

Compare message queue structure --- ring, linklist, queue

By comparing all structures, it is clear that the contention issue become more and more obvious in 1 lock structure. The lock free implementation clearly not affected by the number of threads.

Compare linux and std

Here shows the compression between standard library and linux library. There is not significant difference.

Comments