Project

General

Profile

Start » History » Revision 13

Revision 12 (stbuehler, 2025-03-20 10:02) → Revision 13/15 (gstrauss, 2025-03-21 02:37)

h1. weighttp 

 h2. About 

 @weighttp@ (pronounced @weighty@) is a lightweight and small benchmarking tool for webservers. 

 @weighttp@ 
 It 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 asynchronous i/o 
 for concurrent requests within a single thread. 
 For event handling, weighty relies on "libev":https://software.schmorp.de/pkg/libev.html which fits the design perfectly, being lightweight and fast itself. 
 Thanks to that, weighty supports all modern high-performance event interfaces like epoll or kqueue, that the major OSs provide. 

 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 

 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 Use "waf":http://code.google.com/p/waf/ (included, needs python) to build: 

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

 h4. autotools (If you have libraries/includes in special paths, try something like this: @LINKFLAGS=-L/opt/local/lib CFLAGS=-I/opt/local/include ./waf configure@) 

 <pre> 
 $ ./autogen.sh 
 $ ./configure 
 $ make 
 </pre> See ./waf --help for available configure options and other commands available. 

 The executable is created as @src/weighttp@ 

 Alternatively, you can just use gcc directly. directly too (but you will have to (un)install it manually: 

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

 h3. Installing 

 Depending on your configure arguments, you might need root to (un)install. 

 <pre> 
 $ ./waf install 
 </pre> 

 h3. Removing 

 <pre> 
 $ ./waf uninstall 
 </pre> 

 h2. Usage 

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

 <pre> 
 weighttp <options> <URI> <url> 
   -n num           number of requests        (mandatory) 
   -t num       thread count                  threadcount (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           -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 This allows reusing of sockets which are in the TIME_WAIT state when it is safe from a protocol perspective. perspectiv. 
 <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 This allows 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 loadbalancers 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_