weighttp¶
About¶
weighttp (pronounced weighty) is a lightweight and small benchmarking tool for webservers.
weighttp was designed to be very fast and easy to use and only supports a tiny fraction of the HTTP 1.x protocol in order to be lean and simple.weighttp supports multithreading to make good use of modern CPUs with multiple cores as well as event-driven I/O for concurrent requests within a single thread.
Similar tools¶
Deployment¶
Obtaining¶
Use git to fetch the latest source:
$ git clone https://git.lighttpd.net/lighttpd/weighttp.git
or download a .tar.gz from https://git.lighttpd.net/lighttpd/weighttp/archive/master.tar.gz
Binary packages are available from https://build.opensuse.org for openSUSE and Debian based distributions:
Building¶
meson¶
meson setup --buildtype debugoptimized --prefix /usr/local build cd build meson compile #sudo meson install
autotools¶
$ ./autogen.sh $ ./configure $ make
The executable is created as src/weighttp
Alternatively, you can use gcc directly.
$ gcc -g2 -O2 src/*.c -o weighttp -lpthread -lm
Usage¶
weighttp uses similar command line arguments as apache bench (ab) for the subset of features supported by weighttp:
weighttp <options> <URI>
-n num number of requests (mandatory)
-t num thread count (default: 1) (note: differs from @ab -t timeout@)
-c num concurrent clients (default: 1)
-k keep alive (default: no)
-K num num pipelined requests (default: 1) (note: not a feature of @ab@)
-6 use ipv6 (default: no)
-i use HTTP HEAD method (default: GET)
-m method use custom HTTP method (default: GET)
-H str add header to request ("label: value"); repeatable
-b size socket buffer sizes (SO_SNDBUF, SO_RCVBUF)
-B addr local address to bind to when making outgoing connections
-C cookie add cookie to request ("cookie-name=value"); repeatable
-F use TCP Fast Open (RFC 7413)
-T type Content-Type header to use for POST/PUT data,
e.g. application/x-www-form-urlencoded
(default: text/plain)
-A string add Basic WWW Authorization (str is username:password)
-P string add Basic Proxy-Authorization (str is username:password)
-X proxy proxy:port or unix domain socket path beginning w/ '/'
-p file make HTTP POST request using file contents for body
-u file make HTTP PUT request using file contents for body
-d do not report extended percentiles (beyond min,mean,max)
-S do not show standard deviation confidence warnings
-l (ignored; compatibility with Apache Bench (ab))
-e file output CSV file with percentages for total time to serve
-r (ignored; compatibility with Apache Bench (ab))
-a time max seconds to run benchmark (or until -n requests)
-s cutoff seconds to cutoff fails (default: 4)
-q quiet: do not show version header or progress
-h show help and exit
-V show version and exit
Troubleshooting¶
Benchmarking a webserver can result in a lot of sockets being created, especially if you don't use the -k parameter to reuse existing connections.
This can cause your system to run out of TCP port numbers and you will see the following error:
error: connect() failed: Cannot assign requested address (99)
Linux has a hardcoded 60 seconds timeout before it reuses a previously in use port. You can mitigate the problem by tuning 2 kernel parameters:
TCP_TW_REUSE¶
Linux can be configured to allow reuse of sockets which are in the TIME_WAIT state when it is safe from a protocol perspective.
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
or add "net.ipv4.tcp_tw_reuse = 1" to your /etc/sysctl.conf to make the change permanent. You need to reload it via sysctl /etc/sysctl.conf
TCP_TW_RECYCLE¶
Note: TCP_TW_RECYCLE has been removed since Linux 4.12
Linux before Linux 4.12 can be configured to allow fast recycling of sockets which are in the TIME_WAIT state even if it is not safe from a protocol perspective.
You should not use this in a production environment. It can cause issues with load balancers and other mayhem.
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
or add "net.ipv4.tcp_tw_recycle = 1" to your /etc/sysctl.conf to make the change permanent (bad idea). You need to reload it via sysctl /etc/sysctl.conf
Updated by gstrauss 7 months ago ยท 15 revisions locked