Class BackOffStrategy

java.lang.Object
org.nustaq.kontraktor.impl.BackOffStrategy

public class BackOffStrategy extends 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 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 used
      yieldUntilPark - - number of Thread.yield iterations until parkNanos(1) is used
      parkUntilSleep - - 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

      public BackOffStrategy setNanosToPark(int nanosToPark)
    • kYield

      public void kYield(int count)
    • isSleeping

      public boolean isSleeping(int yieldCount)
    • isYielding

      public boolean isYielding(int count)