{"id":338,"date":"2012-06-19T11:26:27","date_gmt":"2012-06-19T03:26:27","guid":{"rendered":"http:\/\/rmohan.com\/?p=338"},"modified":"2012-06-19T11:27:10","modified_gmt":"2012-06-19T03:27:10","slug":"httpd-process-check","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=338","title":{"rendered":"HTTPD process check"},"content":{"rendered":"<p><strong>HTTPD process check<\/strong><\/p>\n<p>The apache\/httpd config file has a setting which determines how many running processes your apache \/httpd daemon will commit to the system. The idea is, that if your web server needs more processes to handle more connections it will spawn a new child and serve the request.<br \/>\nIf it is able it will kill the process off after and return it back into the pool.<\/p>\n<p>prefork MPM<br \/>\n# StartServers: number of server processes to start<br \/>\n# MinSpareServers: minimum number of server processes which are kept spare<br \/>\n# MaxSpareServers: maximum number of server processes which are kept spare<br \/>\n# ServerLimit: maximum value for MaxClients for the lifetime of the server<br \/>\n# MaxClients: maximum number of server processes allowed to start<br \/>\n# MaxRequestsPerChild: maximum number of requests a server process serves<br \/>\n<IfModule prefork.c><br \/>\nStartServers       8<br \/>\nMinSpareServers    5<br \/>\nMaxSpareServers   20<br \/>\nServerLimit      256<br \/>\nMaxClients       256<br \/>\nMaxRequestsPerChild  4000<br \/>\n<\/IfModule><\/p>\n<p>I can spawn 256 additional child processes in the event that the systems needs them.<br \/>\nAny more, and the system will slow down while attempting to deal with the existing requests.<br \/>\nIt is safe to assume that a normal web site serving hundreds of connections a minute (visitors) will consume approx 100 child processes. <\/p>\n<p>You can count the number of processes spawned by running this very simple command (I use httpd, not apache2)<\/p>\n<p>[root@localhost log]# pstree -G | grep httpd<br \/>\n     ??httpd???crlhelper<br \/>\n     ?       ??9*[httpd]<br \/>\n     ?       ??{httpd}<\/p>\n<p>  #!\/bin\/bash<br \/>\n        # Apache check process script<br \/>\n        HOSTNAME=`hostname`<br \/>\n        THRESHOLD=180<br \/>\n        ADDRTO=&#8221;admin@rmohan.com&#8221;<br \/>\n        SUBJECT=&#8221;${HOSTNAME} &#8211; Apache Process Check&#8221;<br \/>\n        LOCKFILE=&#8221;\/tmp\/apache_process_check.lock&#8221;<br \/>\n        LOGFILE=&#8221;\/var\/log\/apache_processes.log&#8221;<\/p>\n<p>        NUMHTTPD=`ps aux | grep http | grep -v &#8220;\\(root\\|grep\\)&#8221; | wc -l`<br \/>\n        echo &#8220;`date +&#8217;%Y-%m-%d %H:%M:%S %Z&#8217;` &#8211; ${NUMHTTPD}&#8221; >> ${LOGFILE}<\/p>\n<p>        if [[ ${NUMHTTPD} -gt ${THRESHOLD} ]]; then<br \/>\n          if [ ! -e &#8220;${LOCKFILE}&#8221; ]; then<br \/>\n            echo &#8220;The number of currently running httpd threads is ${NUMHTTPD}. Web services restarted&#8221; | mail -s &#8220;${SUBJECT} &#8211; Above Threshold&#8221; ${ADDRTO}<br \/>\n            touch ${LOCKFILE}<br \/>\n                service httpd stop &#038;&#038; sleep 5 &#038;&#038; service httpd start<br \/>\n         fi<br \/>\n        else<br \/>\n          if [ -e &#8220;${LOCKFILE}&#8221; ]; then<br \/>\n            rm -f &#8220;${LOCKFILE}&#8221;<br \/>\n          fi<br \/>\n        fi<\/p>\n<p>    SSH to your webserver you wish to run this script on<br \/>\n    In the directory you wish to run the script, create the file and copy\/paste the contents of the above script<br \/>\n    Make changes to the ADDRTO and THRESHOLD variables as needed to suit your setup<br \/>\n    Save the file then make it executable using chmod +x test.sh<br \/>\n    Insert the script into crontab using<\/p>\n<p>view source<\/p>\n<p>1\t*\/2 * * * * root \/path\/to\/test.sh<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTTPD process check<\/p>\n<p>The apache\/httpd config file has a setting which determines how many running processes your apache \/httpd daemon will commit to the system. The idea is, that if your web server needs more processes to handle more connections it will spawn a new child and serve the request. If it is able it [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/338"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=338"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":340,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions\/340"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}