How to Use the Command 'siege' (with examples)
Siege is a powerful HTTP load testing and benchmarking tool designed for developers and administrators who need to evaluate the performance of web applications and server environments. It offers functionalities to test URLs by simulating multiple concurrent users generating a load on the server. This assists in identifying bottlenecks, ensuring stability, and improving the capacity planning of web services. Below are detailed use cases showcasing the diverse applications of the siege command.
Test a URL with Default Settings
Code:
siege https://example.com
Motivation:
Using the simple command siege https://example.com
provides a straightforward way to test the performance of a single web page without any additional configuration. This is particularly useful for preliminary checks or when quick feedback is needed on how a page performs under load without specifying other parameters.
Explanation:
siege
: This is the command-line tool being used for load testing.https://example.com
: This is the target URL you wish to test. By default, siege will determine appropriate settings for the test, simulating a basic user load.
Example Output:
Transactions: 1000 hits
Availability: 99.90 %
Elapsed time: 29.57 secs
Data transferred: 1.23 MB
Response time: 0.09 secs
Transaction rate: 33.98 trans/sec
Throughput: 0.04 MB/sec
Concurrency: 3.03
Successful transactions: 999
Failed transactions: 1
Longest transaction: 1.23
Shortest transaction: 0.01
Test a List of URLs
Code:
siege --file path/to/url_list.txt
Motivation:
Testing multiple URLs is crucial for understanding how different parts of a web application perform, as it allows the tester to assess the robustness and stability of different endpoints of their application. By using a file containing multiple URLs, siege enables comprehensive testing of an entire site or application architecture.
Explanation:
siege
: Initiates the siege testing.--file path/to/url_list.txt
: Specifies the list of URLs to be tested, effectively testing multiple endpoints or resources in a single execution.
Example Output:
Transactions: 5000 hits
Availability: 99.60 %
Elapsed time: 50.13 secs
Data transferred: 15.00 MB
Response time: 0.12 secs
Transaction rate: 99.76 trans/sec
Throughput: 0.30 MB/sec
Concurrency: 11.97
Successful transactions: 4968
Failed transactions: 32
Longest transaction: 2.01
Shortest transaction: 0.01
Test List of URLs in a Random Order
Code:
siege --internet --file path/to/url_list.txt
Motivation:
Simulating real-world internet traffic scenarios is essential for realistic load testing. By testing URLs in random order, siege helps mimic the unpredictable patterns in which users might access different resources in an application, contributing to a more robust analysis of performance under authentic user conditions.
Explanation:
siege
: The command to start siege.--internet
: This flag indicates that the URLs will be accessed in a random order, simulating non-sequential user access patterns.--file path/to/url_list.txt
: Refers to the list of URLs to be tested in random order.
Example Output:
Transactions: 3000 hits
Availability: 100.00 %
Elapsed time: 30.00 secs
Data transferred: 9.89 MB
Response time: 0.10 secs
Transaction rate: 100.00 trans/sec
Throughput: 0.33 MB/sec
Concurrency: 10.00
Successful transactions: 3000
Failed transactions: 0
Longest transaction: 1.10
Shortest transaction: 0.01
Benchmark a List of URLs
Code:
siege --benchmark --file path/to/url_list.txt
Motivation:
Benchmarking without waiting between requests is essential for stress testing. This scenario provides essential benchmarks to understand the limits of server performance by maximizing the request load. It can reveal how a server handles peak traffic conditions and aids in uncovering potential breakdowns or failures under stress.
Explanation:
siege
: Initiates the siege test.--benchmark
: This option removes the simulated delay between users, allowing a constant surge of requests to benchmark absolute performance.--file path/to/url_list.txt
: Indicates the URLs to be tested in a rapid succession.
Example Output:
Transactions: 10000 hits
Availability: 99.80 %
Elapsed time: 100.00 secs
Data transferred: 25.00 MB
Response time: 0.20 secs
Transaction rate: 100.00 trans/sec
Throughput: 0.25 MB/sec
Concurrency: 20.00
Successful transactions: 9980
Failed transactions: 20
Longest transaction: 3.10
Shortest transaction: 0.01
Set the Amount of Concurrent Connections
Code:
siege --concurrent=50 --file path/to/url_list.txt
Motivation:
The ability to set concurrent connections means testing how well a server can manage multiple requests at the same time. It is especially useful when the server must handle high traffic or concurrent operations, reflecting scenarios such as promotional campaigns, sales events, or release dates, where multiple users access the application simultaneously.
Explanation:
siege
: Runs the siege test.--concurrent=50
: Configures siege to simulate 50 users making concurrent requests, providing a measure of how performance scales with user count.--file path/to/url_list.txt
: Points to the URLs being tested with the specified concurrency level.
Example Output:
Transactions: 5000 hits
Availability: 99.80 %
Elapsed time: 100.13 secs
Data transferred: 50.00 MB
Response time: 0.50 secs
Transaction rate: 50.00 trans/sec
Throughput: 0.50 MB/sec
Concurrency: 50.00
Successful transactions: 4989
Failed transactions: 11
Longest transaction: 2.00
Shortest transaction: 0.01
Set How Long for the Siege to Run
Code:
siege --time=30s --file path/to/url_list.txt
Motivation:
Setting a specific duration for running siege tests allows for focused performance monitoring over a predefined time frame. This is particularly beneficial for quick tests or repeated assessments over short intervals to gather critical performance data without overloading the server.
Explanation:
siege
: Engages the siege tool.--time=30s
: Sets the duration of the test to 30 seconds, making it finite and allowing for repeated trials or truncated testing cycles.--file path/to/url_list.txt
: Specifies the list of URLs to be executed under the time constraints.
Example Output:
Transactions: 1500 hits
Availability: 100.00 %
Elapsed time: 30.00 secs
Data transferred: 4.50 MB
Response time: 0.10 secs
Transaction rate: 50.00 trans/sec
Throughput: 0.15 MB/sec
Concurrency: 15.00
Successful transactions: 1500
Failed transactions: 0
Longest transaction: 1.00
Shortest transaction: 0.01
Conclusion
The siege command offers comprehensive features for load testing and benchmarking in web applications, catering to various needs from simple URL tests to more complex scenarios involving concurrency and benchmarking under different conditions. It empowers developers and administrators to perform rigorous assessments of web server performance, providing crucial insights to enhance the user’s experience and ensure consistent uptime. By mastering these examples, testers can exploit siege’s full potential, creating robust, scalable, and stable server environments.