This directory sets up a Siege client that will be used to stress test or benchmark the Python Django Workload.
This setup relies on the host system having Siege installed. We will guide you on how to make best use of this tool.
To install Siege and the dependencies for the runner script on Ubuntu 16.04, issue the following command:
apt-get install siege python3-numpy
This will install Siege version 3.0.8. There are no known version requirements for Siege at the moment, although older versions might not allow concurrency levels higher than 256, which can be insufficient to properly stress a certain system.
Siege uses a urls.txt file to know where to direct the requests. This file can be regenerated by modifying the urls_template.txt to point to different pages or to assign new weigths to your urls (some pages are accessed more than others).
The default urls.txt points to localhost:8000 and uses URL weights that follow real life usage we observed.
Use the ./gen-urls-file to generate a new urls.txt from the urls_template.txt:
./gen-urls-file
You must have Python 3 installed to run the above script.
Run siege using the ./run-siege script:
./run-siege
This script can be configured to suit your needs by altering the following environment variables that change the Siege parameters:
WORKERS - specifies the number of concurrent Siege workers
DURATION - specifies the run time of the benchmark, in the format "XY",
where X is a number and Y is the time unit (H, M or S, for
hours, minutes or seconds)
LOG - specifies the log file for Siege
SOURCE - specifies the input file that tells Siege what urls to
benchmark
The command above that launches the Siege client is equivalent to the command below, where the configuration parameters have the default value:
WORKERS=144 DURATION=2M LOG=./siege.log SOURCE=urls.txt ./run-siege
Running siege will possibly throw the following error:
[error] socket: 1384314624 address is unavailable.: Cannot assign requested
address
This is due to reaching OS limits for open file descriptors (sockets in this case). In order to prevent this, please perform the following steps:
1. Modify /etc/sysctl.conf by adding the following lines:
...
net.ipv4.tcp_tw_reuse=1
net.ipv4.ip_local_port_range=1024 64000
net.ipv4.tcp_fin_timeout=45
net.core.netdev_max_backlog=10000
net.ipv4.tcp_max_syn_backlog=12048
net.core.somaxconn=1024
net.netfilter.nf_conntrack_max = 256000
...
#then apply
sudo sysctl -f
The nf_conntrack module might need to be loaded:
sudo modprobe nf_conntrack
To make it persistent, add it to /etc/modules.
2. Set open files to 1 milion
sudo vim /etc/security/limits.conf
# insert the following lines at the end of this file
* soft nofile 1000000
* hard nofile 1000000
# check original values as this example ouput:
ulimit -n
1024
# reboot system and check the values again:
ulimit –n
1000000
# the “open files” value is now set at 1,000,000
Sometimes siege will abort the run if it reaches its own internal error threshold. This threshold can be adjusted in the ~/.siegerc file (may need to be created) using the following attribute:
failures = 1000000
When running all the services on a single machine, it is also possible to hit the PID limit for the current user, resulting in Siege errors like:
[error] Inadequate resources to create pool crew.c:87: Resource temporarily unavailable
[fatal] unable to allocate memory for 185 simulated browser: Resource temporarily unavailable
When this error appears, you will not be able to open another terminal:
-bash: fork: retry: Resource temporarily unavailable
Solving this requires setting a large enough value for the systemd UserTasksMax variable:
sudo vim /etc/systemd/logind.conf
[Login]
# insert the following line under the Login attribute
UserTasksMax=1000000
Reboot for the changes to take effect.