org.apache.commons.performance
Class LoadGenerator

java.lang.Object
  extended by org.apache.commons.performance.LoadGenerator
Direct Known Subclasses:
DBCPSoak, HttpSoak, PoolSoak

public abstract class LoadGenerator
extends Object

Base class for load / peformance test runners. Uses Commons Digester to parse and load configuration and spawns ClientThread instances to generate load and gather statistics.

Subclasses must implement makeClientThread to create client thread instances to be kicked off by execute. Subclasses will also in general override configure to load additional configuration parameters and pass them on to the client in makeClientThread. Implementations of configure should start with a super() call so that the base configuration parameters are loaded. This method should also set the configFile property to a valid URI or filespec (suitable argument for Digester's parse method). Setup code that needs to be executed before any client threads are spawned should be put in init

See DBCPSoak and its sample configuration file for an example. As in that example, additional sections of the config file should be parsed and loaded in the overridden configure method. The "run" section is required by the base implementation. That example also illustrates how init can be used to set up resources or data structures required by the client threads.


Field Summary
protected  String configFile
           
protected  String cycleType
           
protected  String delayType
           
protected  org.apache.commons.digester.Digester digester
           
protected static Logger logger
          logger
protected  long maxDelay
           
protected  long minDelay
           
protected  long peakPeriod
           
protected  long rampPeriod
           
protected  String rampType
           
protected  double sigma
           
protected  long troughPeriod
           
 
Constructor Summary
LoadGenerator()
           
 
Method Summary
protected  void cleanUp()
          This method is invoked by execute() after all spawned threads have terminated.
protected  void configure()
          Starts preparing Digester to parse the configuration file, pushing *this onto the stack and loading rules to configure basic "run" parameters.
 void configureRun(String iterations, String clients, String minDelay, String maxDelay, String sigma, String delayType, String rampType, String rampPeriod, String peakPeriod, String troughPeriod, String cycleType)
          Configures basic run parameters.
 void execute()
          Invokes configure() to load digester rules, then digster.parse, then init() to initialize configuration members.
 String getConfigFile()
           
 org.apache.commons.digester.Digester getDigester()
           
 Statistics getStatistics()
           
protected  void init()
          This method is invoked by execute() after configure() and digester parse, just before client threads are created.
protected abstract  ClientThread makeClientThread(long iterations, long minDelay, long maxDelay, double sigma, String delayType, long rampPeriod, long peakPeriod, long troughPeriod, String cycleType, String rampType, Logger logger, Statistics stats)
           
protected  void parseConfigFile()
           
 void setConfigFile(String configFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final Logger logger
logger


minDelay

protected long minDelay

maxDelay

protected long maxDelay

sigma

protected double sigma

delayType

protected String delayType

rampType

protected String rampType

rampPeriod

protected long rampPeriod

peakPeriod

protected long peakPeriod

troughPeriod

protected long troughPeriod

cycleType

protected String cycleType

digester

protected org.apache.commons.digester.Digester digester

configFile

protected String configFile
Constructor Detail

LoadGenerator

public LoadGenerator()
Method Detail

execute

public void execute()
             throws Exception

Invokes configure() to load digester rules, then digster.parse, then init() to initialize configuration members. Then spawns and executes numClients ClientThreads using makeClientThread(long, long, long, double, java.lang.String, long, long, long, java.lang.String, java.lang.String, java.util.logging.Logger, org.apache.commons.performance.Statistics) to create the ClientThread instances. Waits for all spawned threads to terminate and then logs accumulated statistics, using Statistics.displayOverallSummary()

Subclasses should not need to override this method, but must implement makeClientThread(long, long, long, double, java.lang.String, long, long, long, java.lang.String, java.lang.String, java.util.logging.Logger, org.apache.commons.performance.Statistics) and may override configure() and init() to prepare data to pass to makeClientThread, and cleanUp() to clean up after all threads terminate.

Throws:
Exception

makeClientThread

protected abstract ClientThread makeClientThread(long iterations,
                                                 long minDelay,
                                                 long maxDelay,
                                                 double sigma,
                                                 String delayType,
                                                 long rampPeriod,
                                                 long peakPeriod,
                                                 long troughPeriod,
                                                 String cycleType,
                                                 String rampType,
                                                 Logger logger,
                                                 Statistics stats)

init

protected void init()
             throws Exception
This method is invoked by execute() after configure() and digester parse, just before client threads are created. Objects that need to be created and passed to client threads using configuration info parsed from the config file should be created in this method.

Throws:
Exception

cleanUp

protected void cleanUp()
                throws Exception
This method is invoked by execute() after all spawned threads have terminated. Override to clean up any resources allocated in init().

Throws:
Exception

configureRun

public void configureRun(String iterations,
                         String clients,
                         String minDelay,
                         String maxDelay,
                         String sigma,
                         String delayType,
                         String rampType,
                         String rampPeriod,
                         String peakPeriod,
                         String troughPeriod,
                         String cycleType)
                  throws ConfigurationException
Configures basic run parameters. Invoked by Digester via a rule defined in configure().

Parameters:
iterations - number of iterations
clients - number of client threads
minDelay - minimum delay between client thread requests (ms)
maxDelay - maximum delay between client thread requests (ms)
sigma - standard deviation of delay
delayType - type of delay (constant, gaussian, poisson)
rampType - type of ramp (none, linear, random)
rampPeriod - rampup/rampdown time
peakPeriod - peak period
troughPeriod - trough period
cycleType - cycle type (none, oscillating)
Throws:
ConfigurationException

configure

protected void configure()
                  throws Exception

Starts preparing Digester to parse the configuration file, pushing *this onto the stack and loading rules to configure basic "run" parameters.

Subclasses can override this, using super() to load base parameters and then adding additional addCallMethod sequences for additional parameters.

Throws:
Exception

parseConfigFile

protected void parseConfigFile()
                        throws Exception
Throws:
Exception

getConfigFile

public String getConfigFile()
Returns:
the configFile

setConfigFile

public void setConfigFile(String configFile)
Parameters:
configFile - the configFile to set

getDigester

public org.apache.commons.digester.Digester getDigester()
Returns:
the digester

getStatistics

public Statistics getStatistics()
Returns:
statistics


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