Reputation: 41
I am using Visual Studio 2010 to test a ASP .NET web service. I want to be able to set a fairly low goal for request / second (say 20) and achieve it with good precision (say +/- 2%). I am using the perfmon counter 'Requests/Sec' from category ASP.NET Apps v4.0.30319.
My WebTest vary a lot in duration and the load test keeps varying number of user. When I look at result graph the RPS goes between 0 and 60 and keeps going up and down.
Is there some way to set VS to fire a constant rps from controller stand point. Or even a fixed test / second.
Maybe a counter that lets me measure request initiated per second instead of request / sec so the variation in turn around time does not make a difference.
Upvotes: 2
Views: 496
Reputation: 26766
The only way to do this is using multiple threads - potentially up to RPS * ConnectionTimeout
of them, if all the requests have to wait and you're not using async IO.
You can cheat and use the ThreadPool (but be aware it makes no guarantees re: scheduling). There's also the Task Parallel Library if you're on .Net 4.
For ~20 RPS I doubt the lack of ThreadPool precision is going to be an issue. As you get higher RPS, that will change.
If you want to DIY, be aware it's difficult to do properly. A simple implementation would be to have a main worker thread launching new threads for each connection...
Private ShutdownRequested As Boolean = False
Public Sub StartLoad(RPS As Integer)
ShutdownRequested = False
Dim MainThread As New Threading.Thread(Sub() Worker(RPS))
MainThread.Start()
End Sub
Public Sub StopLoad()
ShutdownRequested = True
End Sub
Private Sub Worker(RPS As Integer)
While Not ShutdownRequested
Threading.Thread.Sleep(CInt(1 / RPS * 1000))
Dim Worker As New Threading.Thread(Sub() OpenAConntection())
End While
End Sub
A better way would be to use the async IO mechanism described here as it allows for many connections with a limited number of threads.
This article may also be of interest re: threading
Upvotes: 1