I am building a document management service using the ASP.NET Web API, and performance is a matter of concern.
Based on this article, the author of Nathanael Jones, the author of the IIS / ASP.NET ImageResizer module, I developed several preconceptions about what is necessary for the "optimal" performance of serving static files. The accuracy of this:
- Use
HttpModuleit because it is very early in the ASP.NET pipeline (less pipeline = more optimized) and it turns out to be easier to deal with such things than HttpHandler. Response.WriteFile(filename)better than Response.Write(memBuffer)where memBuffer is a C # buffer in memory.- Rewriting a URL (i.e.
Context.RewritePath(virtualPath)) is better than Response.WriteFile(filename)because it will use the IIS static file handler, which is well optimized.
The problem is that thanks to some strange caching problem, I still can't figure it out ( here ), my method of rewriting URLs does not behave.
So now I have to wonder about a more realistic implementation of the web API, for example:
public Task<HttpResponseMessage> DoTheFoo()
{
return Task<HttpResponseMessage>.Factory.StartNew(() =>
{
var response = new HttpResponseMessage();
response.Headers.Add("Content-Disposition", "inline; filename=\"" + attachmentFileName + "\"");
response.Headers.Add("content-type", mimeType);
response.Content = new StreamContent(File.OpenRead("somefile.doc"));
return response;
});
}
For a Web API solution, this obviously makes things a bit tidy, since the parts serving the service files may go alongside other actions in the controllers, but how well will it execute and scale? Factors I think about:
- Network bandwidth. Presumably, there is no difference here; all methods write the same number of bytes.
- . IIS , ASP.NET? , ? , , DSL , gbit.
- . , StreamContent , IIS.
- . , , StreamContent , IIS.
- . IIS static file handler ( , , , ), , , , StreamContent. , , , , , .
, , , , - . , , ? URL-, , .