I was trying to benchmark a service that I was building using Apache AB and running into some issues with it (Damn you AB for not supporting HTTP/1.1). I looked up alternatives to AB, and found hey. It's written in Golang and is pretty nifty.
In this post, I will walk you through a setup of golang and hey on your instance and a simple benchmark. Hey requires a Go version of 1.7 and above, and this makes the setup process look time consuming since the yum repo installs Go 1.6, and any Google search to install Go 1.7 will be met with a collection of
wget, tar, export and make. Fortunately, there's gvm, which simplifies things for us.
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
This installs GVM.
Install Go1.4 and make it default. This is needed because some parts of Go 1.5 and above are bootstrapped, so Go 1.7 needs an existing version of Go to install itself. (If the install step fails, try with
--binaryas indicated here.
gvm install go1.4
gvm use go1.4
gvm install go1.7
Switch to the version required by hey
gvm use go1.7
Check if you have GOPATH configured using
go get -u github.com/rakyll/hey to install hey
Et voilÃ . We have installed hey.
hey -n 10 -c 2 -m POST -T "application/x-www-form-urlencoded" -d 'username=1&message=hello' http://your-rest-url/resource
This opens 2 connections, and sends 10 requests. Each request is a form post with 2 parameters to your resource. Tweak the command to add/remove more flags as you need it.