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.
Installing Go1.7 and Hey
Run
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
--binary
as indicated here.
gvm install go1.4
gvm use go1.4
Run
gvm install go1.7
Switch to the version required by hey
gvm use go1.7
Check if you have GOPATH configured using
echo $GOPATH
Install hey.
go get -u github.com/rakyll/hey to install hey
Confirm installation
which hey
Et voilΓ . We have installed hey.
A simple benchmark
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.
Top comments (3)
Thanks for the article! For Ubuntu 16.04/18.04 first installation of go1.4 should looks like:
gvm install go1.4 -B
I'll have to check out Hey! I've always used Locust for my projects. github.com/locustio/locust
I did come across Locus but using it meant to get ramped up with basic Python. Hey worked right out of the box with good CLI parameters. I'll check out Locus when I have a bit more free time to play around with it!