Skip to content

Conversation

2vg
Copy link

@2vg 2vg commented Apr 12, 2018

hi, Nim's super fast HTTP server :)
I made two additions.
First of all it is to get SOMAXCONN of OS.
Since the standard SOMAXCONN is probably hard coated to 128, if the value is greater than 128 it will be pointless.
The second is activation of TCP_NODELAY.
This invalidates the Nagle algorithm and eliminates the 40 ms delay in TCP communication. This will make a big contribution especially to performance.

@genotrance
Copy link

I just tried it and got the following crash:

Starting 16 threads
Listening on port 8080
httpbeast.nim(249)       eventLoop
net.nim(963)             setSockOpt
nativesockets.nim(597)   setSockOptInt
oserr.nim(110)           raiseOSError

This was on Ubuntu 17.10 with Nim #head.

@2vg
Copy link
Author

2vg commented Apr 17, 2018

with sudo ?

@genotrance
Copy link

Yes works with sudo. Not much of a performance improvement when compared with #head.

This PR:

./wrk -t16 -c400 -d30s http://localhost:8080/
Running 30s test @ http://localhost:8080/
  16 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.19ms    1.88ms  40.10ms   87.66%
    Req/Sec    48.99k     7.69k   75.76k    68.92%
  23447787 requests in 30.10s, 1.09GB read
Requests/sec: 779117.10
Transfer/sec:     37.15MB

Vs #head:

Running 30s test @ http://localhost:8080/
  16 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.27ms    2.26ms  87.33ms   89.08%
    Req/Sec    49.09k     8.08k   97.76k    69.79%
  23493417 requests in 30.10s, 1.09GB read
Requests/sec: 780566.70
Transfer/sec:     37.22MB

@genotrance
Copy link

Another sample.

./wrk -t16 -c400 -d30s http://localhost:8080/
Running 30s test @ http://localhost:8080/
  16 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.21ms    1.94ms  39.10ms   87.66%
    Req/Sec    49.23k     7.95k   79.35k    68.26%
  23543925 requests in 30.09s, 1.10GB read
Requests/sec: 782536.31
Transfer/sec:     37.31MB

@2vg
Copy link
Author

2vg commented Apr 17, 2018

I am surprised that the result does not change much.
Well, the benchmark in the local environment can not be trusted so much.
Benchmarking on two servers may change the result 🙄

@genotrance
Copy link

So my server had somaxconn = 128 so I don't think the code does anything relevant.

Also, I don't see any changes related to TCP_DELAY in the PR so no wonder the performance is identical.

@dom96
Copy link
Owner

dom96 commented Apr 18, 2018

Also, I don't see any changes related to TCP_DELAY in the PR so no wonder the performance is identical.

Isn't that related to TCP_DELAY: server.setSockOpt(OptNoDelay, true) ?

@genotrance
Copy link

Okay I missed that, never mind.

@dom96
Copy link
Owner

dom96 commented Apr 18, 2018

Shame that it doesn't improve the speed. But at least I can keep my code simpler, thanks for the PR though @2vg. I might come back to this later, but for now I'll close it.

@dom96 dom96 closed this Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants