**Skewness:**

"In probability theory and statistics, skewness is a measure of the asymmetry of the probability distribution of a real-valued random variable about its mean. The skewness value can be positive or negative, or undefined." (source wikipedia)

**Exponential:**

When designing application simulation model for performance testing you will come across scenarios which will require you to use different probability distribution to emulate correct production behavior. For example, average # of items per order, number of sessions or think time between pages.

The code below allows you to generated a skewed & exponential distribution for such a case in JMeter to emulate correct behavior as observed in production.

**Skewed distribution code**

max = VALUE; //update this value to maximum value expected in the distribution

bias = VALUE; //update this to a value against which the distribution should be biased toward

influence = 1; //[0.0, 1.0] - 1 means 100% influence

rnd = Math.random()*(max-min)+min;

mix = Math.random()*influence;

result = rnd *(1 - mix) + bias * mix;

**NOTE:**This code is from stackoverflow and I don't remember the link to it. If you do, please let me know.

**Exponential distribution code**

Avg = VALUE; //update this value to reflect mean
value for the distribution

MIN = VALUE; //update this value to minimum
value expected in the distribution

result = (long)(-(double)Avg*Math.log(Math.random()))+MIN;

__Example (Exponential distribution):__MIN = 1;

Avg = 2.5;

result = (long)(-(double)Avg*Math.log(Math.random()))+MIN;

If above code is executed for 200 iterations/thread, it will generate the values depicted in the histogram below. More iterations executed, better the distribution will look like. For testing, two threads were used.

**NOTE:**If you want to have a hard boundary, add an if condition in the code to check against a MAX value.

__Example (Skewed distribution):__min = 1;

bias = 3;

influence = 1;

rnd = Math.random()*(max-min)+min;

mix = Math.random()*influence;

result = rnd *(1 - mix) + bias * mix;

If above code is executed for 200 iterations/thread, it will generate the values depicted in the histogram below. More iterations executed, better the distribution will look like. For testing, two threads were used.

Use beanshell sampler to generate the value and save it in a variable. Pass variable into the loop controller to control it. Below is the code in beanshell sampler.

**NOTE:**

1: Make sure you run a few tests to get the distribution right to reflect what is happening in production.

2: If you have a better code to generate probability distribution be it exponential or any other kind, I would love to know.

## No comments:

Post a Comment