-
Notifications
You must be signed in to change notification settings - Fork 227
Wait Strategies
Each Disruptor has a single wait strategy (IWaitStrategy) that is responsible to notify processors of new events.
Please note that the wait strategy is both responsible to notify of new events and to wait until dependent sequences are available, i.e.: that previous event handlers have processed the event. The API allows signalling of new events, but not signalling of sequence availability. Thus all wait strategies, even blocking ones, must rely on variations of spin waiting to wait for sequence availability. This spin waiting can generate high CPU usage that is a common source of issues from users.
A few wait strategies use System.Threading.SpinWait
. This synchronization type is implemented using a mix of Thread.SpinWait
, Thread.Yield
, Thread.Sleep(0)
and Thread.Sleep(1)
. On Windows, the thread pause duration cannot be less than the system timer resolution, which is 15.6 ms by default. So a call to Thread.Sleep(1)
can generate pauses of 15.6 ms. To avoid this issue, the Disruptor often uses its own synchronization type, AggressiveSpinWait, which does not call Thread.Sleep(1)
.
Uses Monitor.Wait
and Monitor.Pulse
to notify of new events and then busy spins to wait for dependent sequences.
This is the default wait strategy.
Uses Monitor.Wait
and Monitor.Pulse
to notify of new events and then uses System.Threading.SpinWait
to wait for dependent sequences.
This strategy should not generate high CPU usage.
Busy spins to wait for new events and dependent sequences.
Uses a mix of Thread.Yield
and Thread.Sleep(0)
to wait for new events and dependent sequences.
Uses Thread.Yield
to wait for new events and dependent sequences.
Uses System.Threading.SpinWait
to wait for new events and dependent sequences.
This strategy should not generate high CPU usage.