Question

I'm trying to develop a small application that tests how many requests per second my service can support but I think I'm doing something wrong. The service is in an early development stage, but I'd like to have this test handy in order to check from time to time I'm not doing something that decrease the performance. The problem is that I cannot get the web server or the database server go to the 100% of CPU.

I'm using three different computers, in one is the web server (WinSrv Standard 2008 x64 IIS7), in other the database (Win 2K, SQL Server 2005) and the last is my computer (Win7 x64 Ultimate), where I'll run the test. The computers are connected through a 100 ethernet switch. The request POST is 9 bytes and the response will be 842 bytes.

The test launches several threads, and each thread has a while loop, in each loop it creates a WebRequest object, performs a call, increment a common counter and waits between 1 and 5 milliseconds, then it do it again:

static int counter = 0;

static void Main(string[] args)
{
    ServicePointManager.DefaultConnectionLimit = 250;

    Console.WriteLine("Ready. Press any key...");
    Console.ReadKey();
    Console.WriteLine("Running...");

    string localhost = "localhost";
    string linuxmono = "192.168.1.74";
    string server = "192.168.1.5:8080";

    DateTime start = DateTime.Now;

    Random r = new Random(DateTime.Now.Millisecond);
    for (int i = 0; i < 50; i++)
    {
        new Thread(new ParameterizedThreadStart(Test)).Start(server);
        Thread.Sleep(r.Next(1, 3));
    }

    Thread.Sleep(2000);

    while (true)
    {
        Console.WriteLine("Request per second :"
            + counter / DateTime.Now.Subtract(start).TotalSeconds);
        Thread.Sleep(3000);
    }
}

public static void Test(object ip)
{
    Guid guid = Guid.NewGuid();

    Random r = new Random(DateTime.Now.Millisecond);
    while (true)
    {
        String test = "<lalala/>";
        WebRequest req = WebRequest.Create("http://"
            + (string) ip + "/WebApp/" + guid.ToString()
            + "/Data/Tables=whatever");
        req.Method = "POST";
        req.ContentType = "application/xml";
        req.Credentials = new NetworkCredential("aaa", "aaa","domain");
        byte[] array = Encoding.UTF8.GetBytes(test);
        req.ContentLength = array.Length;
        using (Stream reqStream = req.GetRequestStream())
        {
            reqStream.Write(array, 0, array.Length);
            reqStream.Close();
        }

        using (Stream responseStream = req.GetResponse().GetResponseStream())
        {
            String response = new StreamReader(responseStream).ReadToEnd();
            if (response.Length != 842) Console.Write(" EEEE ");
        }

        Interlocked.Increment(ref counter);

        Thread.Sleep(r.Next(1,5));
    }
}

If I run the test neither of the computers do an excessive CPU usage. Let's say I get a X requests per second, if I run the console application two times at the same moment, I get X/2 request per second in each one... but still the web server is on 30% of CPU, the database server on 25%...

I've tried to remove the Thread.Sleep in the loop, but it doesn't make a big difference.

I'd like to put the machines to the maximum, to check how may requests per second they can provide. I guessed that I could do it in this way... but apparently I'm missing something here... What is the problem?

Kind regards.

Was it helpful?

Solution

There are a lot of limiting factors besides the CPU on a web server. There are a lot of IIS settings which throttle the number of connections can be served.

I would read this:

http://www.eggheadcafe.com/articles/20050613.asp

I know it is for IIS 6, but there are things that will still apply.

If you have access to MSDN and have VS 2010 ultimate, I would check out their load testing tools. Purchasing the load testing program can be expensive, but if you need to test something specific, you can use the trial version to accomplish what you need. You can use it to monitor and response time, server utilization, etc. Well worth looking into.

OTHER TIPS

IMO, you're better off using SoapUI for the test. You can easily adjust the test case for the number of threads, number of iterations, etc.. And it'll graph the results. When you hit the plateau where you overwhelm the server, you'll see it on the graph. If one PC isn't enough, just run more of them on other PCs. You can do all of this with the free version.

I agree with Chris, and would go a step further to recommend JMeter, as it can also test the database and webapp, all within the same script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top