org.apache.commons.performance
Class ClientThread

java.lang.Object
  extended by org.apache.commons.performance.ClientThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
DBCPClientThread, HttpClientThread, PoolClientThread

public abstract class ClientThread
extends Object
implements Runnable

Base for performance / load test clients. The run method executes init, then setup-execute-cleanup in a loop, gathering performance statistics, with time between executions based on configuration parameters. The finish method is executed once at the end of a run. See nextDelay() for details on inter-arrival time computation.

Subclasses must implement execute, which is the basic client request action that is executed, and timed, repeatedly. If per-request setup is required, and you do not want the time associated with this setup to be included in the reported timings, implement setUp and put the setup code there. Similarly for cleanUp. Initialization code that needs to be executed once only, before any requests are initiated, should be put into init and cleanup code that needs to be executed only once at the end of a simulation should be put into finish.

By default, the only statistics accumulated are for the latency of the execute method. Additional metrics can be captured and added to the Statistics for the running thread.


Field Summary
protected  Logger logger
          Logger shared by client threads
protected static int PEAK_LOAD
           
protected static int RAMPING_DOWN
           
protected static int RAMPING_UP
          Cycle state constants
protected  RandomData randomData
          Random data generator
protected  Statistics stats
          Statistics container
protected static int TROUGH_LOAD
           
 
Constructor Summary
ClientThread(long iterations, long minDelay, long maxDelay, double sigma, String delayType, long rampPeriod, long peakPeriod, long troughPeriod, String cycleType, String rampType, Logger logger, Statistics stats)
          Create a client thread.
 
Method Summary
protected  void adjustState(long currentTime)
          Adjusts cycleState, periodStart and lastMean if a cycle state transition needs to happen.
protected  void cleanUp()
          Executed in finally block of iteration try-catch
protected  double computeCyclicDelay(long currentTime, double min, double max)
           
abstract  void execute()
          Core iteration code.
protected  void finish()
          Executed once after the run finishes
 int getCycleState()
           
 String getCycleType()
           
 String getDelayType()
           
 long getIterations()
           
 double getLastMean()
           
 long getMaxDelay()
           
 long getMinDelay()
           
 long getNumErrors()
           
 long getNumMisses()
           
 long getPeakPeriod()
           
 long getPeriodStart()
           
 long getRampPeriod()
           
 String getRampType()
           
 double getSigma()
           
 long getStartTime()
           
 Statistics getStats()
           
 long getTroughPeriod()
           
protected  void init()
          Executed once at the beginning of the run
protected  long nextDelay()
          Computes the next interarrival time (time to wait between requests) based on configured values for min/max delay, delay type, cycle type, ramp type and period.
 void run()
           
 void setCycleState(int cycleState)
           
 void setDelayType(String delayType)
           
 void setLastMean(double lastMean)
           
 void setMaxDelay(long maxDelay)
           
 void setMinDelay(long minDelay)
           
 void setNumErrors(long numErrors)
           
 void setNumMisses(long numMisses)
           
 void setPeakPeriod(long peakPeriod)
           
 void setPeriodStart(long periodStart)
           
 void setRampPeriod(long rampPeriod)
           
 void setRampType(String rampType)
           
 void setSigma(double sigma)
           
 void setStartTime(long startTime)
           
 void setTroughPeriod(long troughPeriod)
           
protected  void setUp()
          Executed at the beginning of each iteration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RAMPING_UP

protected static final int RAMPING_UP
Cycle state constants

See Also:
Constant Field Values

RAMPING_DOWN

protected static final int RAMPING_DOWN
See Also:
Constant Field Values

PEAK_LOAD

protected static final int PEAK_LOAD
See Also:
Constant Field Values

TROUGH_LOAD

protected static final int TROUGH_LOAD
See Also:
Constant Field Values

randomData

protected RandomData randomData
Random data generator


stats

protected Statistics stats
Statistics container


logger

protected Logger logger
Logger shared by client threads

Constructor Detail

ClientThread

public ClientThread(long iterations,
                    long minDelay,
                    long maxDelay,
                    double sigma,
                    String delayType,
                    long rampPeriod,
                    long peakPeriod,
                    long troughPeriod,
                    String cycleType,
                    String rampType,
                    Logger logger,
                    Statistics stats)
Create a client thread.

Parameters:
iterations - number of iterations
minDelay - minimum mean time between client requests
maxDelay - maximum mean time between client requests
sigma - standard deviation of time between client requests
delayType - distribution of time between client requests
rampPeriod - ramp period of cycle for cyclic load
peakPeriod - peak period of cycle for cyclic load
troughPeriod - trough period of cycle for cyclic load
cycleType - type of cycle for mean delay
rampType - type of ramp (linear or random jumps)
logger - common logger shared by all clients
stats - Statistics instance to add results to
Method Detail

run

public void run()
Specified by:
run in interface Runnable

init

protected void init()
             throws Exception
Executed once at the beginning of the run

Throws:
Exception

setUp

protected void setUp()
              throws Exception
Executed at the beginning of each iteration

Throws:
Exception

cleanUp

protected void cleanUp()
                throws Exception
Executed in finally block of iteration try-catch

Throws:
Exception

finish

protected void finish()
               throws Exception
Executed once after the run finishes

Throws:
Exception

execute

public abstract void execute()
                      throws Exception
Core iteration code. Timings are based on this, so keep it tight.

Throws:
Exception

nextDelay

protected long nextDelay()
                  throws ConfigurationException

Computes the next interarrival time (time to wait between requests) based on configured values for min/max delay, delay type, cycle type, ramp type and period. Currently supports constant (always returning minDelay delay time), Poisson and Gaussian distributed random time delays, linear and random ramps, and oscillating / non-oscillating cycle types.

loadType determines whether returned times are deterministic or random. If loadType is not "constant", a random value with the specified distribution and mean determined by the other parameters is returned. For "gaussian" loadType, sigma is used as used as the standard deviation.

cycleType determines how the returned times vary over time. "oscillating", means times ramp up and down between minDelay and maxDelay. Ramp type is controlled by rampType. Linear rampType means the means increase or decrease linearly over the time of the period. Random makes random jumps up or down toward the next peak or trough. "None" for rampType under oscillating cycleType makes the means alternate between peak (minDelay) and trough (maxDelay) with no ramp between.

Oscillating loads cycle through RAMPING_UP, PEAK_LOAD, RAMPING_DOWN and TROUGH_LOAD states, with the amount of time spent in each state determined by rampPeriod (time spent increasing on the way up and decreasing on the way down), peakPeriod (time spent at peak load, i.e., minDelay mean delay) and troughPeriod (time spent at minimum load, i.e., maxDelay mean delay). All times are specified in milliseconds.

Examples:

  1. Given
     delayType = "constant"
     minDelay = 250
     maxDelay = 500
     cycleType = "oscillating"
     rampType = "linear" 
     rampPeriod = 10000
     peakPeriod = 20000
     troughPeriod = 30000
    load will start at one request every 500 ms, which is "trough load." Load then ramps up linearly over the next 10 seconds unil it reaches one request per 250 milliseconds, which is "peak load." Peak load is sustained for 20 seconds and then load ramps back down, again taking 10 seconds to get down to "trough load," which is sustained for 30 seconds. The cycle then repeats.
  2.  delayType = "gaussian"
     minDelay = 250
     maxDelay = 500
     cycleType = "oscillating"
     rampType = "linear" 
     rampPeriod = 10000
     peakPeriod = 20000
     troughPeriod = 30000
     sigma = 100 
    produces a load pattern similar to example 1, but in this case the computed delay value is fed into a gaussian random number generator as the mean and 100 as the standard deviation - i.e., nextDelay returns random, gaussian distributed values with means moving according to the cyclic pattern in example 1.
  3.  delayType = "constant"
     minDelay = 250
     maxDelay = 500
     cycleType = "none"
     rampType = "linear" 
     rampPeriod = 10000
    produces a load pattern that increases linearly from one request every 500ms to one request every 250ms and then stays constant at that level until the run is over. Other parameters are ignored in this case.
  4.  delayType = "poisson"
     minDelay = 250
     maxDelay = 500
     cycleType = "none"
     rampType = "none" 
     
    produces inter-arrival times that are poisson distributed with mean 250ms. Note that when rampType is "none," the value of minDelay is used as the (constant) mean delay.

Returns:
next value for delay
Throws:
ConfigurationException

adjustState

protected void adjustState(long currentTime)
Adjusts cycleState, periodStart and lastMean if a cycle state transition needs to happen.

Parameters:
currentTime - current time

computeCyclicDelay

protected double computeCyclicDelay(long currentTime,
                                    double min,
                                    double max)

getMinDelay

public long getMinDelay()

getMaxDelay

public long getMaxDelay()

getSigma

public double getSigma()

getDelayType

public String getDelayType()

getRampPeriod

public long getRampPeriod()

getPeakPeriod

public long getPeakPeriod()

getTroughPeriod

public long getTroughPeriod()

getCycleType

public String getCycleType()

getRampType

public String getRampType()

getIterations

public long getIterations()

getStartTime

public long getStartTime()

getPeriodStart

public long getPeriodStart()

getLastMean

public double getLastMean()

getCycleState

public int getCycleState()

getNumErrors

public long getNumErrors()

getNumMisses

public long getNumMisses()

getStats

public Statistics getStats()

setStartTime

public void setStartTime(long startTime)

setPeriodStart

public void setPeriodStart(long periodStart)

setLastMean

public void setLastMean(double lastMean)

setCycleState

public void setCycleState(int cycleState)

setNumErrors

public void setNumErrors(long numErrors)

setNumMisses

public void setNumMisses(long numMisses)

setRampType

public void setRampType(String rampType)

setMinDelay

public void setMinDelay(long minDelay)

setMaxDelay

public void setMaxDelay(long maxDelay)

setSigma

public void setSigma(double sigma)

setDelayType

public void setDelayType(String delayType)

setRampPeriod

public void setRampPeriod(long rampPeriod)

setPeakPeriod

public void setPeakPeriod(long peakPeriod)

setTroughPeriod

public void setTroughPeriod(long troughPeriod)


Copyright © 2007-2010 The Apache Software Foundation. All Rights Reserved.