views:

126

answers:

3

Hi,

I'm trying to develop a small application that test how many requests per second can my service 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 in 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 millisencods, then it do it again:

    static Int32 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 excesive 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 maximun, 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.

+1  A: 

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.

Kevin
Nice. I'm pretty new in web development and as long I know that I'm not stretching more the CPUs because there are parameters that avoid it... I'm happy. I don't wanna mess (by the moment) with those parameters because I feel that those default values have a reason, and probably are protecting the web server. Right now the server is performing very simple tasks, but in the future those tasks will be much more complicated and time consuming, I'm happy with the current throughtput. Thanks!
vtortola
+2  A: 

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.

Chris Thornton
Interesting, I'll take a look on it! Thanks.
vtortola
+1  A: 

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.

BlackGaff