c# - Load test WebClient server



I am a developer who has no load test experience and would like to learn how to do this.

I have a simple client server application where the client sends a request to the server and the server sends a response back.

I would like to load test this but I am not sure how to do this. Here is my GetResponse method which receives a response from the server.

    Response GetResponse(Request request)
        string data = Newtonsoft.Json.JsonConvert.SerializeObject(request);

        System.Net.WebClient wb = new System.Net.WebClient();
        string response = wb.UploadString("http://localhost:8080", data);

        return Newtonsoft.Json.JsonConvert.DeserializeObject<Response>(response);

My initial thoughts are to write a routine to send a load of get response requests all at the same time and then try and monitor the CPU ticks or other to see how it is performing.

Can anyone let me know if this is the correct way to go about it? I am also not really sure what the best stats to gather are?

Thanks in advance


Whist waiting for an answer I have written the following which adds a new thread and processes the requests as desired. Please can you comment on whether this is sufficient to see what I need or do I need a proper load testing tool?

        DateTime startTime;
        DateTime endTime;

        Console.WriteLine("Test how many concurrent users?");
        string users = Console.ReadLine();

        int usersCount;

        if (int.TryParse(users, out usersCount) && usersCount > 0)
            startTime = DateTime.Now;
            _countDown = new CountdownEvent(usersCount);

            for (var i = 0; i < usersCount; i++)
                string userName = string.Format("user{0}", i);
                Task.Factory.StartNew(() => TestRun(userName));


            endTime = DateTime.Now;

            Console.WriteLine("All tasks are completed!");
            Console.WriteLine(string.Format("Av time(ms) per user: {0}", (endTime - startTime).TotalMilliseconds / usersCount));

        Console.WriteLine("Press any key to exit");

    public static void TestRun(object userName)
        Thread newThread = new Thread(DoWork);

    public static void DoWork(object userName)

1 Answer: 

  1. First of all you need a load testing tool. If your Visual Studio license allows, the most straightforward option would be using MS VS Load Testing Framework. If you don't have Web and Load test types - there is a number of free and open source load testing tools.
  2. Creating test itself. Being a developer you should know how to construct HTTP Request. If not - most load testing tools offer record and replay functionality.
  3. Once you get load test working you can start ramping up the number of virtual users and keep an eye on associated metrics and KPIs, i.e. :

    • Number of concurrent users vs response time
    • Number of concurrent users vs throughput
    • Transactions per second
    • Server hits per second
    • Response Time:

    • What is the maximum number of concurrent users / requests per second your application is able to serve without errors and having reasonable response time

    • If application is overloaded and does not respond does it return to normal operating mode when the load decreases
  4. Analysing above metrics you can:

    • determine maximum performance and capacity of your application
    • identify the bottleneck and work it around if possible