High Performance ASP.NET Site (> 1000 Request/Second)

TobiHeidi picture TobiHeidi · Mar 20, 2012 · Viewed 7.8k times · Source

I am writing a High Performance ASP.NET Json API with soon > 1000 Request/Second. All my logic and processing is done in an IHttpHandler. I measured via Stopwatch Class and the handler finishes a request in around 0,1 - 0,5 Millisecond.

But it seems IIS and/or other HTTPHandlers (Modules?) are taking away a lot of performance. Can i measure that somehow ? How much overhead will a request produce in IIS when configured for best performance ?

Will removing all those HTTPHandlers help, or are there other tricks to speed it up? I dont need much of the ASP.NET Featureset besides Session (could even workaround that if it give a significant performance boost).

Answer

Abel picture Abel · Mar 21, 2012

Measuring performance of a web server is no trivial task. A few things to consider:

  • Find the actual bottleneck. This can be memory, disk access, caching, database access, network latency etc. Use a memory profiler, or other performance profiler to find out.
  • Use WireShark to find the difference between how long the request is on your machine and how long your code runs.
  • Try other configurations. Give ASP.NET more memory. Upgrade the test system. I.e., going from 8GB / 2.5GHz with 600 requests/sec to 16GB / 3.0GHz can yield 6500 requests/sec. Performance growth is often not linear. See this document from Microsoft.
  • Consider adding an extra machine. This can yield up to a 50 or even higher performance upgrade depending on how you configure it. See again that document from MS.
  • Check these hints by Jon Skeet. The comment thread reveals some non-obvious potential bottlenecks as well.

NOTE 1: know your tools. ASP.NET runs each request in its own thread. Thread swapping is faster than process swapping, but it still requires time. If other handlers take time because they are in the request chain, it's beneficial to disable them.

NOTE 2: one of the original side-goals of stackoverflow was to create a site in ASP.NET that had great performance on max 2 servers and could handle > 1Mln visitors per hour. They managed to do that. I believe they wrote some blogposts on it, but I don't remember where they are.