Monday, May 23, 2005 8:09 AMHi,
I have a situation where I want the virtual users to sleep for a random amount of time. Can I achieve this without using the WebTestRequest class, bcos in this situation there is no request at that point.
Eg. For a LoadTest (which has one web test), I set a constant load of 1000 users. The first step all of them do is to login to the web site. But I dont want all of them to log in at the same time. So I want to introduce a random delay for each virtual user.
Thanks in advance
Monday, May 23, 2005 7:22 PMModeratorA good way to do this would be to use a step load profile as opposed to a constant load profile. By using a step load profile you could add a specified number of users to the load test every x seconds up to a maximum number of users. For example you could start with 10 users and add 10 more every 5 seconds until you reached 100 users. To change the load profile do the following:
1) Open the load test
2) Locate the scenario node
3) One of the children of the scnenario node is the load profile node. Click on the load profile node.
4) Open the property window
5) Change the pattern from constant to step
6) Fill out the properties for the step profile.
7) Save and run the test.
Another way to step up the user load is to use a warmup period. During the warmup period the load test steps up the user load from 0 to the initial user count. The warmup period is a property of the run setting node.
Tuesday, May 24, 2005 4:33 AMHi,
This definitly solves the intial load on the web server. But I have other places in my code where I need to put the virtual user to sleep for a period of time and then send a request.
Is it "correct" and "safe" to use System.Threading.Thread.Sleep(int) method for this purpose?
Tuesday, May 24, 2005 2:26 PMModerator
Using Thread.Sleep() for this purpose is actually a bit dangerous and not recommended because the load test engine does not dedicate a thread to the running of each web test. Instead, threads in the load test engine are shared among multiple web tests, and some operations run on threads that are part of the .NET thread pool. So if you Sleep too often or too long, you may impact more than the just the current web test instance, and in the worst case this could cause the load test engine to run out of free threads in the thread pool. If you can use the step load profile to stagger the start of the test, and then set the Request think time property where possible, I think you will have better results. The think time is not actually implemented as a Sleep() (I could explain how it is done if you are interested).