NATS is fast and lightweight and places a priority on performance. NATS provides tools for measuring performance. In this tutorial you learn how to benchmark and tune NATS on your systems and environment.
Prerequisites
Start the NATS server with monitoring enabled
% nats-server -m 8222
Verify that the NATS server starts successfully, as well as the HTTP monitor:
[18541] 2016/10/31 13:26:32.037819 [INF] Starting nats-server version 0.9.4
[18541] 2016/10/31 13:26:32.037912 [INF] Starting http monitor on 0.0.0.0:8222
[18541] 2016/10/31 13:26:32.037997 [INF] Listening for client connections on 0.0.0.0:4222
[18541] 2016/10/31 13:26:32.038020 [INF] Server is ready
Installing and running the benchmark utility
The NATS benchmark can be installed and run via Go. Ensure your golang environment is setup.
There are two approaches; you can either install the nats-bench utility in the directory specified in your GOBIN environment variable:
% go install $GOPATH/src/github.com/nats-io/nats.go/examples/nats-bench/main.go
... or you can simply run it via go run:
% go run $GOPATH/src/github.com/nats-io/nats.go/examples/nats-bench/main.go
On windows use the % environment variable syntax, replacing $GOPATH with %GOPATH%.
For the purpose of this tutorial, we'll assume that you chose the first option, and that you've added the GOBIN environment variable to your PATH.
The nats-bench utility is straightforward to use. The options are as follows:
When specifying multiple publishers, or multiple subscribers, nats-bench will also report statistics for each publisher and subscriber individually, along with min/max/avg and standard deviation.
Let's increase both the number of messages, and the number of subscribers.: