locked
“Unable to connect to remote server fail” in HttpWebRequest RRS feed

  • Question

  • User127071777 posted

    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 (e.g. 2000 threads), the client will receive error "Unable to connect to remote server fail" when invoking response = (HttpWebResponse)request.GetResponse().My confusion is -- I have set timeout to be a large value, but I got such fail message within a minute. I think even if the connection are really larger than what IIS could serve, client should not get such fail message so soon, it should get such message after timeout period. Any comments? Any ideas what is wrong? Any ideas to make more number of concurrent connection being served by IIS 7.0?

    Here is my code,

           class Program
            {
                private static int ClientCount = 2000;
                private static string TargetURL = "http://labtest/abc.wmv";
                private static int Timeout = 3600;
       
                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

     

    Wednesday, October 21, 2009 12:53 AM

Answers

  • User690216013 posted

    IIS 7 does not have that. To edit IIS 7 settings, you can utilize IIS Manager, or edit %windir%\system32\inetsrv\config\applicationHost.config directly.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Wednesday, October 21, 2009 6:14 AM

All replies

  • User690216013 posted
    You'd better check both IIS logs and HTTP error logs on the IIS server. Generally speaking, HTTP.sys component will stop accepting new connections when it cannot afford them. That will trigger a client side error immediately instead of timeout sometimes.
    Wednesday, October 21, 2009 1:20 AM
  • User127071777 posted

    For "IIS logs and HTTP error logs", could you specify in more details which files do you mean?

    Wednesday, October 21, 2009 2:26 AM
  • User690216013 posted

    IIS logs contain web site access records,

    http://support.microsoft.com/kb/943891

    while HTTP error logs contain HTTP.sys activities,

    http://support.microsoft.com/kb/820729

    Wednesday, October 21, 2009 2:35 AM
  • User127071777 posted

    I am a little bit confused, IIS log and Http log, they are different things? What are the differences and purposes between them?

    Wednesday, October 21, 2009 2:42 AM
  • User690216013 posted
    That's a long history to tell. In short, IIS logs are closely related to IIS web site parts, while HTTP error logs are closely related to a Windows driver named http.sys. They are different things.
    Wednesday, October 21, 2009 2:47 AM
  • User127071777 posted

    I am confused. I am testing against IIS, do you mean IIS log itself is not enough and we have to use additional http.sys log? My confusion is why IIS log itself is not enough for testing on IIS application (as in my scenario).

    Wednesday, October 21, 2009 2:56 AM
  • User690216013 posted

    Please understand IIS is not a single process program but a Windows system component that is composed of many pieces.

    It will be irrational to put all logging information into one place as difference sources have different things/structures to log.

    Yes, IIS log files mentioned in KB 943891 are not enough for diagnostics, as many relevant information can be logged in HTTP error logs, Application event log, System event log and many others.

    Regards,

    Wednesday, October 21, 2009 3:03 AM
  • User127071777 posted

    Thanks! I followed directions in http://support.microsoft.com/kb/820729, and then I find in my registry, HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters, there is no keys like EnableErrorLogging/ErrorLogFileTruncateSize/ErrorLoggingDir, but in directory C:\Windows\System32\LogFiles\HTTPERR under IIS 7.0 machine, there is already log files like httperr12.log. Does it mean by default Http.sys error will be logged and in my system, I do not need to configure any additional settings, and the Http.sys already works?

    Wednesday, October 21, 2009 3:25 AM
  • User127071777 posted

    From logs under C:\Windows\System32\LogFiles\HTTPERR, I got failed reasons of two categories, any ideas what is wrong?


    HTTP/1.1 GET /test.wmv - 1 Timer_MinBytesPerSecond DefaultAppPool

    HTTP/1.1 GET /test.wmv - 1 Connection_Dropped_List_Full DefaultAppPool

    Wednesday, October 21, 2009 3:28 AM
  • User690216013 posted

    :) I hope you go through http://support.microsoft.com/kb/820729 and the answers are already there.

     

    Wednesday, October 21, 2009 3:56 AM
  • User127071777 posted

    How to edit meta database of IIS 7.0 on Windows Server 2008? I read some tutorials and they said I should enable meta data editing feature from Properties of a web server in IIS management console. But when I right click on a web server in IIS management console, there is no menu called Properties.

    Here is what I am referring to. Any ideas what is wrong?

    http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/1d1e5de4-fd63-40cd-bc5d-c20521548eed.mspx?mfr=true

    Wednesday, October 21, 2009 5:40 AM
  • User690216013 posted
    Please search on IIS.net as most IIS 7 information is published here, http://learn.iis.net/. IIS 6 and IIS 7 have different configuration system so many IIS 6 articles like the one you found does not apply to IIS 7.
    Wednesday, October 21, 2009 5:57 AM
  • User127071777 posted

    All I found is about meta compatibility of IIS 6 and IIS 7. Could you refer me a document from iis.net about how to edit meta database please? :-)

    Wednesday, October 21, 2009 6:09 AM
  • User690216013 posted

    IIS 7 does not have that. To edit IIS 7 settings, you can utilize IIS Manager, or edit %windir%\system32\inetsrv\config\applicationHost.config directly.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Wednesday, October 21, 2009 6:14 AM
  • User127071777 posted

    Thanks! Can you let me know how to edit Timer_MinBytesPerSecond configuration item in IIS 7 meta database please? All I find is for IIS 6.0.

    BTW: I opened file applicationHost.config, but find no item called Timer_MinBytesPerSecond. :-(

    Wednesday, October 21, 2009 6:22 AM
  • User127071777 posted

    Thanks, question answered!

    Wednesday, October 21, 2009 11:44 PM