markrendle/Simple.Web — pull request #49 by nordbergm (2013-01-30 10:36:39+00:00)
Title: Performance fix by caching run methods

I've run performance tests using WeigHTTP against a simple REST endpoint, like this one:

```csharp
[UriTemplate("/objects/{Id}")]
public class GetObjectById : IGet, IOutput
{
public Status Get()
{
Output = new GetObjectResponseDto
{
Id = Id
};

return Status.OK;
}

public int Id { get; set; }
public GetObjectResponseDto Output { get; private set; }
}
```

I noticed that on my machine I could only get a throughput of around __600 req/sec__ using IIS 8.0, and the follwing WeigHTTP parameters:
```shell
weighttp -n 10000 -c 10 -t 4 -k -H "Accept: application/json" http://localhost/objects/1
```
Compare this to MVC4 doing around 4500 req/sec and Web API around 5500 req/sec.

Using ANTS Profiler I've pinpointed the problem being that the handler run methods are compiled at each requests. Much of this was because the HandlerInfo variables were unique per request.

So, I've made a change so that HandlerInfo is a parameter to the lambda allowing the lambda to be cached under the handler type and HTTP method.

This has increased the throughput to around __4500 req/sec__.