Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h3>Native code vs Managed Code</h3> <p>IIS would use native code for serving static files and likely employs some aggressive in-memory caching to achieve its performance.</p> <p>As ServiceStack is a .NET library that code is writing directly to ASP.NET's response stream so its harder to get any faster at streaming a file in managed .NET code. You could further increase performance by loading the file into memory and writing raw bytes instead.</p> <h3>Take advantage of HTTP Caching</h3> <p>Which is why if you have to do it managed code you should give your best efforts at taking advantage of HTTP Caching which is what we do in our <a href="https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/WebHost.EndPoints/Support/StaticFileHandler.cs" rel="nofollow">StaticFileHandler</a> - i.e. what ServiceStack uses to serve its static content, e.g css/js/html pages.</p> <h3>Register a Raw HttpHandler</h3> <p>Although ServiceStack's request pipeline is heavily optimized (i.e. doesn't add much overhead) you can still by-pass it by registering your own custom <code>IHttpHandler</code> and handle the raw ASP.NET request yourself - this will be the fastest option in .NET code, e.g:</p> <pre><code>SetConfig(new EndpointHostConfig { RawHttpHandlers = { MiniProfilerHandler.MatchesRequest }, }); </code></pre> <p>This is what the built-in MiniProfiler uses to serve its static content. <a href="https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/MiniProfiler/UI/MiniProfilerHandler.cs#L21" rel="nofollow">MatchesRequest</a> just takes a <code>IHttpRequest</code> to work out if it should handle the request (by returning a instance of IHttpHandler) or not (return null):</p> <pre><code>public static IHttpHandler MatchesRequest(IHttpRequest request) { var file = Path.GetFileNameWithoutExtension(request.PathInfo); return file != null &amp;&amp; file.StartsWith("ss-") ? new MiniProfilerHandler() : null; } </code></pre> <p>Other than that, the stand-alone version of ServiceStack (i.e. HttpListener host) should provide better raw thoughput than ASP.NET.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload