org.camunda.bpm.engine.impl.jobexecutor
Class BackoffJobAcquisitionStrategy

java.lang.Object
  extended by org.camunda.bpm.engine.impl.jobexecutor.BackoffJobAcquisitionStrategy
All Implemented Interfaces:
JobAcquisitionStrategy

public class BackoffJobAcquisitionStrategy
extends Object
implements JobAcquisitionStrategy

Determines the number of jobs to acquire and the time to wait between acquisition cycles by an exponential backoff strategy.

Manages two kinds of backoff times:

Both times are calculated by applying an exponential backoff. This means, when the respective conditions repeatedly hold, the time increases exponentially from one acquisition cycle to the next.

This implementation manages idle and backoff time in terms of levels. The initial backoff level is 0, meaning that no backoff is applied. In case the condition for increasing backoff applies, the backoff level is incremented. The actual time to wait is then computed as follows

timeToWait = baseBackoffTime * (backoffFactor ^ (backoffLevel - 1))

Accordingly, the maximum possible backoff level is

maximumLevel = floor( log( backoffFactor, maximumBackoffTime / baseBackoffTime) ) + 1
(where log(a, b) is the logarithm of b to the base of a)

Author:
Thorben Lindhauer

Field Summary
protected  boolean applyJitter
           
protected  int backoffDecreaseThreshold
           
protected  float backoffIncreaseFactor
           
protected  int backoffLevel
           
protected  long baseBackoffWaitTime
           
protected  long baseIdleWaitTime
           
protected  int baseNumJobsToAcquire
           
static long DEFAULT_EXECUTION_SATURATION_WAIT_TIME
           
protected  boolean executionSaturated
           
protected  long executionSaturationWaitTime
           
protected  float idleIncreaseFactor
           
protected  int idleLevel
           
protected  Map<String,Integer> jobsToAcquire
           
protected  int maxBackoffLevel
           
protected  long maxBackoffWaitTime
           
protected  int maxIdleLevel
           
protected  long maxIdleWaitTime
           
protected  int numAcquisitionsWithoutLockingFailure
           
 
Constructor Summary
BackoffJobAcquisitionStrategy(JobExecutor jobExecutor)
           
BackoffJobAcquisitionStrategy(long baseIdleWaitTime, float idleIncreaseFactor, long maxIdleTime, long baseBackoffWaitTime, float backoffIncreaseFactor, long maxBackoffTime, int backoffDecreaseThreshold, int baseNumJobsToAcquire)
           
 
Method Summary
protected  boolean allSubmittedJobsRejected(JobAcquisitionContext context)
           
protected  long calculateBackoffTime()
           
protected  long calculateIdleTime()
           
 int getNumJobsToAcquire(String processEngine)
           
 long getWaitTime()
           
protected  void initializeMaxLevels()
           
protected  double log(double base, double value)
           
 void reconfigure(JobAcquisitionContext context)
           
protected  void reconfigureBackoffLevel(JobAcquisitionContext context)
           
protected  void reconfigureIdleLevel(JobAcquisitionContext context)
           
protected  void reconfigureNumberOfJobsToAcquire(JobAcquisitionContext context)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXECUTION_SATURATION_WAIT_TIME

public static long DEFAULT_EXECUTION_SATURATION_WAIT_TIME

baseIdleWaitTime

protected long baseIdleWaitTime

idleIncreaseFactor

protected float idleIncreaseFactor

idleLevel

protected int idleLevel

maxIdleLevel

protected int maxIdleLevel

maxIdleWaitTime

protected long maxIdleWaitTime

baseBackoffWaitTime

protected long baseBackoffWaitTime

backoffIncreaseFactor

protected float backoffIncreaseFactor

backoffLevel

protected int backoffLevel

maxBackoffLevel

protected int maxBackoffLevel

maxBackoffWaitTime

protected long maxBackoffWaitTime

applyJitter

protected boolean applyJitter

numAcquisitionsWithoutLockingFailure

protected int numAcquisitionsWithoutLockingFailure

backoffDecreaseThreshold

protected int backoffDecreaseThreshold

baseNumJobsToAcquire

protected int baseNumJobsToAcquire

jobsToAcquire

protected Map<String,Integer> jobsToAcquire

executionSaturated

protected boolean executionSaturated

executionSaturationWaitTime

protected long executionSaturationWaitTime
Constructor Detail

BackoffJobAcquisitionStrategy

public BackoffJobAcquisitionStrategy(long baseIdleWaitTime,
                                     float idleIncreaseFactor,
                                     long maxIdleTime,
                                     long baseBackoffWaitTime,
                                     float backoffIncreaseFactor,
                                     long maxBackoffTime,
                                     int backoffDecreaseThreshold,
                                     int baseNumJobsToAcquire)

BackoffJobAcquisitionStrategy

public BackoffJobAcquisitionStrategy(JobExecutor jobExecutor)
Method Detail

initializeMaxLevels

protected void initializeMaxLevels()

log

protected double log(double base,
                     double value)

reconfigure

public void reconfigure(JobAcquisitionContext context)
Specified by:
reconfigure in interface JobAcquisitionStrategy

allSubmittedJobsRejected

protected boolean allSubmittedJobsRejected(JobAcquisitionContext context)
Returns:
true, if all acquired jobs (spanning all engines) were rejected for execution

reconfigureIdleLevel

protected void reconfigureIdleLevel(JobAcquisitionContext context)

reconfigureBackoffLevel

protected void reconfigureBackoffLevel(JobAcquisitionContext context)

reconfigureNumberOfJobsToAcquire

protected void reconfigureNumberOfJobsToAcquire(JobAcquisitionContext context)

getWaitTime

public long getWaitTime()
Specified by:
getWaitTime in interface JobAcquisitionStrategy

calculateIdleTime

protected long calculateIdleTime()

calculateBackoffTime

protected long calculateBackoffTime()

getNumJobsToAcquire

public int getNumJobsToAcquire(String processEngine)
Specified by:
getNumJobsToAcquire in interface JobAcquisitionStrategy


Copyright © 2017 camunda services GmbH. All rights reserved.