Friday, December 27, 2013

How to resume an interrupted performance test

Recently I read an interesting blog on "Handling consumable parameter data in LoadRunner" by Stu, a veteran on performance test. Even though it's about loadrunner, the underlying problem itself is applicable to all performance test platforms.

The problem may come naturally when you run performance tests. Think about this scenario: you have a csv file with 100,000 users and you need to register these users. Half way through, there is a problem or you need to leave, so the test has to be stopped. When you come back to continue with the test, you need to resume from where you left. You can make a note (or a mental note) where the test stopped, but it's cumbersome, especially when you have to start and stop test multiple times.

Stu's blog gave multiple creative solutions, however, none of them are quite simple due to the design limitation of Loadrunner. On NetGend, we have the concept of "permanent" variable and it solves the problem nicely. A variable is "permanent" if the value of the variable is stored in a permanent place (like in a file). So even after the test program was stopped, the value of the variable is still there, when you run the test again, the "permanent" variable will continue with the value left from the previous run.

Permanent variables can be created with "createPermVar()" function. It takes two parameters, the first one is the name of the permanent variable, the second parameter is the name of the file to store the value of the permanent variable.

createPermVar( <variableName>, <fileName>);

Here is a simple example that shows how to use it. The file "users.csv" contains rows of usernames and passwords.

In the above script, the variable "index" is a permanent variable, whenever its value changes (as by index ++), it will be implicitly stored in a file.

If the file (in this case "perm.txt") doesn't exist, the permanent variable ("index" in this case) will have initial value of 0 (when used as an index, it refers to the first element in an array) and the file will be created.

You may be concerned with the impact on performance due to storing value to a file - we all know writing to a file can be slow, especially on the disk seeking. Rest assured, storing values in our case is actually very fast! Our performance evaluation on this operation shows that we can achieve 2,000,000 operations per second on a slow PC.

Now you see how the "permanent" variable works. Does your favorite test platform have this feature?