Wednesday, October 1, 2008

Random page selection for Load Testing

How should I design a load test for a scenario where a user can randomly hit one page from a given set of unsecure pages maintained on my web server? So at any point of time there could be 'x' no. of users, each accessing one page from the 'y' no. of pages residing on my web server. First I wrote a web test that will simulate 1 user accessing a random page. To do this, I created a table named a single column table named "Files" and populated it with the names of the aspx pages I have on the web server. Then I created a view over it with a SQL query

SELECT TOP(1) 'http://localhost/' + [dbo].[Files].[FileName] AS [PageName] FROM [dbo].[Files] ORDER BY NEWID()

Thanks to Philipe for giving this tip!

The above query will return a random page Url like http://localhost/Page1.aspx which is bound to a request in the WebTest.
Then I associated this WebTest with the LoadTest and configured the LoadTest to start with 1 user and add a new user every 1 second till a maximum count which will be equal to the number of pages on my web server. By selecting a distribution model based on the number of virtual users, I expected that the load test will result in user's getting a random unique page in each iteration. However, I was baffled to see what the load test engine was actually doing. On running the load test, the Page Results section in the Summary showed me that only one page was requested during the entire execution!!! On further investigation, I noticed that the WebLoadTestRequestMap table in the Load Test Database had only 1 RequestUri corresponding to my LoadTestRunId.

To get over this issue, I found it best to execute the above SQL statement using SqlDataReader in the WebTest code and create a WebTestRequest instance with the Url returned. With this approach, I am now able to successfully load test the scenario I had in mind. :)

No comments:

What is success?

The journey of life takes us through varied experiences like landing an admission at a prestigious college, earning a degree, getting hired,...