{"id":415,"date":"2012-06-20T17:11:31","date_gmt":"2012-06-20T09:11:31","guid":{"rendered":"http:\/\/rmohan.com\/?p=415"},"modified":"2012-07-23T15:29:56","modified_gmt":"2012-07-23T07:29:56","slug":"script-for-load-test-apache","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=415","title":{"rendered":"Performance Benchmarks a Webserver Apache  concurrency"},"content":{"rendered":"<p><strong>Performance Benchmarks a Webserver<\/strong><\/p>\n<p>Apache Benchmark Procedures<\/p>\n<p>Tweak include the KeepAlive, KeepAliveTimeout, and MaxKeepAliveRequests settings. Recommended settings, which can all be set in the httpd.conf file, would be:<\/p>\n<p><strong> Code:<\/strong><br \/>\nServerLimit 128<br \/>\nMaxClients 128<br \/>\nKeepAlive On<br \/>\nKeepAliveTimeout 2<br \/>\nMaxKeepAliveRequests 100<\/p>\n<p>Testing a stock Apache configuration (MaxClients is 256, ServerLimit is 256, KeepAliveTimeout is 15) using ab configured to make 1000 requests with a concurrency of 100 consecutive requests would be as follows.<\/p>\n<p>&nbsp;<\/p>\n<p>$ ab -n 1000 -c 5 http:\/\/10.4.85.106\/index.html<br \/>\nWhere,<\/p>\n<p>-n 1000: ab will send 1000 number of requests to server 10.4.85.106 in order to perform for the benchmarking session<br \/>\n-c 5 : 5 is concurrency number i.e. ab will send 5 number of multiple requests to perform at a time to server 10.4.85.106<\/p>\n<p>For example if you want to send 10 request, type following command:<br \/>\n$ ab -n 10 -c 2 http:\/\/www.test.com\/<\/p>\n<p>Please note that 1000 request is a small number you need to send bigger (i.e. the hits you want to test) requests, for example following command will send 50000 requests :<br \/>\n$ ab -k -n 50000 -c 2 http:\/\/10.4.85.106\/index.html<\/p>\n<p>How do I carry out Web server Static KeepAlive test?<\/p>\n<p>Use -k option that enables the HTTP KeepAlive feature using ab test tool. For example:<br \/>\n$ ab -k -n 1000 -c 5 http:\/\/10.4.85.106\/index.html<\/p>\n<p>How do I save result as a Comma separated value?<\/p>\n<p>Use -e option that allows to write a comma separated value (CSV) file which contains for each percentage (from 1% to 100%) the time (in milliseconds) it took to serve that percentage of the requests:<br \/>\n$ ab -k -n 50000 -c 2 -e apache2r1.cvs http:\/\/10.4.85.106\/index.html<br \/>\nHow do I import result into excel or gnuplot programs so that I can create graphs?<\/p>\n<p>Use above command or -g option as follows:<br \/>\n$ ab -k -n 50000 -c 2 -g apache2r3.txt http:\/\/10.4.85.106\/index.html<\/p>\n<p><strong>Sample psql.php (php+mysql) file<\/strong><\/p>\n<p><!--?php <br ?--> $link = mysql_connect(&#8220;localhost&#8221;, &#8220;USERNAME&#8221;, &#8220;PASSWORD&#8221;);<br \/>\nmysql_select_db(&#8220;DATABASE&#8221;);<\/p>\n<p>$query = &#8220;SELECT * FROM TABLENAME&#8221;;<br \/>\n$result = mysql_query($query);<\/p>\n<p>while ($line = mysql_fetch_array($result))<br \/>\n{<br \/>\nforeach ($line as $value)<br \/>\n{<br \/>\nprint &#8220;$value\\n&#8221;;<br \/>\n}<br \/>\n}<\/p>\n<p>mysql_close($link);<br \/>\n?&gt;<br \/>\nRun ab command as follows:<br \/>\n$ ab -n 1000 -c 5 http:\/\/10.4.85.106\/psql.php<\/p>\n<p><strong>Script For Load test Apache <\/strong><\/p>\n<p>Here is my bash script that use wget command to bombard your web servers:<\/p>\n<p>#\/usr\/bin\/bash<br \/>\nfor((i=0;i&lt;=100;i++))<br \/>\ndo<br \/>\nwget http:\/\/192.168.1.7\/index.html<br \/>\ndone<br \/>\nrm -f index.html*<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"text-decoration: underline;\"><a href=\"http:\/\/nixcraft.com\/web-servers\/15313-apache-bench-max-concurrency.html\">apache bench max concurrency<\/a> <\/span><\/strong><br \/>\necho &#8220;10240&#8221; &gt; \/proc\/sys\/net\/core\/somaxconn<\/p>\n<p>or set (to make permanent)<\/p>\n<p>net.core.somaxconn = 10240 (or any number over what you are using as max connections)<\/p>\n<p>in<\/p>\n<p>\/etc\/sysctl.conf<\/p>\n<p>then run<\/p>\n<p>\/sbin\/sysctl -p \/etc\/sysctl.conf<\/p>\n<p>Also set your local ulimit to<\/p>\n<p>ulimit -n 65535<\/p>\n<p>just to have some overhead in case you want to increase the concurrent connections in ab. Let me know if that helps. If you want my thoughts on why I think this fixes things (assuming it helps you) let me know<\/p>\n<p>Also if you move to Worker MPM (you will have to redo php to be threadsafe if you use php) it might lower you CPU usage for a higher RAM usage depending on what your running off your server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Performance Benchmarks a Webserver<\/p>\n<p>Apache Benchmark Procedures<\/p>\n<p>Tweak include the KeepAlive, KeepAliveTimeout, and MaxKeepAliveRequests settings. Recommended settings, which can all be set in the httpd.conf file, would be:<\/p>\n<p> Code: ServerLimit 128 MaxClients 128 KeepAlive On KeepAliveTimeout 2 MaxKeepAliveRequests 100<\/p>\n<p>Testing a stock Apache configuration (MaxClients is 256, ServerLimit is 256, KeepAliveTimeout is 15) using [&#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\/415"}],"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=415"}],"version-history":[{"count":7,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/415\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/415\/revisions\/417"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}