Project

General

Profile

Start » History » Revision 14

Revision 13 (gstrauss, 2025-03-21 02:37) → Revision 14/15 (gstrauss, 2025-04-08 12:55)

h1. weighttp 

 h2. 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. 

 h2. Similar tools 

 * "ab":https://httpd.apache.org/docs/current/programs/ab.html 
 * "httperf":https://github.com/httperf/httperf 
 * "httpress":https://github.com/yarosla/httpress 
 * "wrk2":https://github.com/giltene/wrk2 

 h2. Deployment 

 h3. Obtaining 

 Use "git":https://git-scm.com/ to fetch the latest source: 

 <pre> 
 $ git clone https://git.lighttpd.net/lighttpd/weighttp.git 
 </pre> 

 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: 

 * "server:http":https://build.opensuse.org/package/show/server:http/weighttp 
 * "home:stbuehler:lighttpd-utils":https://build.opensuse.org/package/show/home:stbuehler:lighttpd-utils/weighttp 

 h3. Building 

 h4. meson 

 <pre> 
 meson setup --buildtype debugoptimized --prefix /usr/local build 
 cd build 
 meson compile 
 #sudo meson install 
 </pre> 

 h4. autotools 

 <pre> 
 $ ./autogen.sh 
 $ ./configure 
 $ make 
 </pre> 

 The executable is created as @src/weighttp@ 

 Alternatively, you can use gcc directly. 

 <pre> 
 $ gcc -g2 -O2 src/*.c -o weighttp -lpthread -lm 
 </pre> 

 h2. Usage 

 @weighttp@ uses similar command line arguments as @apache bench@ (ab) for the subset of features supported by weighttp: 

 <pre> 
 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           (ignored; compatibility with Apache Bench (ab)) 
   -l           (ignored; compatibility with Apache Bench (ab)) 
   -r           (ignored; compatibility with Apache Bench (ab)) 
   -q           quiet: do not show version header or progress 
   -h           show help and exit 
   -V           show version and exit 
 </pre> 

 h2. 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: 
 <pre> 
 error: connect() failed: Cannot assign requested address (99) 
 </pre> 
 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: 

 h3. 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. 
 <pre> 
 echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse 
 </pre> 
 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_ 

 h3. 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. 
 <pre> 
 echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle 
 </pre> 
 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_