Skip to main content

Apache tuning documentation

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

Comments

Popular posts from this blog

SystemD commands

[root@centos7 ~]# systemctl -t target UNIT                   LOAD   ACTIVE SUB    DESCRIPTION basic.target           loaded active active Basic System cryptsetup.target      loaded active active Encrypted Volumes getty.target           loaded active active Login Prompts graphical.target       loaded active active Graphical Interface local-fs-pre.target    loaded active active Local File Systems (Pre) local-fs.target        loaded active active Local File Systems multi-user.target      loaded active active Multi-User System network-online.target  loaded active active Network is Online network.target         loaded active active Network nfs-client.target      loaded active active NFS client services nss-user-lookup.target loaded active active User and Gr...

How to tweak linux server harddisk using hdparm

hdparm switches explained http://manpages.ubuntu.com/manpages/intrepid/man8/hdparm.8.html   First of all you have to install hdparm in linux. apt-get install hdparm #hdparm /dev/sda /dev/sda: readonly = 0 (off) readahead = 120 (on) geometry = 8850/255/63, sectors = 142182912, start = 0 Hard disk Performance Information # hdparm -tT /dev/hda /dev/hdd: Timing cached reads: 496 MB in 2.00 seconds = 247.42 MB/sec Timing buffered disk reads: 60 MB in 3.03 seconds = 19.81 MB/sec Hard drive set to low, slow settings # hdparm -cuda /dev/hda /dev/hda: IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 0 (off) readahead = 256 (on) Use below tweaks to increase disk read write performance. For sda drive ~]# hdparm -a 2048 /dev/sda /dev/sda: setting fs readahead to 2048 readahead = 2048 (on) For sdb drive [root@439298a ~]# hdparm -a 2048 /dev/sdb /dev/sdb: setting fs readahead to 2048 readahead = 2048 (on) ]# echo “anticipatory” >...

RAID

Check the Raid installed lspci | grep RAID     Software Raid ============== Linux Support For Software RAID Currently, Linux supports the following RAID levels (quoting from the man page): LINEAR RAID0 (striping) RAID1 (mirroring) RAID4 RAID5 RAID6 RAID10 MULTIPATH, and FAULTY. MULTIPATH is not a Software RAID mechanism, but does involve multiple devices: each device is a path to one common physical storage device. FAULTY is also not true RAID, and it only involves one device. It provides a layer over a true device that can be used to inject faults. Install mdadm Type the following command under RHEL / CentOS / Fedora Linux: # yum install mdadm Type the following command under Debian / Ubuntu Linux: # apt-get update && apt-get install mdadm How Do I Create RAID1 Using mdadm? Type the following command to create RAID1 using /dev/sdc1 and /dev/sdd1 (20GB size each). First run fdisk on /dev/sdc and /dev/sdd with " Softwa...