Nancy: Many concurrent requests

Created on 16 Apr 2016  ·  9Comments  ·  Source: NancyFx/Nancy

Description

Nancy can not serve many(<10) concurrent requests at once.

Steps to Reproduce

  1. Add a StaticContentsConventions to serve files from a directory.
  2. Copy a long video file to the directory.
  3. Open the video in your browser in many tabs(>10) by pointing all to e.g. http://localhost/myvideo.mp4.
  4. Observe: Video is not displayed on all tabs, instead they wait for a connection till you close other tabs.

    System Configuration

  • Nancy version: 1.4.1
  • Nancy host: OWIN
  • Browser: Chrome

Most helpful comment

The best option to use nginx for static content(or another http server).

All 9 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thecodejunkie picture thecodejunkie  ·  8Comments

8 picture 8  ·  5Comments

Radzhab picture Radzhab  ·  11Comments

Hell0wor1d picture Hell0wor1d  ·  12Comments

jchannon picture jchannon  ·  9Comments