-4

I'm trying to figure out how it might be I have 5600 rps even with simple "Hello World" response. I tried starndard net/http, echo and fasthttp. Here is an example of the latter:

func main() {
    router := routing.New()

    router.Get("/", func(c *routing.Context) error {
        fmt.Fprintf(c, "Hello, world!")
        return nil
    })

    panic(fasthttp.ListenAndServe(":7777", router.HandleRequest))
}

I use ab and wrk for testing. Here is wrk command:

$ wrk -t10 -c100 -d10s http://somesite.com
Running 10s test @ http://somesite.com
  10 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    17.05ms    1.08ms  33.46ms   91.30%
    Req/Sec   587.80     33.97   670.00     84.92%
  58603 requests in 10.10s, 8.27MB read
Requests/sec:   5802.71
Transfer/sec:    838.67KB

I tried on two different servers. One of them is a simple Digital Ocean instance, but another is dedicated with 32G RAM, 8 cores and 1Gb network channel. The results are the same for both servers. I run fasthttp application on one of them and wrk on another, and wise versa.

James May
  • 1,371
  • 3
  • 20
  • 37

1 Answers1

13

In HTTP/1.0 benchmarks where each request is its own TCP connection the benchmark is really testing the server's TCP session setup and teardown. Not the web server.

I just reran your test (well sort of) using Go's net/http and the server process used 150% CPU. Out of 16 available CPUs. That's pathetic CPU usage. It gets much better if I use persistent HTTP/1.1 connections (try -k in ab). Then the server gets up to 600%.

If you want to serve a lot of small temporary TCP connections focus on improving your kernel's TCP performance. You can find guides online. It's mostly about disabling any firewalls or connection tracking, increasing available file descriptors and tweaking things like TCP Fast Open and reducing the timeouts on closed sockets.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131