dom96 / httpbeast

A highly performant, multi-threaded HTTP 1.1 server written in Nim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Responses never terminate (ab dies with timeout error) (OS X)

joshgoebel opened this issue · comments

Using latest jester and Apache bench and for some reason it thinks the requests timeout. Perhaps we're not closing a socket properly or something? It's 100% reproducible here and only with httpbeast. asynchttpserver does not have the same issue.

nim c -d:release -r tests/example
...

INFO Jester is making jokes at http://0.0.0.0:5000
Starting 1 threads
ab -r -n 1000 -c 1000 http://0.0.0.0:5000/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 0.0.0.0 (be patient)
apr_pollset_poll: The timeout specified has expired (70007)

Seems to work fine in browser and with curl. AB is receiving the responses (if I used -v2), but obviously something else is off.

Thoughts?

Pretty sure this is because we don't yet support close=0 or keep-alive=0.

Hrm, interesting. Not sure what the problem could be, I'd need to look into how apache bench creates requests.

        if data.sendQueue.len == data.bytesSent:
          data.bytesSent = 0
          data.sendQueue.setLen(0)
          data.data.setLen(0)

          # selector.unregister(fd)
          # fd.SocketHandle.close()
          selector.updateHandle(fd.SocketHandle,
                                {Event.Read})

Adding the two commented lines fixed it for me... but of course (if this is the proper place to add them) they would need to be dependent on the Close/Keep-Alive/ and HTTP version. You can see how it's done in asynchttpserver if you want a reference.

ab is using HTTP/1.0 (though it doesn't seem to mind the 1.1 being returned) which by default expects keep-alive to be off and the connection to be terminated by the server - which we aren't doing.

commented

@yyyc514 You can use wrk instead of ab.
Although ab is a single thread and old tool, but wrk runs in multithreading.
If you want to use wrk with single thread, simply specify -t 1 with the command line option.
wrk -t 1 http://localhost:8080
Techempower, a famous benchmark, also uses wrk to measure it.

Yeah I've been using wrk, but still think httpbeast isn't doing the correct connection handling here.

Same problem here.

I also ran into this.

I tried this work around by adding req.client.close() to end of requests, but I get this error after some requests:

Error: unhandled exception: ioselectors_epoll.nim(147, 11) `s.fds[fdi].ident == InvalidIdent` Descriptor 118 already registered [AssertionDefect]```