Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Many concurrent requests #2412

Open
cody82 opened this issue Apr 15, 2016 · 9 comments
Open

Many concurrent requests #2412

cody82 opened this issue Apr 15, 2016 · 9 comments
Assignees

Comments

@cody82
Copy link

cody82 commented Apr 15, 2016

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
@Yantrio
Copy link
Contributor

Yantrio commented Apr 16, 2016

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)?

@cody82
Copy link
Author

cody82 commented Apr 16, 2016

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?

@hey-red
Copy link

hey-red commented Apr 19, 2016

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

@sphiecoh
Copy link
Contributor

I agree with @kiri-rin nginx is perfect for static content and then let nancy handle api related stuff.

@cody82
Copy link
Author

cody82 commented Apr 22, 2016

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.

@thecodejunkie
Copy link
Member

@cody82 if you have long running routes then you should make them async so they do not block up the request threads

@thecodejunkie thecodejunkie self-assigned this Apr 22, 2016
@cody82
Copy link
Author

cody82 commented Apr 22, 2016

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.

@cody82
Copy link
Author

cody82 commented May 3, 2016

I have tracked the problem to GenericFileResponse.GetFileContent:

        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?

@danbarua
Copy link
Contributor

danbarua commented Mar 28, 2017

(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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants