Click here to Skip to main content
15,851,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a small windows application where the click on a button will display the list of users in a datagrid starting with a name that is entered in a textbox..

I would like to find out how much it takes if there are 30 users uses this search page simultaneously and find out the time it takes to fetch the results on to datagrid of my windows application..


sample code:
C#
private void btnseacrh_Click(object sender, EventArgs e)
  {
      var name=txttextbox.Text;

     var Resultdataset= Fecthresultfromdb(name);
     
 // retchresultfromdb method calls the database and fetches all the people whose name //starts with 'name' value entered in a textbox
     
    //finally result set is bind to datagrid for display

    datagrid.datasource=Resultdataset;

  }  

Now I would like to know if there are 30 users concurrently using this seacrher window,how much time it takes..This is one of non functional requirement that has to be met within 3 secs.

PLease tell what modifications i need to do..PLease share the modified code snippet as well.
Posted
Updated 7-Jan-14 8:27am
v2

1 solution

What you are asking about is called load testing. Depending on what Visual Studio version you are using, there are built-in tools to help you load test your application. See Visual Studio Load Testing Tools[^]

If you are using some other version that doesn't have those tools, you should look at third party load testing tools for .net[^].

Your other option is to create a unit test application and queue up 30 parallel tasks to hit the database at the same time and use performance counters to measure responses, but this takes a lot more set up than using load testing tools. Some of the ones in the google link may have trial versions that run for some number of days or number of concurrent tests, evaluate each one to find one that meets your needs.

[Edit]

Here is a sample, simple load test you can do:

C#
public class LoadTester
{

    List<TimeSpan> times = new List<TimeSpan>();

    public void Test()
    {
        Thread[] threads = new Thread[30];

        for (int i = 0; i < 30; i++)
        {
            threads[i] = new Thread(new ThreadStart(TestDBConn));
            threads[i].IsBackground = true;
            threads[i].Name = "Test Thread " + i.ToString();
        }

        for (int i = 0; i < 30; i++)
        {
            threads[i].Start();
        }

        bool allFinished = false;

        while (!allFinished)
        {
            allFinished = threads.All(t => t.ThreadState == System.Threading.ThreadState.Stopped);
            Thread.Sleep(10);
        }

        double minMs, maxMs, avgMs, sum;
        minMs = double.MaxValue;
        maxMs = double.MinValue;
        sum = 0.0;

        foreach (TimeSpan ts in times)
        {
            if (ts.TotalMilliseconds < minMs)
                minMs = ts.TotalMilliseconds;

            if (ts.TotalMilliseconds > maxMs)
                maxMs = ts.TotalMilliseconds;

            sum += ts.TotalMilliseconds;
        }

        avgMs = sum / (double)times.Count;

        System.Diagnostics.Debug.WriteLine("Max: " + maxMs);
        System.Diagnostics.Debug.WriteLine("Min: " + minMs);
        System.Diagnostics.Debug.WriteLine("Avg: " + avgMs);
    }

    public void TestDBConn()
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();

        //Run your test here

        sw.Stop();

        times.Add(sw.Elapsed);
    }
}


You would put your call to Fecthresultfromdb(name) where it says "Run your test here". I would pull this function out of your form since you only care about the load on the database, the updating of the UI happens in a fixed time, regardless of the number of clients. Its the fetch from the database that will change.

Output will be in the output window.
 
Share this answer
 
v3
Comments
mahesh kumar BM 7-Jan-14 13:31pm    
If i use the second option ,how could i call 30 parallel tasks to hit db??? can u explain with simple example..Even an example with 10 line code is sufficient....can u explain using the method that i have used for better understanding ..I have only 3hrs left to finish this and my mind has reached saturation level n is blank..plz plz help
Ron Beyer 7-Jan-14 13:32pm    
What .NET framework version are you using?
mahesh kumar BM 7-Jan-14 13:34pm    
3.5 and vs 2010..
mahesh kumar BM 7-Jan-14 13:33pm    
And more ever the example using load test have explained with respect to website or web application..Is the same thing applies to win application as well....can u plz explain the second option of parallel tasks?
mahesh kumar BM 7-Jan-14 13:38pm    
Framework is 3.5 or higher and v use vs 2010 as IDE..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900