How to Use the Command 'vegeta' (with Examples)

How to Use the Command 'vegeta' (with Examples)

Vegeta is a versatile and powerful command-line utility and library for HTTP load testing. It allows developers, testers, and DevOps professionals to simulate a high volume of HTTP requests to test the performance and scalability of web services. Its flexibility and robust nature make it a popular choice for ensuring that applications can handle traffic efficiently.

Use case 1: Launch an Attack Lasting 30 Seconds

Code:

echo "GET https://example.com" | vegeta attack -duration=30s

Motivation:

Testing the endurance of a web service over a sustained period. The idea is to simulate a 30-second burst of traffic, to observe how the server handles requests continuously over this timeframe.

Explanation:

  • echo "GET https://example.com": This part of the command specifies the HTTP request that will be sent repeatedly. It’s a simple GET request to the URL https://example.com.
  • |: The pipe operator is used to pass the output of the echo command directly into the Vegeta attack command.
  • vegeta attack: This initializes the Vegeta attack process.
  • -duration=30s: This option specifies that the attack should last for 30 seconds. During this time, Vegeta will continuously send requests as quickly as possible.

Example Output:

Requests      [total, rate, throughput]      2000, 67.32, 66.65
Duration      [total, attack, wait]          30.047s, 29.736s, 311.594ms
Latency       [min, avg, 95, max]            100.5ms, 1050.3ms, 1500ms, 3000ms
Bytes In      [total, mean]                  500000, 250.00
Bytes Out     [total, mean]                  0, 0.00
Success       [ratio]                        90.00%
Status Codes  [code:count]                   200:1800  500:200
Error Set:
500 Internal Server Error

Use case 2: Launch an Attack on a Server with a Self-Signed HTTPS Certificate

Code:

echo "GET https://example.com" | vegeta attack -insecure -duration=30s

Motivation:

Testing web services with self-signed certificates without validation—useful for internal development environments where securing an official certificate might not be necessary.

Explanation:

  • -insecure: This flag tells Vegeta to proceed with the attack even if the SSL/TLS certificate cannot be verified. It bypasses normal security checks, allowing you to test servers with self-signed certificates.

Example Output:

Requests      [total, rate, throughput]      1900, 63.33, 63.15
Duration      [total, attack, wait]          30.020s, 30.000s, 20ms
Latency       [min, avg, 95, max]            120.1ms, 1120.6ms, 1420.2ms, 3123.3ms
Bytes In      [total, mean]                  475000, 250.00
Bytes Out     [total, mean]                  0, 0.00
Success       [ratio]                        93.00%
Status Codes  [code:count]                   200:1767  500:133
Error Set:
500 Self-Signed SSL Error

Use case 3: Launch an Attack with a Rate of 10 Requests per Second

Code:

echo "GET https://example.com" | vegeta attack -duration=30s -rate=10

Motivation:

Control the rate of requests to simulate precise load conditions. This is useful when testing specific user load scenarios to predict performance under typical traffic conditions.

Explanation:

  • -rate=10: This specifies the number of requests per second that Vegeta should generate. Setting a specific rate helps to apply a predictable and consistent load on the server.

Example Output:

Requests      [total, rate, throughput]      300, 10.00, 9.89
Duration      [total, attack, wait]          30.436s, 30.000s, 436ms
Latency       [min, avg, 95, max]            50.2ms, 548.1ms, 890.0ms, 1900.0ms
Bytes In      [total, mean]                  75000, 250.00
Bytes Out     [total, mean]                  0, 0.00
Success       [ratio]                        98.00%
Status Codes  [code:count]                   200:294  500:6
Error Set:
500 Internal Server Error

Use case 4: Launch an Attack and Display a Report

Code:

echo "GET https://example.com" | vegeta attack -duration=30s | vegeta report

Motivation:

Generate an immediate human-readable performance report directly after an attack. Reports help in understanding the attack performance without needing additional tools or scripts.

Explanation:

  • | vegeta report: This takes the output from the Vegeta attack and processes it into a plain text report format, showing key performance metrics immediately on the console.

Example Output:

Targets      [        total       through  ]       3000,   2892
Throughput   [     min,    avg,    max     ]       80.0,  88.0, 101.0
Success      [    total,    ratio,    count]     2900,  96.67,
Latency      [     min,    avg, 95%]            54ms,  543ms, 750ms
HTTP Codes   [Code:Count]                      200:2900, 500:100
Errors:
500 Internal Server Error
Failure (ratio=3.3%)

Use case 5: Launch an Attack and Plot Results on a Graph (Latency Over Time)

Code:

echo "GET https://example.com" | vegeta attack -duration=30s | vegeta plot > path/to/results.html

Motivation:

Visualize attack data to analyze latency trends over time. Graphs provide a clearer and more digestible insight into performance patterns, highlighting potential issues like latency spikes.

Explanation:

  • | vegeta plot: This processes the attack output into an HTML file that graphically represents the performance data.
  • > path/to/results.html: Redirects the HTML output to a file. This file can be opened in a web browser to view the latency over time.

Example Output:

Graph Example

(In the actual output, the graph will show latency over time with peaks and valleys indicating response time fluctuations.)

Use case 6: Launch an Attack Against Multiple URLs from a File

Code:

vegeta attack -duration=30s -targets=requests.txt | vegeta report

Motivation:

Test a suite of URLs simultaneously, such as all endpoints of a REST API. This is useful for comprehensive testing and ensuring the robustness of multiple services handled by the same server.

Explanation:

  • -targets=requests.txt: Specifies a text file containing a list of HTTP requests to execute. Each line in the file could have a format like “GET https://example.com/api/v1/resource" .

Example Output:

Targets      [total, rate, throughput]      5000, 166.67, 160.34
Duration     [total, attack, wait]          30.343s, 30.000s, 343ms
Latency      [min, avg, 95, max]            28ms, 404ms, 700ms, 1500ms
Bytes In     [total, mean]                  1250000, 250.00
Bytes Out    [total, mean]                  0, 0.00
Success      [ratio]                        97.00%
Status Codes [code:count]                   200:4850  500:150
Error Set:
500 Internal Server Error

Conclusion:

Vegeta provides a robust toolset for conducting load testing and analyzing the performance of HTTP services. Whether you are testing single endpoints, managing load rates, dealing with self-signed certificates, or visualizing results, Vegeta offers a straightforward and efficient way of ensuring your infrastructure can handle the expected (or unexpected) load. With the examples provided, users can leverage Vegeta for various scenarios to ensure their web services are robust and ready for production traffic.

Related Posts

How to use the command 'hwclock' (with examples)

How to use the command 'hwclock' (with examples)

The hwclock command is a powerful tool used in Unix-like operating systems to interact with the hardware clock of your computer.

Read More
How to Utilize the 'mandb' Command (with examples)

How to Utilize the 'mandb' Command (with examples)

The mandb command is a powerful tool used in UNIX-like operating systems for managing the pre-formatted manual page databases, commonly referred to as “man pages.

Read More
Exploring the 'qtile' Command (with examples)

Exploring the 'qtile' Command (with examples)

QTile is a sophisticated and customizable tiling window manager written in Python.

Read More