Sunday, October 27, 2013

Using random functions for performance testing

When doing performance testing, we may need to use random functions to emulate client behavior. This blog use the ep scripting (can be seen as pesudo code here) to show some interesting applications of random functions.

The simplest example is the function that returns the random number between min and max.

randNumber(0,100);

Just with this simple function, we can do some fascinating client emulations. For example, suppose we want to emulate lots of sensor clients who will send temperature info periodically to a server. Each client will start with a random temperature between 50 and 90 degrees and adjust randomly by 2 degrees, after reporting temperature, it will sleep for 10 seconds.

Along with a random number, we may want to generate a random string. This can be used to generate a random user name of length between 4 and 10.

userName = randString(4,10);

The above examples look more like simple exercises, what about some real world user case? For example, emulating different browsers? The following script will emulate a Chrome browser with 30% chance, Firefox with 30% and IE with 40%. We can do it by

get a random number between 1 and 100, this will be the random percentage.

if the random percentage is between 71 and 100, then it's Chrome browser.

if the random percentage is between 41 and 70, then it's Firefox browser