HttpWebRequest is extremely slow!

Posted by Earlz on Stack Overflow See other posts from Stack Overflow or by Earlz
Published on 2010-03-25T21:49:01Z Indexed on 2010/03/25 21:53 UTC
Read the original article Hit count: 441

Filed under:
|
|
|

Hello, I am using an open source library to connect to my webserver. I was concerned that the webserver was going extremely slow and then I tried doing a simple test in Ruby and I got these results

Ruby program: 2.11seconds for 100 HTTP GETs

C# library: 20.81seconds for 100 HTTP GETs

I have profiled and found the problem to be this function:

private HttpWebResponse GetRawResponse(HttpWebRequest request) {
  HttpWebResponse raw = null;
  try {
    raw = (HttpWebResponse)request.GetResponse(); //This line!
  }
  catch (WebException ex) {
    if (ex.Response is HttpWebResponse) {
      raw = ex.Response as HttpWebResponse;
    }
  }
  return raw;
}

The marked line is takes over 1 second to complete by itself while the ruby program making 1 request takes .3 seconds. I am also doing all of these tests on 127.0.0.1, so network bandwidth is not an issue.

What could be causing this huge slow down?

© Stack Overflow or respective owner

Related posts about httpwebrequest

Related posts about http