Go HTTP server testing ab vs wrk so much difference in result
Firstly: benchmarks are often pretty artificial. Sending back a handful of bytes is going to net you very different results once you start adding database calls, template rendering, session parsing, etc. (expect an order of magnitude difference)
Then tack on local issues - open file/socket limits on your dev machine vs. production, competition between your benchmarking tool (ab/wrk) and your Go server for those resources, the local loopback adapter or OS TCP stacks (and TCP stack tuning), etc. It goes on!
In addition:
ab
is not highly regarded- It is HTTP/1.0 only, and therefore doesn't do keepalives
- Your other metrics vary wildly - e.g. look at the avg latency reported by each tool - ab has a much higher latency
- Your
ab
test also runs for12s
and not the5s
your wrk test does. - Even 8k req/s is a huge amount of load - that's 28 million requests an hour. Even if—after making a DB call, marshalling a JSON struct, etc—that went down to 3k/req/s you'd still be able to handle significant amounts of load. Don't get too tied up in these kind of benchmarks this early.
I have no idea what kind of machine you're on, but my iMac with a 3.5GHz i7-4771 can push upwards of 64k req/s on a single thread responding with a w.Write([]byte("Hello World\n"))
Short answer: use wrk
and keep in mind that benchmarking tools have a lot of variance.
POST request with wrk?
This is possible now. Here is an example https://github.com/wg/wrk/blob/master/scripts/post.lua.
wrk.method = "POST"
wrk.body = "foo=bar&baz=quux"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
save this in a *.lua
script and pass it into your command line test with the -s
flag.
Go server performance is the same when adding more cores
You need to tell the Go runtime to use more cores by setting the environment variable GOMAXPROCS
to your desired core count. Alternatively, there is also a function to change it.
By default, this is set to one. As of Go 1.5 it will be the number of cores in your system.
Go http server slow benchmark performance
Golang net/http is rather slow. If the goal is to maximize the requests rate there are other implementations. For example https://github.com/valyala/fasthttp In my tests fasthttp doubles the query rate. My test is a short request and short reply.
The library comes with limitations, like no HTTP/2 support. If you need HTTP for REST API and you are not looking for interoperability fasthttp will fit nicely
Related Topics
Change Filenames to Lowercase in Ubuntu in All Subdirectories
Differencebetween Module_Init and Init_Module in a Linux Kernel Module
Using Environment Variables in Curl Command - Unix
Cannot Clone Repository: Fatal: R Any Gitolite-Admin Gitolite Denied by Fallthru
Shell Variable Issue When Trying to Mkdir
How to Write-Protect Every Page in the Address Space of a Linux Process
Sed: How to Delete Lines Matching a Pattern That Contains Forward Slashes
Trying to Find All the Kernel Modules Needed for My MAChine Using Shell Script
Coreos - Get Docker Container Name by Pid
Cannot Sudo Su Anymore, "No Tty Present and No Askpass Program Specified"
How to Redirect from Audio Output to Mic Input Using Pulseaudio
How to Run an Opengl Application Installed on a Linux MAChine from My Windows MAChine