quic icon indicating copy to clipboard operation
quic copied to clipboard

Many uses of unbounded queues (TQueue)

Open infinity0 opened this issue 3 years ago • 1 comments

There are many uses of TQueue in this codebase, which is an unbounded queue. This effectively negates flow-control, as the consumer has no way to tell the producer to slow down, and the queue grows without bound by design.

You might not notice any problems during most normal system loads, but it can cause hard-to-debug problems during heavy load - the scheduler generally cannot figure out which consumers need to be run more often than which producers to keep the queue sizes down and so the queues may run out of memory.

The solution is not simple; generally one ought to replace the queue with a bounded queue, but depending on the relationship between the producers and consumers setting the appropriate bound is not obvious and case-dependent. If it is set too low, deadlocks can occur, e.g. if two threads have two queues between them in opposite directions, this is a cyclic relationship and can deadlock depending precisely on how the production / consumption depend on each other.

infinity0 avatar Nov 24 '20 14:11 infinity0