Class BackoffIdleStrategy
- All Implemented Interfaces:
IdleStrategy
Spin for maxSpins, then
Thread.yield()
for maxYields, then
LockSupport.parkNanos(long)
on an exponential backoff to maxParkPeriodNs.
Under Linux, multiple timer events will be coalesced in a 50 us window to minimize the timer overhead
on the CPU. E.g. if you want to wait 10 us, it could be you need to wait 50us. This situation can be
improved by changing the value of the timerslack_ns property which defaults to 50000. This can be done
like this:
echo 10000 > /proc/PID/timerslack_ns
This will set the timer slack to 10 microseconds for the given PID of the thread. This property
can't be set at the process level, so needs to be set for each thread specifically. Also, it isn't
guaranteed that after setting the property, the waiting time will be respected.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Name to be returned fromalias()
.static final long
Default maximum interval the strategy will park a thread.static final long
Default number of times the strategy will spin without work before going to next state.static final long
Default number of times the strategy will yield without work before going to next state.static final long
Default minimum interval the strategy will park a thread.(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
Fields inherited from class org.agrona.concurrent.BackoffIdleStrategyData
maxParkPeriodNs, maxSpins, maxYields, minParkPeriodNs, NOT_IDLE, PARKING, parkPeriodNs, SPINNING, spins, state, YIELDING, yields
Fields inherited from class org.agrona.concurrent.BackoffIdleStrategyPrePad
p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015, p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031, p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047, p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor usingDEFAULT_MAX_SPINS
,DEFAULT_MAX_YIELDS
,DEFAULT_MIN_PARK_PERIOD_NS
, andDEFAULT_MAX_YIELDS
.BackoffIdleStrategy
(long maxSpins, long maxYields, long minParkPeriodNs, long maxParkPeriodNs) Create a set of state tracking idle behavior. -
Method Summary
Modifier and TypeMethodDescriptionalias()
Simple name by which the strategy can be identified.void
idle()
Perform current idle action (e.g.void
idle
(int workCount) Perform current idle action (e.g.void
reset()
Reset the internal state in preparation for entering an idle state again.toString()
-
Field Details
-
ALIAS
Name to be returned fromalias()
.- See Also:
-
DEFAULT_MAX_SPINS
public static final long DEFAULT_MAX_SPINSDefault number of times the strategy will spin without work before going to next state.- See Also:
-
DEFAULT_MAX_YIELDS
public static final long DEFAULT_MAX_YIELDSDefault number of times the strategy will yield without work before going to next state.- See Also:
-
DEFAULT_MIN_PARK_PERIOD_NS
public static final long DEFAULT_MIN_PARK_PERIOD_NSDefault minimum interval the strategy will park a thread.- See Also:
-
DEFAULT_MAX_PARK_PERIOD_NS
public static final long DEFAULT_MAX_PARK_PERIOD_NSDefault maximum interval the strategy will park a thread.- See Also:
-
p064
byte p064 -
p065
byte p065 -
p066
byte p066 -
p067
byte p067 -
p068
byte p068 -
p069
byte p069 -
p070
byte p070 -
p071
byte p071 -
p072
byte p072 -
p073
byte p073 -
p074
byte p074 -
p075
byte p075 -
p076
byte p076 -
p077
byte p077 -
p078
byte p078 -
p079
byte p079 -
p080
byte p080 -
p081
byte p081 -
p082
byte p082 -
p083
byte p083 -
p084
byte p084 -
p085
byte p085 -
p086
byte p086 -
p087
byte p087 -
p088
byte p088 -
p089
byte p089 -
p090
byte p090 -
p091
byte p091 -
p092
byte p092 -
p093
byte p093 -
p094
byte p094 -
p095
byte p095 -
p096
byte p096 -
p097
byte p097 -
p098
byte p098 -
p099
byte p099 -
p100
byte p100 -
p101
byte p101 -
p102
byte p102 -
p103
byte p103 -
p104
byte p104 -
p105
byte p105 -
p106
byte p106 -
p107
byte p107 -
p108
byte p108 -
p109
byte p109 -
p110
byte p110 -
p111
byte p111 -
p112
byte p112 -
p113
byte p113 -
p114
byte p114 -
p115
byte p115 -
p116
byte p116 -
p117
byte p117 -
p118
byte p118 -
p119
byte p119 -
p120
byte p120 -
p121
byte p121 -
p122
byte p122 -
p123
byte p123 -
p124
byte p124 -
p125
byte p125 -
p126
byte p126 -
p127
byte p127
-
-
Constructor Details
-
BackoffIdleStrategy
public BackoffIdleStrategy()Default constructor usingDEFAULT_MAX_SPINS
,DEFAULT_MAX_YIELDS
,DEFAULT_MIN_PARK_PERIOD_NS
, andDEFAULT_MAX_YIELDS
. -
BackoffIdleStrategy
public BackoffIdleStrategy(long maxSpins, long maxYields, long minParkPeriodNs, long maxParkPeriodNs) Create a set of state tracking idle behavior.- Parameters:
maxSpins
- to perform before moving toThread.yield()
maxYields
- to perform before moving toLockSupport.parkNanos(long)
minParkPeriodNs
- to use when initiating parkingmaxParkPeriodNs
- to use when parking
-
-
Method Details
-
idle
public void idle(int workCount) 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()Perform current idle action (e.g. nothing/yield/sleep). To be used in conjunction withIdleStrategy.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
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
-