Siege Command to Benchmark a Website: 5 Easy Fixes
The siege command is a small HTTP load tester: you give it a URL, a number of simulated users and a duration, and it prints how many requests the server handled. The old version of this post gave three commands and a config edit, but two details do not work as written on a current system. This rewrite runs the siege command 4.1.6 on Debian 13 against a local nginx, so you see the real output, the real error messages, and one result that is easy to misread.
Scope: the target was a local nginx serving the default page, in the same container. The numbers (tens of thousands of requests per second) show how the tool behaves, not how fast any real server is. Test only sites that you own or have permission to test.
Contents
Install the siege command and find the config file
On Debian and Ubuntu the package is called siege: sudo apt-get install -y siege. The old post then told you to edit /etc/siege/siegerc to enable logging. That file exists, but it is only a template. At the first run, siege printed New configuration template added to /root/.siege, and created ~/.siege/siege.conf. This per-user file is the one siege reads afterwards. Open it, not the file in /etc:
nano ~/.siege/siege.conf
In that file the lab showed logging = false, show-logfile = true and limit = 255, and the line logfile was commented out. When the same logfile line was edited in /etc/siege/siegerc after the first run, the siege command still used its default and failed, as shown below. So the edit in the old post has no effect for a user who has already run siege once.
Run a test with the siege command
The old example was siege https://SERVER -c 100 -t 5m: 100 concurrent users for five minutes. The lab used the same options with a shorter time, siege -c 10 -t 5S http://localhost/, where S means seconds. After the line "Lifting the server siege..." it printed the summary:
Transactions: 163330 hitsandAvailability: 100.00 %;Elapsed time: 5.79 secs,Data transferred: 61.84 MB,Transaction rate: 28208.98 trans/sec;Concurrency: 8.80,Successful transactions: 163331,Failed transactions: 0.
According to the siege manual, each simulated user waits half a second between requests by default (--delay=0.5), and the option -b (benchmark mode) means there is no delay between iterations. With -b -c 20 -t 3S the local site reached 38499 transactions per second. Use -b only on a test server, because it is a stress test, not a model of real visitors. If you run a rate limit such as the one in the iptables how-to, your own test machine can be blocked by it.

Save the siege command log
The option -l writes a line of results to a log file. With the default configuration the lab run printed LOG FILE: /var/log/log/siege.log and then unable to create log file: /var/log/log/siege.log: No such file or directory. The path contains log twice, so the default does not work on this version without a change. Editing /etc/siege/siegerc gave the same error. In ~/.siege/siege.conf the working line was:
logfile = $(HOME)/var/log/siege.log
This still failed with unable to create log file: /root/var/log/siege.log until the directory existed, so run mkdir -p ~/var/log first. After that siege -q -c 5 -t 2S -l http://localhost/ wrote a CSV file with the columns Date & Time, Trans, Elap Time, Data Trans, Resp Time, Trans Rate, Throughput, Concurrent, OKAY and Failed. The first row had 57525 transactions in 2.86 seconds and 0 failed.
Test several URLs with the siege command
The old post put one site per line in a file and ran siege -f ~/huuphan-sites.txt. The format works, and the lines may be written without http://. The lab used a file with localhost and localhost/missing and the options -c 2 -r 3 (two users, three repetitions each). That is six requests, and siege printed Transactions: 6 hits. Note that every site in the file receives real traffic, so do not list sites that are not yours: the old example file with www.example.org would send requests to that public site.
Read the results: a 404 is not a failure
The most useful detail is hidden in the summary. A run against a page that does not exist (siege -c 1 -r 2 -d 1 localhost/missing) printed two lines HTTP/1.1 404, and then Transactions: 2 hits, Availability: 100.00 %, Successful transactions: 0 and Failed transactions: 0. Availability counts answered requests, not correct ones. A load test that points at a wrong URL, or at a login page that returns errors, can therefore still show 100%. Always read the status lines and the "Successful transactions" value, and compare them with the number of hits.
The user limit and common mistakes
The option -c 300 printed Preparing 255 concurrent users for battle and the warning that the number of users is capped at 255; the limit comes from limit = 255 in the config. Raise it in ~/.siege/siege.conf if you need more, and check the open file limit of your shell. Mistakes to avoid with the siege command:
- Editing
/etc/siege/siegercafter the first run and expecting a change. - Using
-lwithout a valid log path and an existing directory. - Trusting "100% availability" without looking at the HTTP status codes.
- Testing a site that is not yours, or testing production with
-b.
The options are described in the siege manual linked above and in the siege repository. If you test a site behind a reverse proxy, see the Apache ProxyPassReverse and nginx post to check the redirect headers first.
FAQ
Does the siege command work with HTTPS? The old post used https://SERVER; only plain HTTP to localhost was tested here.
How long should a test run? The old post used five minutes. The lab used seconds, only to show the output. Pick a time long enough for the server to reach a steady state.
Comments
Post a Comment