Package org.agrona.concurrent
Class NoOpIdleStrategy
- java.lang.Object
-
- org.agrona.concurrent.NoOpIdleStrategy
-
- All Implemented Interfaces:
IdleStrategy
public final class NoOpIdleStrategy extends java.lang.Object implements IdleStrategy
Low-latency idle strategy to be employed in loops that do significant work on each iteration such that any work in the idle strategy would be wasteful.The
NoOpIdleStrategy
should be used with care:- It could increase power consumption.
- The increased power consumption could lead to thermal throttling causing an overall performance drop.
- It could consume resources that otherwise would be used by the hyper-sibling.
- It could lead to a memory order violation at the end of the loop causing a pipeline reset.
BusySpinIdleStrategy
might be a better alternative in some scenarios. That being said, usingNoOpIdleStrategy
is perfectly fine if the underlying duty cycle loops is performing syscalls (e.g. in sender and receiver threads in Aeron).
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALIAS
Name to be returned fromalias()
.static NoOpIdleStrategy
INSTANCE
As there is no instance state then this object can be used to save on allocation.
-
Constructor Summary
Constructors Constructor Description NoOpIdleStrategy()
Create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
alias()
Simple name by which the strategy can be identified.void
idle()
Note: this implementation will result in no safepoint poll once inlined.void
idle(int workCount)
Note: this implementation will result in no safepoint poll once inlined.void
reset()
Reset the internal state in preparation for entering an idle state again.java.lang.String
toString()
-
-
-
Field Detail
-
ALIAS
public static final java.lang.String ALIAS
Name to be returned fromalias()
.- See Also:
- Constant Field Values
-
INSTANCE
public static final NoOpIdleStrategy INSTANCE
As there is no instance state then this object can be used to save on allocation.
-
-
Method Detail
-
idle
public void idle(int workCount)
Note: this implementation will result in no safepoint poll once inlined.Perform current idle action (e.g. nothing/yield/sleep). This method signature expects users to call into it on every work 'cycle'. The implementations may use the indication "workCount > 0" to reset internal backoff state. This method works well with 'work' APIs which follow the following rules:
- 'work' returns a value larger than 0 when some work has been done
- 'work' returns 0 when no work has been done
- 'work' may return error codes which are less than 0, but which amount to no work has been done
Callers are expected to follow this pattern:
while (isRunning) { idleStrategy.idle(doWork()); }
- Specified by:
idle
in interfaceIdleStrategy
- Parameters:
workCount
- performed in last duty cycle.
-
idle
public void idle()
Note: this implementation will result in no safepoint poll once inlined.Perform current idle action (e.g. nothing/yield/sleep). To be used in conjunction with
IdleStrategy.reset()
to clear internal state when idle period is over (or before it begins). Callers are expected to follow this pattern:while (isRunning) { if (!hasWork()) { idleStrategy.reset(); while (!hasWork()) { if (!isRunning) { return; } idleStrategy.idle(); } } doWork(); }
- Specified by:
idle
in interfaceIdleStrategy
-
reset
public void reset()
Reset the internal state in preparation for entering an idle state again.- Specified by:
reset
in interfaceIdleStrategy
-
alias
public java.lang.String alias()
Simple name by which the strategy can be identified.- Specified by:
alias
in interfaceIdleStrategy
- Returns:
- simple name by which the strategy can be identified.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-