API Reference¶
Workload Generator¶
-
class
wg.
WorkerThread
(parent, sleep_time=2)[source]¶ This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
-
class
wg.
WorkloadGenerator
(worker_func, rps=0.16666666666666666, delay_func=None, worker_thread_count=10, *args, **kwargs)[source]¶ WorkloadGenerator is the class responsible for generating the desired workload using the delay function provided, to achieve the target requests per second.
- Returns
an instance of the WorkloadGenerator class
- Return type
object
__init__ for WorkloadGenerator class.
- Parameters
worker_func (function) – the worker function that will be called by the worker threads, it shouldn’t have any arguments and should return a dict.
rps (float, optional) – desired requests per second to be achieved by the workload generator, defaults to 10/60
delay_func (function, optional) – the function that generates a draw from inter-arrival time given rps as an argument, defaults to exponential distribution
worker_thread_count (int, optional) – number of worker threads, defaults to 10
-
fire_wait
()[source]¶ fire_wait fires a request, generates an inter-arrival delay using delay_finc, then waits for that amount of time.
-
get_stats
()[source]¶ get_stats gathers the values generated by calling the workload function throughout the test.
- Returns
stats
- Return type
array of dicts
-
reset_stats
()[source]¶ reset_stats resets the info gathered from worker threads.
- Returns
sucess
- Return type
boolean
-
wg.
get_random_wait_time
(rps)[source]¶ get_random_wait_time generates random exponential inter-arrival times corresponding to Poisson process.
- Parameters
rps (float) – rps or requests per second is the target number of requests per second
- Returns
a draw from the resulting exponential distribution for inter-arrival time
- Return type
float
Timer¶
-
class
timer.
TimerClass
[source]¶ TimerClass is an object that can help with timing different components of the execution.
- Returns
TimerClass object
- Return type
object
-
tic
()[source]¶ tic resets the starting time fo the timer. toc() will get seconds past since calling tic().
-
toc
()[source]¶ - toc calculates the number of seconds passed since tic() has been called, or object has been created,
whichever is more recent.
- Returns
elapsed time since time reference
- Return type
float