Apache bench marking
=======================
Things or checklist to be considered before the test
CPU: avoid power-saving mode. cpufreq-set -g performance.
File descriptors: raise the limit to (at least) the number of concurrent connections you wish to handle, using ulimit -n in your shell, or setrlimit(RLIMIT_NOFILE) in your server. Beware, some systems forbid you to raise the limit, you might need to investigate a bit to find how to unlock it.
Disable the logs of your server (you do not want to lose time logging thousands of requests instead of answering them).
Raise /proc/sys/net/somaxconn to the number of concurrent connections you want to handle. To understand why this is necessary, read the technical report or the excellent paper Measuring the Capacity of a Web Server (Banga and Druschel, Usenix 97). More on the fascinating topic of the accept() queue can be found in accept()able Strategies for Improving Web Server Performance (Brecht et al., Usenix 04) and in the libev manual. You should really read these references: this is one of the trickiest part of a web server behavior under heavy load, very easy to misinterpret (or to get wrong when you write a server). Using http_load is helpful when debugging this part because it gives the effective number of concurrent requests it has been able to perform, unlike Apache Bench which will happily pretend it managed to reach 1024 concurrent connections when the server is in fact limited to 128.
You also need to tune the client: the same advices apply. Do not forget to use a client faster than your server (or to use several client simultaneously) and to link them through a dedicated switch to ensure the bottleneck does not lie in the network.
TCP_TW_REUSE
This allows reusing of sockets which are in the TIME_WAIT state when it is safe from a protocol perspectiv.
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
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.
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
http://www.rootusers.com/web-server-performance-benchmark/
weighttp -n 100000 -c [0-1000 step:10] -t X -k "http://127.0.0.1:80/100.html"
http://adolgarev.blogspot.in/2013/12/performance-analysis-of-our-own-full.html
=============================================
ps -ylC httpd --sort:rss
Apache Max clients= Total Ram allocated to apache/ apache child process size
http://www.zarafa.com/wiki/index.php/Apache_tuning
ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
# ps -u apache -opid,ppid,nlwp
PID PPID NLWP
10622 10604 27
10654 10604 27
* How to get the total thread counts: #
ps -u apache -Lf | wc -l
55
or CentOS/RedHat and openSUSE/SLES will use httpd or httpd2
ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
===============================================
Lets take an example. I have a server below apache 2.4 and mpm event
[~]# free -g
total used free shared buffers cached
Mem: 31 15 15 0 0 12
-/+ buffers/cache: 3 28
Swap: 3 0 3
That is having 31 GB memory.
ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
Apache Memory Usage (MB): 233.23
Average Proccess Size (MB): 77.7435
There is enough memory and I can have number of child process upto
The average process size of 398
398 * 77 =30 GB
We need to allot memory to other process in the server also. So we can choose a child process limit of 200. This would be the server limit. Now we can tune apache on basis of mpm event . Say we need the server to handle connection of 25000 concurrent
We can go like below
ServerLimit 200
MaxRequestWorkers 25600
MaxConnectionsPerChild 0
KeepAlive On
KeepAliveTimeout 25
MaxKeepAliveRequests 10000
Keep alive reduces CPU overhead. Here I given start server of 50
MinSpareThreads 32
MaxSpareThreads 100
ThreadsPerChild 128
ThreadLimit 128
ListenBacklog 4096
=========================================
http://httpd.apache.org/docs/2.4/mod/event.html
http://httpd.apache.org/docs/current/mod/worker.html
http://www.genericarticles.com/mediawiki/index.php?title=How_to_optimize_apache_web_server_for_maximum_concurrent_connections_or_increase_max_clients_in_apache#mpm_worker_module
http://blog-en.openalfa.com/how-to-configure-apache-mpm-worker
=======================
Things or checklist to be considered before the test
CPU: avoid power-saving mode. cpufreq-set -g performance.
File descriptors: raise the limit to (at least) the number of concurrent connections you wish to handle, using ulimit -n in your shell, or setrlimit(RLIMIT_NOFILE) in your server. Beware, some systems forbid you to raise the limit, you might need to investigate a bit to find how to unlock it.
Disable the logs of your server (you do not want to lose time logging thousands of requests instead of answering them).
Raise /proc/sys/net/somaxconn to the number of concurrent connections you want to handle. To understand why this is necessary, read the technical report or the excellent paper Measuring the Capacity of a Web Server (Banga and Druschel, Usenix 97). More on the fascinating topic of the accept() queue can be found in accept()able Strategies for Improving Web Server Performance (Brecht et al., Usenix 04) and in the libev manual. You should really read these references: this is one of the trickiest part of a web server behavior under heavy load, very easy to misinterpret (or to get wrong when you write a server). Using http_load is helpful when debugging this part because it gives the effective number of concurrent requests it has been able to perform, unlike Apache Bench which will happily pretend it managed to reach 1024 concurrent connections when the server is in fact limited to 128.
You also need to tune the client: the same advices apply. Do not forget to use a client faster than your server (or to use several client simultaneously) and to link them through a dedicated switch to ensure the bottleneck does not lie in the network.
TCP_TW_REUSE
This allows reusing of sockets which are in the TIME_WAIT state when it is safe from a protocol perspectiv.
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
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.
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
http://www.rootusers.com/web-server-performance-benchmark/
weighttp -n 100000 -c [0-1000 step:10] -t X -k "http://127.0.0.1:80/100.html"
http://adolgarev.blogspot.in/2013/12/performance-analysis-of-our-own-full.html
=============================================
ps -ylC httpd --sort:rss
Apache Max clients= Total Ram allocated to apache/ apache child process size
http://www.zarafa.com/wiki/index.php/Apache_tuning
ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
# ps -u apache -opid,ppid,nlwp
PID PPID NLWP
10622 10604 27
10654 10604 27
* How to get the total thread counts: #
ps -u apache -Lf | wc -l
55
or CentOS/RedHat and openSUSE/SLES will use httpd or httpd2
ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
===============================================
Lets take an example. I have a server below apache 2.4 and mpm event
[~]# free -g
total used free shared buffers cached
Mem: 31 15 15 0 0 12
-/+ buffers/cache: 3 28
Swap: 3 0 3
That is having 31 GB memory.
ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
Apache Memory Usage (MB): 233.23
Average Proccess Size (MB): 77.7435
There is enough memory and I can have number of child process upto
The average process size of 398
398 * 77 =30 GB
We need to allot memory to other process in the server also. So we can choose a child process limit of 200. This would be the server limit. Now we can tune apache on basis of mpm event . Say we need the server to handle connection of 25000 concurrent
We can go like below
ServerLimit 200
MaxRequestWorkers 25600
MaxConnectionsPerChild 0
KeepAlive On
KeepAliveTimeout 25
MaxKeepAliveRequests 10000
Keep alive reduces CPU overhead. Here I given start server of 50
MinSpareThreads 32
MaxSpareThreads 100
ThreadsPerChild 128
ThreadLimit 128
ListenBacklog 4096
=========================================
http://httpd.apache.org/docs/2.4/mod/event.html
http://httpd.apache.org/docs/current/mod/worker.html
http://www.genericarticles.com/mediawiki/index.php?title=How_to_optimize_apache_web_server_for_maximum_concurrent_connections_or_increase_max_clients_in_apache#mpm_worker_module
http://blog-en.openalfa.com/how-to-configure-apache-mpm-worker
Comments
Post a Comment