|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.performance.ClientThread
public abstract class ClientThread
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 |
---|
protected static final int RAMPING_UP
protected static final int RAMPING_DOWN
protected static final int PEAK_LOAD
protected static final int TROUGH_LOAD
protected RandomData randomData
protected Statistics stats
protected Logger logger
Constructor Detail |
---|
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)
iterations
- number of iterationsminDelay
- minimum mean time between client requestsmaxDelay
- maximum mean time between client requestssigma
- standard deviation of time between client requestsdelayType
- distribution of time between client requestsrampPeriod
- ramp period of cycle for cyclic loadpeakPeriod
- peak period of cycle for cyclic loadtroughPeriod
- trough period of cycle for cyclic loadcycleType
- type of cycle for mean delayrampType
- type of ramp (linear or random jumps)logger
- common logger shared by all clientsstats
- Statistics instance to add results toMethod Detail |
---|
public void run()
run
in interface Runnable
protected void init() throws Exception
Exception
protected void setUp() throws Exception
Exception
protected void cleanUp() throws Exception
Exception
protected void finish() throws Exception
Exception
public abstract void execute() throws Exception
Exception
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:
delayType = "constant" minDelay = 250 maxDelay = 500 cycleType = "oscillating" rampType = "linear" rampPeriod = 10000 peakPeriod = 20000 troughPeriod = 30000load 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.
delayType = "gaussian" minDelay = 250 maxDelay = 500 cycleType = "oscillating" rampType = "linear" rampPeriod = 10000 peakPeriod = 20000 troughPeriod = 30000 sigma = 100produces 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.delayType = "constant" minDelay = 250 maxDelay = 500 cycleType = "none" rampType = "linear" rampPeriod = 10000produces 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.
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.
ConfigurationException
protected void adjustState(long currentTime)
currentTime
- current timeprotected double computeCyclicDelay(long currentTime, double min, double max)
public long getMinDelay()
public long getMaxDelay()
public double getSigma()
public String getDelayType()
public long getRampPeriod()
public long getPeakPeriod()
public long getTroughPeriod()
public String getCycleType()
public String getRampType()
public long getIterations()
public long getStartTime()
public long getPeriodStart()
public double getLastMean()
public int getCycleState()
public long getNumErrors()
public long getNumMisses()
public Statistics getStats()
public void setStartTime(long startTime)
public void setPeriodStart(long periodStart)
public void setLastMean(double lastMean)
public void setCycleState(int cycleState)
public void setNumErrors(long numErrors)
public void setNumMisses(long numMisses)
public void setRampType(String rampType)
public void setMinDelay(long minDelay)
public void setMaxDelay(long maxDelay)
public void setSigma(double sigma)
public void setDelayType(String delayType)
public void setRampPeriod(long rampPeriod)
public void setPeakPeriod(long peakPeriod)
public void setTroughPeriod(long troughPeriod)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |