Author: HelloGitHub – Anthony

This is HelloGitHub’s “Open Source Project” series. This installment introduces the HTTP(S) pressure measuring tool vegeta, which is implemented in 17.7K pure Go language

Project address: github.com/tsenart/veg…

Vegeta is a multi-functional HTTP(S) stress test tool written in Go language. It is easy to install, fully functional and easy to use. It can also be used as a command line tool or as a development library. Not only does it provide the usual pressure testing functionality, it also supports formatting the results and output as a chart or dynamically displaying the current results.

In this article, you will learn the basics of this powerful pressure measuring tool and make it possible to test with just one command!

A, install,

Download the compiled binaries from the repository:

Github.com/tsenart/veg…

Download the AMD64 version on a PC and install it on Mac Os X using Homebrew:

$ brew update && brew install vegeta
Copy the code

If you know the Go language, use GET to install it automatically:

$ go get -u github.com/tsenart/vegeta
Copy the code

If the command cannot be found, make sure go and GOBIN are in your environment variables

Two, quick start

The following commands can be run under Linux

Vegeta is recommended to be temporarily added to PATH for easy use.

$ cd vegeta
$ export PATH=$pwd:$PATH
Copy the code

Or just put vegeta in the bin directory:

$ cd vegeta
$ sudo mv vegeta /usr/local/bin/
Copy the code

Vegeta-version is displayed as proof of successful installation.

For first use:

$ vegeta --help
Copy the code

To see the supported directives and related examples.

1. Examples

On the command line type:

$ echo "GET http://127.0.0.1:233"| vegeta attack -rate=500 -connections=1 -duration=1s | tee results.bin | vegeta report
Copy the code

You will get something like this:

Echo “GET http://127.0.0.1:233” in the first half of this directive indicates the address you want to test. I’m using nginx’s local server. Then -rate-connections-duration indicates the number of requests per second, the maximum number of connections per address, and the duration, respectively.

After the attack is complete, use tee Results.bin to save the test report and veteta report to display the report.

Vegeta Report also supports the use of text, JSON, histogram, hdrplot and more:

$ echo "GET http://127.0.0.1:233"| vegeta attack -rate=500 -connections=1 -duration=5s > results.bin
Copy the code

Text (default)

$ vegeta report results.bin
Copy the code

histogram

$ vegeta report -type='hist [0, 1 ms, ms, 2 3 ms, 4 ms)' results.bin
Copy the code

JSON

$ vegeta report --type json results.bin
Copy the code

hdrplot

$ vegeta report --type hdrplot results.bin
Copy the code

2. Generate graphics

In the following section, we turn the text report into a chart by typing:

$ vegeta plot --title HelloGitHub results.bin > plot.html
Copy the code

Open the newly generated plot. HTML in a browser and see the graphical test data:

Where –title HelloGitHub is used to set the header. In addition to

– CPU is used to set the number of CPU cores to be used by default. Here I default to 12. You can use the –threshold flag command to set the subsampling threshold.

Vegeta plot also allows you to put multiple curves together using vegeta plot result_1.bin result_.bin… Result_n. bin > plot. HTML

In addition, with jaggr and jplot under Go, dynamic screen output can be realized. The official instructions and effects are as follows:

$ echo 'GET http://localhost:8080'| \ vegeta attack - rate 5000 - duration 10 m | vegeta encode | \ jaggr @ count = RPS \ hist \ [100200300400500 \] : code \ p25,p50,p95:latency \ sum:bytes_in \ sum:bytes_out | \ jplot rps+code.hist.100+code.hist.200+code.hist.300+code.hist.400+code.hist.500 \ latency.p95+latency.p50+latency.p25 \ bytes_in.sum+bytes_out.sum

Copy the code

Jplot requires iTerm2 but I don’t have an Apple computer so you’ll have to work on the dynamic output.

3. Use pipes

If you are familiar with Shell pipes, you can see that we are using the pipe to send the output of echo “GET http:// XXX “to vegeta. Through the pipe, you can use the output of any program other than the simple Echo tool as a test target.

4. Switch codes

Vegeta also provides encoding conversion function. It now supports three encoding formats: Gob (binary), CSV and JSON (default). Using veget Encode you can convert these encoding to each other.

$ echo "GET http://127.0.0.1:233"| vegeta attack -rate=500 -connections=1 -duration=1s > results.gob
$ cat results.gob | vegeta encode | jq .
Copy the code

You can display the test information converted to JSON format, or:

$ cat results.gob | vegeta encode --to csv --output results.csv
Copy the code

The input format is automatically detected, and no manual setting is required.

Three, endnotes

Vegeta [Command] –help vegeta [command] –help vegeta [command] –help You can also read the official user manual

Project address: github.com/tsenart/veg…

Warm tip: although pressure testing is fun, do not drink oh, do not press up to pressure online service to hang up!


Follow the HelloGitHub public account to receive the first updates.

There are many more open source projects and treasure trove projects to be discovered.