views:

404

answers:

2

Hello everyone,

I am using VSTS 2008 + C# + .Net 3.5 to develop a console application and I send request to another server (IIS 7.0 on Windows Server 2008). I find when the # of request threads are big, the IIS 7.0 will response with http 503 error. Any ideas what is wrong and how to tune to make IIS 7.0 serve more requests?

Here is my code,

class Program
{
    private static int ClientCount = 100;
    private static string TargetURL = "http://labtest/abc.wmv";
    private static int Timeout = 200;

    static void PerformanceWorker()
    {
        Stream dataStream = null;
        HttpWebRequest request = null;
        HttpWebResponse response = null;
        StreamReader reader = null;
        try
        {
            request = (HttpWebRequest)WebRequest.Create(TargetURL);
            request.Timeout = Timeout * 1000;
            request.Proxy = null;
            response = (HttpWebResponse)request.GetResponse();
            dataStream = response.GetResponseStream();
            reader = new StreamReader(dataStream);

            // 1 M at one time
            char[] c = new char[1000 * 10];

            while (reader.Read(c, 0, c.Length) > 0)
            {
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
        }
        finally
        {
            if (null != reader)
            {
                reader.Close();
            }
            if (null != dataStream)
            {
                dataStream.Close();
            }
            if (null != response)
            {
                response.Close();
            }
        }
    }

    static void Main(string[] args)
    {
        Thread[] workers = new Thread[ClientCount];
        for (int i = 0; i < ClientCount; i++)
        {
            workers[i] = new Thread((new ThreadStart(PerformanceWorker)));
        }

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

        for (int i = 0; i < ClientCount; i++)
        {
            workers[i].Join();
        }           

        return;
    }
}

thanks in advance, George

+1  A: 

I don't know much about IIS administration but the capacity of a web server depends on various factors the cpu power, memory available, request processing, time taken to process, etc. I don't know if IIS have a configuration to limit number of request it can process at a time. No matter what there will be always a limit a server can handle. So depending upon the factors above you need to provide that much capacity to handle the expected load.

Bhushan
Thanks! I have opened task manager and see CPU/Memory/Network are all consumed a small portion (less than 50%). Any further ideas to tuning?
George2
Thanks! I have got a similar question here, appreciate if you could take a look.http://stackoverflow.com/questions/1598748/unable-to-connect-to-remote-server-fail-in-httpwebrequest
George2
+2  A: 

The 503 Status Code stands for Service Unavailable and can be issued by servers when they are temporarily overloaded or too busy.

Like Bhushan says many factors can affect the ability of a server to service requests.

Look up IIS configuration on MSDN or maybe try asking your question on Server Fault (the server administrators equivalent of StackOverflow). You'll probably need to increase the amount of simultaneous requests permitted in a config file somewhere but even if you do you'll still be limited by the capabilities of your server.

Also take a look at this MSDN forum post about increasing the maximum simultaneous requests to one host that HttpWebRequest can make: http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/1f863f20-09f9-49a5-8eee-17a89b591007/
By default this is limited to 2

Edit

Try looking at http://www.server7.iis.net/ConfigReference/system.applicationHost/sites/site/siteDefaults/limits for configuring server connection and bandwith limits

RobV
What you mentioned is client side limitation (I already set client side max connection to 20,000). I think what I should configure is server side limitation?
George2
added a link to what looks like the IIS 7 config stuff you'll need to adjust to the original answer
RobV
From this document, the default max concurrent connection number is The default value is 4294967295, looks like it is big enough and no need to set?
George2
Thanks! I have got a similar question here, appreciate if you could take a look.http://stackoverflow.com/questions/1598748/unable-to-connect-to-remote-server-fail-in-httpwebrequest
George2