{"id":1150,"date":"2012-08-27T17:05:54","date_gmt":"2012-08-27T09:05:54","guid":{"rendered":"http:\/\/rmohan.com\/?p=1150"},"modified":"2012-08-27T17:09:55","modified_gmt":"2012-08-27T09:09:55","slug":"tuning-apache-tomcat","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1150","title":{"rendered":"Tuning Apache + Tomcat"},"content":{"rendered":"<h1>ATG: Tuning Apache + Tomcat<\/h1>\n<p>I did some tuning on Apache which vastly decreased response times.<\/p>\n<p>The tests show increase vast decrease in response. (see table below) which is due to the following improvements made effective by the tuning (Increased maxclients, KeepAlive on. KeepAliveTimeout etc):<\/p>\n<p>1) Reusable connections to handle multiple requests from the same client, which in return causes less connections from client to the web-server and decreases response times.<\/p>\n<p>2) Because of Point 1, apache now needs less Httpd clients to server more load, hence decrease in resource usage (Memory).<\/p>\n<p>4) MaxClients has been increased to 1000, hence if required apache can now expand to serve more load without the queue buildup which causes high latencies.<\/p>\n<table cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\"><strong>Request<\/strong><\/td>\n<td valign=\"top\"><strong>100<\/strong><\/td>\n<td valign=\"top\"><strong>100 (Tuned)<\/strong><\/td>\n<td valign=\"top\"><strong>Perf gain (%)<\/strong><\/td>\n<td valign=\"top\"><strong>400<\/strong><\/td>\n<td valign=\"top\"><strong>400(Tuned)<\/strong><\/td>\n<td valign=\"top\"><strong>Perf gain (%)<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>1-homePage<\/strong><\/td>\n<td valign=\"top\">850.21<\/td>\n<td valign=\"top\">253.52<\/td>\n<td valign=\"top\">70.18<\/td>\n<td valign=\"top\">4812.72<\/td>\n<td valign=\"top\">533.55<\/td>\n<td valign=\"top\">88.91<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>2-login<\/strong><\/td>\n<td valign=\"top\">1132.27<\/td>\n<td valign=\"top\">593.72<\/td>\n<td valign=\"top\">47.56<\/td>\n<td valign=\"top\">5411.01<\/td>\n<td valign=\"top\">1186.64<\/td>\n<td valign=\"top\">78.07<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>3-1-search<\/strong><\/td>\n<td valign=\"top\">1698.79<\/td>\n<td valign=\"top\">1616.14<\/td>\n<td valign=\"top\">4.87<\/td>\n<td valign=\"top\">4303.77<\/td>\n<td valign=\"top\">4366.99<\/td>\n<td valign=\"top\">-1.47<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>3-2-searchPagination<\/strong><\/td>\n<td valign=\"top\">1822.23<\/td>\n<td valign=\"top\">1005.70<\/td>\n<td valign=\"top\">44.81<\/td>\n<td valign=\"top\">8810.29<\/td>\n<td valign=\"top\">3429.22<\/td>\n<td valign=\"top\">61.08<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>4-productDetails<\/strong><\/td>\n<td valign=\"top\">1043.62<\/td>\n<td valign=\"top\">398.56<\/td>\n<td valign=\"top\">61.81<\/td>\n<td valign=\"top\">5454.44<\/td>\n<td valign=\"top\">686.17<\/td>\n<td valign=\"top\">87.42<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>5-cartOverviewDeleteAllProducts<\/strong><\/td>\n<td valign=\"top\">328.95<\/td>\n<td valign=\"top\">320.88<\/td>\n<td valign=\"top\">2.45<\/td>\n<td valign=\"top\">712.25<\/td>\n<td valign=\"top\">514.25<\/td>\n<td valign=\"top\">27.80<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>5-cartOverviewViaMiniCart<\/strong><\/td>\n<td valign=\"top\">1026.01<\/td>\n<td valign=\"top\">421.22<\/td>\n<td valign=\"top\">58.95<\/td>\n<td valign=\"top\">5248.49<\/td>\n<td valign=\"top\">743.63<\/td>\n<td valign=\"top\">85.83<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>6-cartOverviewAddProduct<\/strong><\/td>\n<td valign=\"top\">351.52<\/td>\n<td valign=\"top\">336.90<\/td>\n<td valign=\"top\">4.16<\/td>\n<td valign=\"top\">873.58<\/td>\n<td valign=\"top\">824.36<\/td>\n<td valign=\"top\">5.63<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>7-cartPreview<\/strong><\/td>\n<td valign=\"top\">1352.69<\/td>\n<td valign=\"top\">665.76<\/td>\n<td valign=\"top\">50.78<\/td>\n<td valign=\"top\">6218.38<\/td>\n<td valign=\"top\">1162.07<\/td>\n<td valign=\"top\">81.31<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>8-cartConfirm<\/strong><\/td>\n<td valign=\"top\">908.65<\/td>\n<td valign=\"top\">848.04<\/td>\n<td valign=\"top\">6.67<\/td>\n<td valign=\"top\">1662.67<\/td>\n<td valign=\"top\">1251.99<\/td>\n<td valign=\"top\">24.70<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>9-logout<\/strong><\/td>\n<td valign=\"top\">840.03<\/td>\n<td valign=\"top\">214.11<\/td>\n<td valign=\"top\">74.51<\/td>\n<td valign=\"top\">5095.36<\/td>\n<td valign=\"top\">523.79<\/td>\n<td valign=\"top\">89.72<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The changes will require the following changes in the HTTP.cong (\/etc\/httpd\/conf\/httpd.conf)<\/p>\n<p>\u2014-<br \/> KeepAlive on<br \/> MaxKeepAliveRequests 100<br \/> KeepAliveTimeout 2<\/p>\n<p>&lt;IfModule prefork.c&gt;<br \/> StartServers 10<br \/> MinSpareServers 10<br \/> MaxSpareServers 20<br \/> ServerLimit 1000<br \/> MaxClients 1000<br \/> MaxRequestsPerChild 4000<br \/> &lt;\/IfModule&gt;<\/p>\n<p>&lt;IfModule worker.c&gt;<br \/> StartServers 10<br \/> MaxClients 1000<br \/> MinSpareThreads 25<br \/> MaxSpareThreads 75<br \/> ThreadsPerChild 25<br \/> MaxRequestsPerChild 1000<br \/> &lt;\/IfModule&gt;<br \/> \u2014<\/p>\n<p>Reference: http:\/\/blog.springsource.org\/2008\/10\/14\/optimising-and-tuning-apache-tomcat-part-2\/<\/p>\n<p>Note: the above improves performance but exausts mod_jk thread pools, as the response are shorter now, hence more load.<\/p>\n<p>Read the following on MPMs to fine tune it further:<\/p>\n<h3>Choosing an MPM<\/h3>\n<p>Apache 2.x supports pluggable concurrency models, called\u00a0<a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mpm.html\">Multi-Processing Modules<\/a> (MPMs). When building Apache, you must choose an MPM to use. There are platform-specific MPMs for some platforms:\u00a0<code><a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/beos.html\">beos<\/a><\/code>,\u00a0<code><a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/mpm_netware.html\">mpm_netware<\/a><\/code>,\u00a0<code><a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/mpmt_os2.html\">mpmt_os2<\/a><\/code>, and\u00a0<code><a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/mpm_winnt.html\">mpm_winnt<\/a><\/code>. For general Unix-type systems, there are several MPMs from which to choose. The choice of MPM can affect the speed and scalability of the httpd:<\/p>\n<ul>\n<li>The\u00a0<code><a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/worker.html\">worker<\/a><\/code> MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.<\/li>\n<li>The\u00a0<code><a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/prefork.html\">prefork<\/a><\/code> MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory. Prefork\u2019s threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.<\/li>\n<\/ul>\n<p>For more information on these and other MPMs, please see the MPM\u00a0<a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mpm.html\">documentation<\/a>.<\/p>\n<p>http:\/\/httpd.apache.org\/docs\/2.2\/misc\/perf-tuning.html<\/p>\n<p>http:\/\/tomcat.apache.org\/connectors-doc\/reference\/workers.html<\/p>\n<p>https:\/\/community.jboss.org\/wiki\/OptimalModjk12Configuration<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ATG: Tuning Apache + Tomcat <\/p>\n<p>I did some tuning on Apache which vastly decreased response times.<\/p>\n<p>The tests show increase vast decrease in response. (see table below) which is due to the following improvements made effective by the tuning (Increased maxclients, KeepAlive on. KeepAliveTimeout etc):<\/p>\n<p>1) Reusable connections to handle multiple requests from the same [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1150"}],"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=1150"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1150\/revisions"}],"predecessor-version":[{"id":1154,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1150\/revisions\/1154"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}