Project

General

Profile

Start » History » Revision 7

Revision 6 (stbuehler, 2012-08-11 10:42) → Revision 7/10 (stbuehler, 2012-11-30 17:12)

h1. weighttp 

 h2. About 

 @weighttp@ (pronounced @weighty@) is a lightweight and small benchmarking tool for webservers. 
 It was designed to be very fast and easy to use and only supports a tiny fraction of the HTTP protocol in order to be lean and simple. 
 @weighttp@ supports multithreading to make good use of modern CPUs with multiple cores as well as asynchronous i/o 
 for concurrent requests within a single thread. 
 For event handling, weighty relies on "libev":http://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. Deployment 

 h3. Obtaining 

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

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

 or download a .tar.gz from http://cgit.lighttpd.net/weighttp.git/snapshot/weighttp-master.tar.gz http://cgit.lighttpd.net/weighttp/snapshot/weighttp-master.tar.gz 

 h3. Bulding 

 Use "waf":http://code.google.com/p/waf/ (included, needs python) to build: 

 <pre> 
 $ ./waf configure 
 $ ./waf build 
 </pre> 

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

 See ./waf --help for available configure options and other commands available. 

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

 <pre> 
 $ gcc -g2 -O2 src/*.c -o weighttp -lev -lpthread 
 </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 commandline arguments as @apache bench@ (ab): 

 <pre> 
 weighttp <options> <url> 
   -n num     number of requests (mandatory) 
   -t num     threadcount (default: 1) 
   -c num     concurrent clients (default: 1) 
   -k         keep alive (default: no) 
   -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 

 This allows reusing of sockets which are in the TIME_WAIT state when it is safe from a protocol 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 

 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 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_