org.apache.commons.performance
Class ClientThread

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

public abstract class ClientThread
extends java.lang.Object
implements java.lang.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. 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.


Field Summary
protected  int cycleState
          Cycle state
protected  java.lang.String cycleType
          Cycle type
protected  java.lang.String delayType
          Delay type - determines how next start times are computed
protected  long iterations
          Number of iterations
protected  double lastMean
          Last mean delay
protected  java.util.logging.Logger logger
          Logger shared by client threads
protected  long maxDelay
          Maxiimum mean time between requests
protected  long minDelay
          Minimum mean time between requests
protected static int PEAK_LOAD
           
protected  long peakPeriod
          Peak length for cyclic mean delay
protected  long periodStart
          Start time of current period
protected static int RAMPING_DOWN
           
protected static int RAMPING_UP
          Cycle state constants
protected  long rampPeriod
          Ramp length for cyclic mean delay
protected  java.lang.String rampType
          Ramp type
protected  org.apache.commons.math.random.RandomData randomData
          Random data generator
protected  double sigma
          Standard deviation of delay distribution
protected  long startTime
          Start time of run
protected  Statistics stats
          Statistics container
protected static int TROUGH_LOAD
           
protected  long troughPeriod
          Trough length for cyclic mean delay
 
Constructor Summary
ClientThread(long iterations, long minDelay, long maxDelay, double sigma, java.lang.String delayType, long rampPeriod, long peakPeriod, long troughPeriod, java.lang.String cycleType, java.lang.String rampType, java.util.logging.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 finalize()
          Executed once after the run finishes
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()
           
protected  void setUp()
          Executed at the beginning of each iteration
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minDelay

protected long minDelay
Minimum mean time between requests


maxDelay

protected long maxDelay
Maxiimum mean time between requests


sigma

protected double sigma
Standard deviation of delay distribution


delayType

protected java.lang.String delayType
Delay type - determines how next start times are computed


rampPeriod

protected long rampPeriod
Ramp length for cyclic mean delay


peakPeriod

protected long peakPeriod
Peak length for cyclic mean delay


troughPeriod

protected long troughPeriod
Trough length for cyclic mean delay


cycleType

protected java.lang.String cycleType
Cycle type


rampType

protected java.lang.String rampType
Ramp type


iterations

protected long iterations
Number of iterations


startTime

protected long startTime
Start time of run


periodStart

protected long periodStart
Start time of current period


lastMean

protected double lastMean
Last mean delay


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

cycleState

protected int cycleState
Cycle state


randomData

protected org.apache.commons.math.random.RandomData randomData
Random data generator


stats

protected Statistics stats
Statistics container


logger

protected java.util.logging.Logger logger
Logger shared by client threads

Constructor Detail

ClientThread

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

Parameters:
iterations - number of iterations
minDelay - minumum mean time between client requests
maxDelay - maximum mean time between client requests
delayType - distribution of time between client requests
rampPeriod - ramp period of cycle for cyclic load
peakOeriod - 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
statsList - List of SummaryStatistics to add results to
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

init

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

Throws:
java.lang.Exception

setUp

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

Throws:
java.lang.Exception

cleanUp

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

Throws:
java.lang.Exception

finalize

protected void finalize()
                 throws java.lang.Exception
Executed once after the run finishes

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Exception

execute

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

Throws:
java.lang.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)


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