Editor's note: This article is part of a library of custom VuC functions developed by performance test engineers to handle special situations encountered in scripting applications. For an overview of the library and links to other custom functions, see "A library of custom VuC functions."
The connectspeed function sets a random VU connection speed distributed normally over a range of predefined values.
In simulating a user model as realistically as possible, you need to consider user connection speeds. IBM® Rational® TestManager® offers standard ways to set the connection speed for each user group, and this functionality is enough for most purposes. But in more complex scenarios it can become quite a burden to correctly merge your connection speed requirements in your test suite.
That's why I developed the connectspeed function, which allows you to specify a range of speeds and the proportion of users connected at each speed. Thanks to this function, you no longer need to create user groups for the sole purpose of testing different connection speeds. Adding a range of connection speeds to your scripts becomes very simple.
My research indicated that the posted modem/connection speeds are hardly ever reached and that typically only 75% of the throughput is realized. In other words, if you have a 56.6 kilobits-per-second modem, the best throughput you can hope to realize is 42 Kbps. This is due to protocol overhead, other traffic, network hops, and line quality. To simulate connection speeds more realistically, we have to take this fact into account.
The connectspeed function uses the normdist function
to create a normal distribution of the specified connection speeds. The peak
of the normal distribution coincides with 75% of the posted connection speed,
for the reason just mentioned. The result is a function that will provide a
very "natural" spread of connection speeds.
The connectspeed function takes no parameters but does require
you to create ten shared variables in your test suite (Speed1 to
Speed10) relating to the different connection speeds you want to
simulate. You can assign a weight to each of these variables to define how frequently
the related speed should be chosen. It makes sense to choose weights that add
up to 100 (as in 100%), but the function will accept any combination of numbers.
Remember that the numbers are all relative to each other.
Table 1 shows the connection speeds represented by the shared variables in
the connectspeed function as written. You can change these connection
speeds by replacing them in the function code with the speeds you want.
| Shared variable | Connection speed (bps) | Shared variable | Connection speed (bps) |
|---|---|---|---|
| Speed1 | 28800 | Speed6 | 1000000 |
| Speed2 | 56600 | Speed7 | 1540000 |
| Speed3 | 128000 | Speed8 | 3000000 |
| Speed4 | 256000 | Speed9 | 10000000 |
| Speed5 | 900000 | Speed10 | Unlimited |
Table 1: Connection speeds represented by the shared variables
To set up the shared variables in your test suite, choose Suite > Edit Shared Variables in TestManager and enter the desired weights in the Shared Variable Settings window, as exemplified in Figure 1. You can add the connection speed in the comment field as a reminder of the speed the shared variable represents.
Figure 1: Setting up the shared variables in your test suitee
This function uses the
normdist
function.
Here's the code for the connectspeed function, to be placed in
your script or in a .h file:
/* Add these shared variables to your suite.
You need as many variables as entries in
your nSimulationSpeed array. */
shared int Speed1; //28800: The old 28.8 Kbps modem
shared int Speed2; //56600: The 56.6 Kbps modem
shared int Speed3; //128000: Single channel ISDN
shared int Speed4; //256000: Dual channel ISDN
shared int Speed5; //900000: Typical ADSL speed
shared int Speed6; //1000000: Typical cable speed
shared int Speed7; //1540000: T1
shared int Speed8; //3000000: 3Mbs
shared int Speed9; //10000000: 10Mbs
shared int Speed10; //Unlimited: Up to the maximum speed on your local connection
int func connectspeed()
{
int iSeed;
int iTemp;
int nCount;
/* Add the speeds you want to simulate to this array. */
int nSimulationSpeed\[\] =
{28800,
56600,
128000,
256000,
900000,
1000000,
1540000,
3000000,
10000000,
0};
int nSpeedWeight\[\];
//Place the shared variables in an array to be able to iterate
//through them.
nSpeedWeight\[0\] = Speed1;
nSpeedWeight\[1\] = Speed2;
nSpeedWeight\[2\] = Speed3;
nSpeedWeight\[3\] = Speed4;
nSpeedWeight\[4\] = Speed5;
nSpeedWeight\[5\] = Speed6;
nSpeedWeight\[6\] = Speed7;
nSpeedWeight\[7\] = Speed8;
nSpeedWeight\[8\] = Speed9;
nSpeedWeight\[9\] = Speed10;
/* Select a random number between 1 and the sum of the shared variable values
*/
iSeed=uniform(1,Speed1+Speed2+Speed3+Speed4+Speed5+Speed6+Speed7+Speed8+Speed9
+Speed10);
nCount=0;
iTemp=0;
while(nCount<10)
{
iTemp = iTemp + nSpeedWeight\[nCount\]; if (iSeed<=iTemp &&
nSpeedWeight\[nCount\]> 0)
{
if (nSimulationSpeed\[nCount\]==0)
return 0;
else
return normdist(nSimulationSpeed\[nCount\]/2,nSimulationSpeed\[nCount\],(nSimulationSpeed
\[nCount\]- nSimulationSpeed\[nCount\]/2)/3);
}
nCount++;
}
}
|
The connectspeed function can be placed in each calling script
immediately following the #include command, or it can go in a separate
.h file referenced by an additional #include command.
The function can then be put in either the test script section of the repository
or the Rational Test include directory. Putting it in the latter
location will give you the benefit of not having to copy this function into
every repository you work with.
To use the connectspeed function, you need to put a reference
to the normdist function in your test script. Place either one
of the following #include statements just below the #include
<vu.h> line at the top of your script:
#include <normdist.h> /* If normdist.h is in your c:\Program
Files\Rational\Rational Test\include directory */
or
#include "normdist.h" /* If normdist.h is in your repository's script
Directory */
int connectspeed()
To set the connection speed per virtual user for the whole suite, insert the following code in the first script of a suite before your first emulation command:
/*** All you need to set the connection speed for a script ***/ |
And don't forget to include
pop Line_speed;
at the end of the last script in your suite to remove the value of the VU environment
variable Line_speed from the top of the stack.
As an example of how connectspeed works, consider the scenario for simulation
shown in Table 2.
| Connection speed (bps) | Weight | Connection speed (bps) | Weight |
|---|---|---|---|
| 28800 | 5 | 1000000 | 15 |
| 56600 | 15 | 1540000 | 30 |
| 128000 | 1 | 3000000 | 2 |
| 256000 | 0 | 10000000 | 0 |
| 900000 | 10 | Unlimited | 0 |
Table 2: A scenario for simulating different connection speeds
When we apply the connectspeed function with these weights assigned,
the actual speeds used in our simulation will resemble the graphic representation
in Figure 2.
Figure 2: Spread of connection speeds when connectspeed is applied
It's very clear that both the weighting and the normal distribution have been applied.
Roland Stens is an independent consultant based in Vancouver, Canada, who specializes in QA and testing -- particularly performance and robustness testing. His background is in programming, system analysis, database and network management, testing, and project/test management. As an active participant in various forums related to performance testing, he shares his insights with other testers to help expand their knowledge and vision of the tools and testing processes. He is happy to answer questions by e-mail.





