max0x7ba / atomic_queue

C++ lockless queue.
MIT License
1.51k stars 180 forks source link

CPU load at 100% #40

Closed visstup closed 2 years ago

visstup commented 2 years ago

Hi,

I'm writing a high-performance consumer of real-time messages and need a thread-safe, fast queue. I've implemented the AtomicQueueB in my application and noticed that one or more CPUs are always at 100% load during runtime. When running the example.cc with unsigned constexpr N = std::numeric_limits<unsigned>::max() - 10; // Pass this many elements from producers to consumers. I noticed similar behaviour.

Is this normal? If no, any ideas on how to set up the queue so it doesn't exhibit the load? I didn't disable real-time thread throttling.

Also, if the tasks are pinned to a specific core, is it possible to disable this? My application needs to run in the cloud (only virtual cores available there...)

Compiled with g++ 9.3.1 with C++14

max0x7ba commented 2 years ago

The queues here are non-blocking, that's why you observe 100% CPU usage.

You sound surprised. I suggest you read the README and about thread-safe queues in general.

xsacha commented 1 year ago

The spin lock is designed from a latency perspective (for HFT). For other use-cases this is not desirable for obvious reasons. I'd suggest changing the spin_loop_pause @visstup or even using a different queue (as this one is entirely designed for latency and may not be the best for other situations).