Nancy can not serve many(<10) concurrent requests at once.
This screams of a common issue with full iis on non-server windows OS, what version of windows/iis are you running in (if at all)?
Forgot to mention: I am using Selfhosting with Microsoft.Owin.Host.HttpListener.
Maybe thats the Problem?
OS is Windows 10.
What would be the best Option for Selfhosting?
The best option to use nginx for static content(or another http server).
I agree with @Kiri-rin nginx is perfect for static content and then let nancy handle api related stuff.
Well, the problem is that I also have nonstatic content that is large or takes some time to generate.
I understand that this is no common use case though.
I will investigate this further. If someone can give me a hint where the problem could be it would be great.
@cody82 if you have long running routes then you should make them async so they do not block up the request threads
Yes. So does that mean that the problem is not in the general HTTP request handling in Nancy but in the handler for static files that does not properly use async?
I also experienced the same problem in ServiceStack that does most its handling asynchronous but then it calls one synchronous Socket.Write function that blocks everything.
I have tracked the problem to GenericFileResponse.GetFileContent:
c#
private static Action<Stream> GetFileContent(string filePath, long length)
{
return stream =>
{
using (var file = File.OpenRead(filePath))
{
file.CopyTo(stream, (int)(length < BufferSize ? length : BufferSize));
}
};
}
So File.CopyTo blocks the thread while the file/video is transfered.
(Also this class does not seam to handle partial responses but thats another issue.)
I doubt this can be just converted to an async function but I may be wrong?
(Also this class does not seam to handle partial responses but thats another issue.)
@cody82 I created a PartialFileResponse for video/audio streaming applications: https://gist.github.com/danbarua/0fd9fcad5ec85e0c02dc
Needs a little cleaning up but could possibly be merged in to Nancy or have the functionality added to GenericFileResponse.
Most helpful comment
The best option to use nginx for static content(or another http server).