3

I have a select query, i would like to run it 50 times in parallel(to load test) ie. 50 independent times(a separate process).

if i run like this

for (int i=0;i<=49;i++)
{
 //record start time before the query
 //Code that runs the select query...
 //record end time after the query
}

I need to test the select query for 50 times, do I need to use 50 different threads or running that query in for loop 50 times, which is the correct approach?

Is there better way to check the consumption time of the query for say 50 times ? Do i need to use threads? I am not sure how to use Threads, don't have much idea of threaded programming, any sample will help.

Sharpeye500
  • 8,775
  • 25
  • 95
  • 143

1 Answers1

0

First of all, why are you doing this? Is this for performance evaluation purposes, as a fun hobby project, or part of production code?

Since it is a Select query, you shouldn't run into the same kinds of locking/transaction-breaking problems you would get trying to implement async Insert/Update/Delete queries. One thing to know is, don't run them in a loop, since that's synchronous. You can set up the queries in a loop if you need to, but you'll need to use a Service Broker to run them. Take a look at this excellent article to get started. For the C# side, take a look at this MSDN article if you're running 2012.

Jesse Smith
  • 963
  • 1
  • 8
  • 21
  • This is for load testing of the query from UI, so that, when 50 different users hit the same query, at the same time, I would like to record the consumption time of each user(s). – Sharpeye500 Jun 28 '13 at 16:34