cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
10.03k stars 1.69k forks source link

worse than locked queue #399

Open 396848385 opened 1 month ago

396848385 commented 1 month ago

I tried using this lock free queue in our program, but the performance of the task was even worse.

Our program scenario involves multiple queues, each with a fixed number of elements. After an element is retrieved by wait_dequeue, the program performs other operations and then enqueues the element. The purpose of this is to avoid repeatedly creating objects or to block threads in some scenarios to prevent too many threads from executing a logic at the same time

What I want to know is why the performance of this lock free queue is worse than the locked queue that our program already has

cameron314 commented 1 month ago

Hard to say why without sample code to investigate.

396848385 commented 1 month ago

image like this

396848385 commented 1 month ago

and this image

cameron314 commented 1 month ago

That's a start. I see you're using integers. Are you using tokens? What sort of contention is there?

396848385 commented 1 month ago

Only a very few scenarios use integer no using tokens. Basically, it's the same usage as the two images above, but after using this lock free queue, my training task time has greatly increased. Do you know what possible reasons are causing this

cameron314 commented 1 month ago

For the non-integer types, do they have no-except move constructors? Are they being moved? Consider using producer and consumer tokens. I also encourage you to profile the code to see where the overhead is.