Package org.nustaq.kontraktor.impl
Class BackOffStrategy
java.lang.Object
org.nustaq.kontraktor.impl.BackOffStrategy
public class BackOffStrategy
extends java.lang.Object
Created by moelrue on 06.05.2014.
Kontraktor uses spinlocking. By adjusting the backofstrategy values one can define the tradeoff
regarding latency/idle CPU load.
if a message queue is empty, first busy spin is used for N iterations, then Thread.all, then LockSupport.park, then sleep(nanosToPark)
Note that default constants are public static, so one can globally trade higher latency against lower cpu (polling) load
-
Field Summary
Fields Modifier and Type Field Description static intPARK_UNTIL_SLEEPstatic intSLEEP_NANOSstatic intSPIN_UNTIL_YIELDstatic intYIELD_UNTIL_PARK -
Constructor Summary
Constructors Constructor Description BackOffStrategy()BackOffStrategy(int spinUntilYield, int yieldUntilPark, int parkUntilSleep) -
Method Summary
Modifier and Type Method Description intgetNanosToPark()booleanisSleeping(int yieldCount)booleanisYielding(int count)voidkYield(int count)voidsetCounters(int spinUntilYield, int yieldUntilPark, int parkUntilSleep)BackOffStrategysetNanosToPark(int nanosToPark)
-
Field Details
-
SLEEP_NANOS
public static int SLEEP_NANOS -
SPIN_UNTIL_YIELD
public static int SPIN_UNTIL_YIELD -
YIELD_UNTIL_PARK
public static int YIELD_UNTIL_PARK -
PARK_UNTIL_SLEEP
public static int PARK_UNTIL_SLEEP
-
-
Constructor Details
-
BackOffStrategy
public BackOffStrategy() -
BackOffStrategy
public BackOffStrategy(int spinUntilYield, int yieldUntilPark, int parkUntilSleep)- Parameters:
spinUntilYield- - number of busy spins until Thread.yield is usedyieldUntilPark- - number of Thread.yield iterations until parkNanos(1) is usedparkUntilSleep- - number of parkNanos(1) is used until park(nanosToPark) is used. Default for nanosToPark is 0.5 milliseconds
-
-
Method Details
-
setCounters
public void setCounters(int spinUntilYield, int yieldUntilPark, int parkUntilSleep) -
getNanosToPark
public int getNanosToPark() -
setNanosToPark
-
kYield
public void kYield(int count) -
isSleeping
public boolean isSleeping(int yieldCount) -
isYielding
public boolean isYielding(int count)
-