Ronan Thibaudau
Ronan Thibaudau

Reputation: 3603

HttpListener : writing to outputstream slow depending on content?

Removed the old question & rewriting completely because i've worked on this quite a bit to pinpoint the problem. My issue is that i'm writing a custom CMS with a custom server, with very very high speed/thoroughput as a goal, however i'm noticing that some data or data patterns cause major slowdowns (go from 0 to 55+ms response time). I really need someone better than me helping on this as i'm absolutely clueless about what is going on, i'm suspecting a bug in the .net Framework but i have no idea about where it could be, the little .net code browsing i did didn't suggest the output Stream does anything data-specific

Things that i've tested and am sure aren't the issue:

How to reproduce the issue:

My result:

Any help is much appreciated, placing all my rep on Bounty there as i really need to know if i go down this path / get more info to report this or if i go lower level and do my own http.sys interop (and, most of all, if the bug is only on the .net side or lower level & going lower level won't fix it!)

The sample file is a gziped array, my content is pre cached and pre compressed in db so this is representative of the data i need to send.

https://www.dropbox.com/s/ao63d7din939new/StackOverFlowSlowServerBug.zip

Edit : if i have fiddler open, the problematic test gets back to 0ms, i'm not sure what to make of it so far this means i'm getting a major slowdown, when sending some data, which isn't defined by the type of data but the actual data, and this doesn't happen if i have fiddler in between. I'm at loss!

Edit 2 : Tested with another browser just to be sure and, actually it's back to 0ms on IE so i'm assuming it may actually not be a HttpListener bug but instead a Firefox bug, i will edit my question & tags toward that if no one suggests otherwise. If this is the case, anyone know where i should be looking in FF's code to understand the issue? (it definately is an issue even if on their side since once again i'm comparing with 2 files, one larger than the other, same file format, the largest one always takes 0ms the smallest one always 55ms!)

Upvotes: 16

Views: 1294

Answers (1)

wdavo
wdavo

Reputation: 5110

Two requests problem:

Chrome:

  • First request = favicon
  • Second request = image

Firefox:

  • First request = image for the tab
  • Second request = image

More on this:

http://forums.mozillazine.org/viewtopic.php?t=341179

https://bugzilla.mozilla.org/show_bug.cgi?id=583351

IE:

  • Only appears to make the one request

If you send the requests through fiddler you never get two coming through.

Performance problem:

Firstly there's a problem with the timer in your demo app. It's restarted everytime the async request handler fires, meaning that the timer started for request A will be restarted when request B is received, possibly before request A is finished, so you won't be getting the correct values. Create the stopwatch inside the ContinueWith callback instead.

Secondly I can't see anyway that "magicnumber" will really affect performance (unless it causes an exception to be thrown I guess). The only way I can cause performance to degrade is by issuing a lot of concurrent requests and causing the wait lock to be continually hit.

In summary: I don't think there's a problem with the HttpListener class

Upvotes: 4

Related Questions