-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Hello world" HTTP server dies under load #503
Comments
If you install libev and the conf-libev opam package then you should be able to handle far more connections. That will cause Lwt to use libev rathe than select for its internal event handling. |
EMFILE -- running out of file descriptors perhaps? Does raising the limit help, eg |
@hcarty, sorry, I forgot to mention it: I did install both |
#328 is relevant to this. |
@j0sh, in the first setup, I don't think so; In the second setup, probably so; |
Does Linux still have the same error after raising the ulimit? If not, what's the new error? |
@j0sh, it's the same error, it just takes a higher number of simultaneous connections to get it. ( |
Looks like on FreeBSD libev is not using |
See also ocsigen/lwt#87. |
@seliopou, I think FreeBSD port actually forces the In any case, this should be a reason for performance degradation, not an outright failure, right? |
If the application passes too many fds to |
@seliopou, so, which code is responsible for checking the number of fds passed into BTW, I've just tried this simple program: #include <ev.h>
#include <stdio.h>
int main() {
struct ev_loop *loop = EV_DEFAULT;
printf("%d\n", ev_backend(loop) == EVBACKEND_KQUEUE);
} ... and it prints |
I've added backtrace to the FreeBSD failure, and it turns out that the exception originates over here, inside Lwt's "select" engine. In other words, So, to workaround let () =
Lwt_engine.set (new Lwt_engine.libev) With this addition FreeBSD setup stops dying with The backtrace for that exception points here and also here, but neither of those seem relevant. What need to happen with the
The overall result should be for the server to accept as many incoming connections as it's allowed to, and to continue serving as many connections as possible even after fd limit is reached. |
Also, I think it will be useful to document the fact that Lwt's "select" engine is:
(Maybe it is already documented somewhere, and I've just missed it?) |
@magv I wouldn't mind mentioning this but this is really an Lwt specific thing so I'd like to see what's their documentation on this subject. |
Lwt's docs do mention that "Unix.select supports only 1024 [file descriptors] at most", so it is sort of covered, but then they also say that "libev is used by default on Unix", which as we've seen above is just false... Documentation-wise I think it would be useful not so much to focus on describing every quirk of Lwt (or Async, which I suspect is similarly limited, because as far as I can see they only have an epoll backend), but rather to describe how to build a robust server out of cohttp. Under FreeBSD, for example, this currently means using Lwt with conf-libev, and manually forcing the Speaking of which, is EMFILE problem something that can be fixed in cohttp, or is it further up the stack (Lwt? conduit? something else?)? |
I will investigate the EMFILE issue. In the meantime, if you'd like to help out it would be nice to see if the issue I can whip up an Async example as well, if you don't have any experience with On 08/17, Vitaly Magerya wrote:
|
As for FreeBSD, I have no experience with that fine OS so contributions On 08/17, Vitaly Magerya wrote:
|
Here's the async server: open Core.Std
open Async.Std
open Cohttp_async
let handler ~body:_ _ _ =
Server.respond_with_string "Hello world"
let () =
ignore (Cohttp_async.Server.create (Tcp.on_port 8000) handler);
never_returns (Scheduler.go ()) Here's the load generator:
On FreeBSD 10 amd64, with OCaml 4.03.0,
Maybe I'm doing something wrong here? "Connection reset by peer" is a pretty trivial error after all. |
Under Linux (Fedora 23, amd64), with OCaml 4.02.2,
If I don't kill it, there's also an error related to fd limit:
Note the core dump. Also don't believe the complaint about missing |
I just hit this myself. The error I get is: So this is a limitation with cohttp, and nothing I need to configure, is that right? EDIT: After investigating a bit more, yes, cohttp just needs to handle this and retry if |
Just encountered this issue when adding mirage as a test in these benchmarking trials TechEmpower/FrameworkBenchmarks@master...ciarancourtney:mirageos |
Have you tried using the |
Hi @SGrondin I resolved my crash issues by combing 2 workarounds actually https://github.com/TechEmpower/FrameworkBenchmarks/pull/2938/files |
@ciarancourtney I was about to suggest Glad those two fixed the crash. |
Should we maybe fix this in Lwt, by always recommending Lwt already recommends always installing |
@aantron There are a few parts to this. Even with libev the issue will come up if @fdopen's opam-for-windows repo has libev disabled under Windows (currently the last line of https://github.com/fdopen/opam-repository-mingw/blob/master/packages/conf-libev/conf-libev.4-11/opam). It would be nice to fix/address this before pushing too hard on a libev requirement. |
Fair enough. If it's ever the right time to require libev, please let me know. There is also of course the impending libuv thing. |
I don't think there is any point in using Beside this, the current lwt bindings would be broken on windows anyway. Therefore I've just disabled the package completely. |
@fdopen Thank you for the explanation! |
Hi. I've tried benchmaking cohttp as a potential web server for my needs, but it seems to die under load. I've got two different setups where this happens.
Here's the server I'm testing:
(I also tried using
cohttp-server-lwt
, and it behaves similarly).Setup 1: FreeBSD, OCaml 4.03, Unix_error(EINVAL, "select", "")
First I build and start the server like so:
Then, on a separate (or the same) machine I run wrk2 a few times:
... and the server dies with this message:
Setup 2: Linux, OCaml 4.02, Unix_error(EMFILE, "accept", "")
First I build and start the server like this:
Then from another machine I run wrk2:
... and the server dies:
I'm not sure if these two are the same problem, but whatever the case, a web server must not die from too many incoming connections.
The text was updated successfully, but these errors were encountered: