<div class="htmledit_views">html
<span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">每一個</span><a href="http://www.haogongju.net/tag/web" rel="nofollow" title="web" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">web</a><a href="http://www.haogongju.net/tag/%E5%AE%A2%E6%88%B7%E7%AB%AF" rel="nofollow" title="客戶端" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">客戶端</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">請求對於</span><a href="http://www.haogongju.net/tag/%E6%9C%8D%E5%8A%A1%E5%99%A8" rel="nofollow" title="服務器" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">服務器</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">端來講就一個單獨的線程,客戶端的請求數量增多將會致使線程數就上去了,CPU就忙着跟線程切換。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">而NIO則是使用單線程(單個CPU)或者只使用少許的</span><a href="http://www.haogongju.net/tag/%E5%A4%9A%E7%BA%BF%E7%A8%8B" rel="nofollow" title="多線程" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">多線程</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(多CPU)來接受Socket,而由線程池來處理堵塞在p</span><a href="http://www.haogongju.net/tag/IP" rel="nofollow" title="ip" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">ip</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">e或者隊列裏的請求.這樣的話,只要</span><a href="http://www.haogongju.net/tag/OS" rel="nofollow" title="OS" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">OS</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">能夠接受TCP的鏈接,web服務器就能夠處理該請求。大大提升了web服務器的可伸縮性。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">你們都據說了在</span><a href="http://www.haogongju.net/tag/apache" rel="nofollow" title="Apache" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">Apache</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> Tomcat6 中支持了</span><a href="http://www.haogongju.net/tag/Java" rel="nofollow" title="Java" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">Java</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">語言的特性 NIO( New I/O),無論你對NIO的技術是否熟悉,但你確定能想象的到NIO是一個好東西。的確,使用NIO在服務器端會有更好的</span><a href="http://www.haogongju.net/tag/%E6%80%A7%E8%83%BD" rel="nofollow" title="性能" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">性能</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">,增強服務器端對併發處理的 性能。 請注意:很抱歉,在tomcat6在默認的配置選項中是沒有把NIO功能打開。因此不少正在使用Tomcat6的朋友們本覺得能快活的使用上NIO。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">不信,你能夠試試,從Apache Tomcat 站點下載 的Tomct6 壓縮包中 conf/server.xml的 配置文件第69 行,內容以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> <Connector port="8080" protocol="HTTP/1.1" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> connectionTimeout="20000" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> redirectPort="8443" /> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">進行測試,能夠在控制檯的啓動信息裏看見,默認狀態下 沒有被打開nio配置,啓動時的信息,以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2010-2-1 12:59:40 org.apache.coyote.http11.Http11Protocol init </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">信息: Initializing Coyote HTTP/1.1 on http-8080 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2010-2-1 12:59:40 org.apache.catalina.startup.Catalina load </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">修改爲支持NIO的類型,配置以下 : </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol " </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> connectionTimeout="20000" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> redirectPort="8443" /> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">進行測試,被打開nio配置,啓動時的信息,以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2010-2-1 13:01:01 org.apache.tomcat.util.</span><a href="http://www.haogongju.net/tag/net" rel="nofollow" title="net" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">net</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">.NioSelectorPool getSharedSelector </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">信息: Using a shared selector for servlet write/read </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2010-2-1 13:01:01 org.apache.coyote.http11.Http11NioProtocol init </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">信息: Initializing Coyote HTTP/1.1 on http-8080 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">這樣才能讓你真正體驗到Tomcat6下NIO給你的</span><a href="http://www.haogongju.net/tag/%E7%B3%BB%E7%BB%9F" rel="nofollow" title="系統" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">系統</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">帶來的快感。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">tomcat6 1000併發量配置 tomcat6配置</span><a href="http://www.haogongju.net/tag/%E4%BC%98%E5%8C%96" rel="nofollow" title="優化" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">優化</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2009-11-23 20:21 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">maxThreads="500" minSpareThreads="400" /> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><Connector executor="tomcatThreadPool" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">port="80" protocol="HTTP/1.1" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">connectionTimeout="20000" enableLookups="false" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">redirectPort="8443" UR</span><a href="http://www.haogongju.net/tag/IE" rel="nofollow" title="IE" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">IE</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">ncoding="UTF-8" acceptCount="1000" /> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">修改tomcat/conf/server.xml配置文件爲以上。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">修改apache-tomcat-6.0.18/bin/catalina.bat配置文件爲如下。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">set JAVA_OPTS=-Xms1024m -Xmx1024m -XX:PermSize=128M -XX:MaxPermSize=256m </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">這一句加在 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">rem --------------------------------------------------------------------------- </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">rem Guess CATALINA_HOME if not defined </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">之間的位置,不要加到那些if裏面去了,不然不必定會生效. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">若是有疑問.能夠用 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">echo %JAVA_OPTS%>d:/JAVA_OPTS.log </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">來查看是否正確的設置了. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">同時告訴你們若是是安裝服務版的Tomcat,或者本身手動注入到</span><a href="http://www.haogongju.net/tag/window" rel="nofollow" title="window" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">window</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">的管理-->服務 裏去的話,那用這個方式是不行的,須要修改</span><a href="http://www.haogongju.net/tag/%E6%B3%A8%E5%86%8C" rel="nofollow" title="註冊" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">註冊</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">表,網上已經有不少內容說明了.你們本身去查吧. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">以上配置都是通過loadrun下的反覆壓力測試得來的。對通常的jsp頁面(相似於靜態頁面了)響應速度已是很是快了。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">可是對不一樣的業務邏輯一塊,仍是須要不一樣的處理方法才能達到最優。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">服務器配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Intel(R) Xeon(R) CPU 3065 @ 2.3</span><a href="http://www.haogongju.net/tag/3G" rel="nofollow" title="3G" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">3G</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Hz </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">3.99GB內存 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">3 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">在Tomcat和</span><a href="http://www.haogongju.net/tag/%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F" rel="nofollow" title="應用程序" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">應用程序</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">進行了壓力測試後,若是您對應用程序的性能結果不太滿意,就能夠採起一些性能調整措施了,固然了前提是應用程序沒有問題,咱們這 裏只講Tomcat的調整。因爲Tomcat的運行依賴於JVM,因此在這裏咱們把Tomcat的調整能夠分爲兩類來詳細描述: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 外部環境調整 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 調整非Tomcat組件,例如Tomcat運行的</span><a href="http://www.haogongju.net/tag/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F" rel="nofollow" title="操做系統" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">操做系統</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">和運行Tomcat的java虛擬機。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 自身調整 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 修改Tomcat自身的參數,調整Tomcat配置文件中的參數。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 下面咱們將詳細講解外部環境調整的有關內容,Tomcat自身調整的內容將在第2部分中闡述。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 1.JAVA虛擬機性能優化 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> Tomcat自己不能直接在</span><a href="http://www.haogongju.net/tag/%E8%AE%A1%E7%AE%97%E6%9C%BA" rel="nofollow" title="計算機" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">計算機</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">上運行,須要依賴於硬件基礎之上的操做系統和一個java虛擬機。您能夠選擇本身的須要選擇不一樣的操做系統 和對應的JDK的版本(只要是符合Sun發佈的Java規範的),但咱們推薦您使用Sun公司發佈的JDK。確保您所使用的版本是最新的,由於Sun公司 和其它一些公司一直在爲提升性能而對java虛擬機作一些升級改進。一些報告顯示JDK1.4在性能上比JDK1.3提升了將近10%到20%。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 能夠給Java虛擬機設置使用的內存,可是若是你的選擇不對的話,虛擬機不會補償。可經過命令行的方式改變虛擬機使用內存的大小。以下表所示有兩個參數用來設置虛擬機使用內存的大小。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">參數 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">描述 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">-Xms<size> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JVM初始化堆的大小 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">-Xmx<size> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JVM堆的最大值 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 這兩個值的大小通常根據須要進行設置。初始化堆的大小執行了虛擬機在啓動時向系統申請的內存的大小。通常而言,這個參數不重要。可是有的應用 程序在大負載的狀況下會急劇地佔用更多的內存,此時這個參數就是顯得很是重要,若是虛擬機啓動時設置使用的內存比較小而在這種狀況下有許多對象進行初始 化,虛擬機就必須重複地增長內存來知足使用。因爲這種緣由,咱們通常把-Xms和-Xmx設爲同樣大,而堆的最大值受限於系統使用的物理內存。通常使用數 據量較大的應用程序會使用持久對象,內存使用有可能迅速地增加。當應用程序須要的內存超出堆的最大值時虛擬機就會提示內存溢出,而且致使應用服務崩潰。因 此通常建議堆的最大值設置爲可用內存的最大值的80%。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> Tomcat默承認以使用的內存爲128MB,在較大型的應用</span><a href="http://www.haogongju.net/tag/%E9%A1%B9%E7%9B%AE" rel="nofollow" title="項目" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">項目</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">中,這點內存是不夠的,須要調大。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> Windows下,在文件{tomcat_home}/bin/catalina.bat,</span><a href="http://www.haogongju.net/tag/Unix" rel="nofollow" title="Unix" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">Unix</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">下,在文件{tomcat_home}/bin/catalina.sh的前面,增長以下設置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> JAVA_OPTS='-Xms【初始化內存大小】 -Xmx【可使用的最大內存】' </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 須要把這個兩個參數值調大。例如: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> JAVA_OPTS='-Xms256m -Xmx512m' </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 表示初始化內存爲256MB,可使用的最大內存爲512MB。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 另外須要考慮的是Java提供的垃圾回收機制。虛擬機的堆大小決定了虛擬機花費在收集垃圾上的時間和頻度。收集垃圾能夠接受的速度與應用有 關,應該經過分析實際的垃圾收集的時間和頻率來調整。若是堆的大小很大,那麼徹底垃圾收集就會很慢,可是頻度會下降。若是你把堆的大小和內存的須要一致, 徹底收集就很快,可是會更加頻繁。調整堆大小的的目的是最小化垃圾收集的時間,以在特定的時間內最大化處理客戶的請求。在基準測試的時候,爲保證最好的性 能,要把堆的大小設大,保證垃圾收集不在整個基準測試的過程當中出現。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 若是系統花費不少的時間收集垃圾,請減少堆大小。一次徹底的垃圾收集應該不超過 3-5 秒。若是垃圾收集成爲瓶頸,那麼須要指定代的大小,檢查垃圾收集的詳細輸出,研究 垃圾收集參數對性能的影響。通常說來,你應該使用物理內存的 80% 做爲堆大小。當增長處理器時,記得增長內存,由於分配能夠並行進行,而垃圾收集不是並行的。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 2.操做系統性能優化 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 這裏說的操做系統是指運行web服務器的系統軟件,固然,不一樣的操做系統是爲不一樣的目的而設計的。好比OpenBSD是面向安全的,所以在它 的</span><a href="http://www.haogongju.net/tag/%E5%86%85%E6%A0%B8" rel="nofollow" title="內核" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">內核</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">中有許多的限制來防止不一樣形式的服務攻擊(OpenBSD的一句座右銘是「默認是最安全的」)。這些限制或許更多地用來運行活躍的web服務器。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 而咱們經常使用的Linux操做系統的目標是易用使用,所以它有着更高的限制。使用BSD內核的系統都帶有一個名爲「Generic」的內核,表 明全部的驅動器都靜態地與之相連。這樣就使系統易於使用,可是若是你要建立一個自定義的內核來增強其中某些限制,那就須要排除不須要的設備。Linux內 核中的許多驅動都是動態地加載的。可是換而言之,內存如今變得愈來愈便宜,因此由於加載額外的設備驅動就顯得不是很重要的。重要的是要有更多的內存,而且 在服務器上騰出更多的可用內存。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 小提示:雖然如今內存已經至關的便宜,但仍是儘可能不要購買便宜的內存。那些有牌子的內存雖然是貴一點,可是從可靠性上來講,性價比會更高一些。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 若是是在Windows操做系統上使用Tomcat,那麼最好選擇服務器版本。由於在非服務器版本上,最終</span><a href="http://www.haogongju.net/tag/%E7%94%A8%E6%88%B7" rel="nofollow" title="用戶" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">用戶</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">受權數或者操做系統自己所能承受的用戶數、可用的網絡鏈接數或其它方面的一些方面都是有限制的。而且基於安全性的考慮,必須常常給操做系統打上最新的補丁。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 3.Tomcat與其它web服務器整合使用 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 雖然tomcat也能夠做web服務器,但其處理靜態</span><a href="http://www.haogongju.net/tag/html" rel="nofollow" title="html" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">html</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">的速度比不上apache,且其做爲web服務器的功能遠不如apache,因 此咱們想把apache和tomcat集成起來,將html與jsp的功能部分進行明確分工,讓tomcat只處理jsp部分,其它的由apache, </span><a href="http://www.haogongju.net/tag/IIS" rel="nofollow" title="IIS" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">IIS</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">等這些web服務器處理,由此大大節省了tomcat有限的工做「線程」。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 4.負載均衡 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 在負載均衡的思路下,多臺服務器爲對稱方式,每臺服務器都具備同等的地位,能夠單獨對外提供服務而無須其餘服務器的輔助。經過負載分擔技術,將外部發送來的請求按必定規則分配到對稱結構中的某一臺服務器上,而接收到請求的服務器都獨立迴應客戶機的請求。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 提供服務的一組服務器組成了一個應用服務器集羣(cluster),並對外提供一個統一的地址。當一個服務請求被髮至該集羣時,根據必定規則選擇一臺服務器,並將服務轉定向給該服務器承擔,即將負載進行均衡分攤。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 經過應用負載均衡技術,使應用服務超過了一臺服務器只能爲有限用戶提供服務的限制,能夠利用多臺服務器同時爲大量用戶提供服務。當某臺服務器 出現故障時,負載均衡服務器會自動進行檢測並中止將服務請求分發至該服務器,而由其餘工做正常的服務器繼續提供服務,從而保證了服務的可靠性。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 負載均衡實現的方式大概有四種:第一是經過DNS,但只能實現簡單的輪流分配,不能處理故障,第二若是是基於MS IIS, Windows 2003 server自己就帶了負載均衡服務,第三是硬件方式,經過交換機的功能或專門的負載均衡設備能夠實現,第四種是軟件方式,經過一臺負載均衡服務器進行, 上面安裝軟件。使用Apache Httpd Server作負載平衡器,Tomcat集羣節點使用Tomcat就能夠作到以上第四種方式。這種方式比較靈活,成本相對也較低。另一個很大的優勢就是 能夠根據應用的狀況和服務器的狀況採起一些策略。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">你們都知道,JAVA程序啓動時都會JVM都會分配一個初始內存和最大內存給這個應用程序。這個初始內存和最大內存在必定程度都會影響程序的性能。好比說在應用程序用到最大內存的時候,JVM是要先去作垃圾回收的動做,釋放被佔用的一些內存。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 因此想調整Tomcat的啓動時初始內存和最大內存就須要向JVM聲明,通常的JAVA程序在運行均可以經過中-Xms -Xmx來調整應用程序的初始內存和最大內存: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 如:java -Xms64m -Xmx128m a.jar. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">tomcat的啓動程序是包裝過的,不能直接使用java -X..... tomcat.來改變內存的設置。在Tomcat在改變這個設置 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">有兩種方法: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">1. 就須要在環境變量中加上TOMCAT_OPTS, CATALINA_OPTS兩個屬性, </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 如 SET CATALINA_OPTS= -Xms64m -Xmx512m; </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> ms是最小的,mx是最大,64m, 512m分別是指內存的容量. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2. 修改Catalina.bat文件 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 在166行「rem Execute Java with the applicable properties 」如下每行 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DE</span><a href="http://www.haogongju.net/tag/BUG" rel="nofollow" title="BUG" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">BUG</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">_OPTS% -Djava.endorsed.dirs ="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE %" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% 中的%CATALINA_OPTS% 替換成-Xms64m - Xmx512m </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat性能優化 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">1.停用DNS查詢 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">server.xml裏 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><Connector </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">port="8887" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">enableLookups="false" redirectPort="8443" acceptCount="100" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">debug="0" connectionTimeout="20000" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">disableUploadTimeout="true" /> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">加上enableLookups="false";這樣就不使用DNS查詢,也不會有延遲了 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">除非須要全部鏈接到服務器的HTTP客戶端的完整</span><a href="http://www.haogongju.net/tag/%E4%B8%BB%E6%9C%BA" rel="nofollow" title="主機" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">主機</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">名稱 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">注:Connector的enableLookups性屬的意義是:調用request.getRemoteHost()是否會經過DNS查詢來取得遠處客戶端的真正主機名稱。true表示會查詢,false表示以字符串格式傳回客戶端的IP地址。默認值是:true </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2,調整線程的數目 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat使用線程池以便對傳入的請求提供快速的響應。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">經過更改Connector的minProcessors與maxProcessors的值,能夠控制所分配的線程數目 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">將這兩個參數設爲最佳值的最好方式是對各個參數嘗試許多不一樣的設定值,而後以仿真的網絡</span><a href="http://www.haogongju.net/tag/%E6%B5%81%E9%87%8F" rel="nofollow" title="流量" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">流量</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">進行測試,同時並觀察響應時間與內存的使用量。每一種 機器、操做系統與JVM的組合均可能有不一樣的表現,並且並不是全部人的</span><a href="http://www.haogongju.net/tag/%E7%BD%91%E7%AB%99%E6%B5%81%E9%87%8F" rel="nofollow" title="網站流量" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">網站流量</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">都會相同,因此沒有現成的規則來決定最小與最大的線程數 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">3.加快jsp的編譯速度,預先編譯jsp </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">4.容量規劃:經驗式的容量規劃,企業容量規劃 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">經驗式的容量規劃與企業容量規劃最大的差別就是深度。經驗式容量規劃使用經驗法則,所以比較像是經驗預測,而企業容量規劃則是深度地研究需求與性能,其目標是儘量產生最精確的數字 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">apache+tomcat+</span><a href="http://www.haogongju.net/tag/MySQL" rel="nofollow" title="mysql" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">mysql</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> Apache+Tomcat+My</span><a href="http://www.haogongju.net/tag/SQL" rel="nofollow" title="sql" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">sql</a><a href="http://www.haogongju.net/tag/%E7%BD%91%E7%AB%99" rel="nofollow" title="網站" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">網站</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">配置 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">前言: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">公司開發了一個網站,估計最高在線人數是3萬,併發人數最多100人。開發的網站是否可否承受這個壓力,如何確保網站的負荷沒有問題,通過研究決定以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(1) 採用負載平衡和集羣技術,初步機構採用Apache+Tomcat的機羣技術。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(2) 採用壓力測試工具,測試壓力。工具是Loadrunner。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">硬件環境搭建: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">爲了可以進行壓力測試,須要搭建一個環境。剛開始時,測試在公司局域網內進行,但很快發現了一個問題,即一個腳本的壓力測試結果每次都不同,而且差異很大。原來是受公司網絡的影響,因而決定搭建一個徹底隔離的局域網測試。搭建後的局域網配置以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(1) 網絡速度:100M </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(2) 三臺服務器: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">負載服務器 :操做系統</span><a href="http://www.haogongju.net/tag/Windows2003" rel="nofollow" title="windows2003" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">windows2003</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">, </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat服務器:操做系統windows2000 Professional </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><a href="http://www.haogongju.net/tag/%E6%95%B0%E6%8D%AE%E5%BA%93" rel="nofollow" title="數據庫" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">數據庫</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">服務器:操做系統windows2000 Professional </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">三臺機器的cpu 2.4 G, 內存 1G。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">軟件環境搭建: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">軟件的版本以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Apache 版本:2.054, </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat5.0.30, </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">mysql :4.1.14. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JDK1.5 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">壓力測試工具:Loadrunner7.8。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">負載平衡方案以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">一臺機器(操做系統2003)安裝apache,做爲負載服務器,並安裝tomcat做爲一個worker;一個單獨安裝tomcat,做爲第二個worker;剩下的一臺單獨做爲</span><a href="http://www.haogongju.net/tag/%E6%95%B0%E6%8D%AE" rel="nofollow" title="數據" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">數據</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">庫服務器。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> Apache和tomcat的負載平衡採用JK1.2.14(沒有采用2.0,主要是2.0再也不維護了)。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">集羣方案: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 採用Tomcat自己的集羣方案。在server.xml配置。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">壓力測試問題: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">壓力測試後,發現了一些問題,現一一列出來: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(1)採用Tocmat集羣后,速度變得很慢。由於集羣后,要進行session複製,致使速度較慢。Tomcatd的複製,目前不支持 application 複製。複製的做用,主要用來容錯的,即一臺機器有故障後,apache能夠把請求自動轉發到另一個機器。在容錯和速度的考慮上,咱們最終選擇速度,去掉 了Tomcat集羣。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(2) 操做系統最大併發用戶的限制: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">爲了採用網站的壓力,咱們開始的時候,僅測試Tomcat的最大負載數。 Tomcat服務器安裝的操做系統是windows2000 Professional。當咱們用壓力測試工具,併發測試時,發現只要超過15個併發用戶,會常常出現沒法鏈接服務器的狀況。通過研究,發現是操做系統 的問題:windows2000 Professional 支持的併發訪問用戶有限,默認的好像是15個。因而咱們把操做系統所有采用windows2003 server版本。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(3) 數據庫鏈接池的問題: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">測試數據庫鏈接性能時,發現數據庫鏈接速度很慢。每增長一些用戶,鏈接性能就差了不少。咱們採用的數據庫鏈接池是DBCP,默認的初始化爲50 個,應該不會很慢吧。查詢數據庫的鏈接數,發現初始化,只初始化一個鏈接。併發增長一個用戶時,程序就會從新建立一個鏈接,致使鏈接很慢。緣由就在這裏 了。如何解決呢?偶爾在 JDK1.4下的Tomcat5.0.30下執行數據庫鏈接壓力測試,發現速度很快,程序建立數據庫鏈接的速度也是很快的。看來JDK1.5的JDBC驅 動程序有問題。因而咱們修改 JDK的版本爲1.4. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(4) C3P0和DBCP </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">C3P0是Hibernate3.0默認的自帶數據庫鏈接池,DBCP是Apache開發的數據庫鏈接池。咱們對這兩種鏈接池進行壓力測試對比,發如今併發300個用戶如下時,DBCP比C3P0平均時間快1秒左右。但在併發400個用戶時,二者差很少。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">速度上雖然DBCP比C3P0快些,可是有BUG:當DBCP創建的數據庫鏈接,由於某種緣由斷掉後,DBCP將不會再從新建立新的鏈接,致使必須從新啓動Tomcat才能解決問題。DBCP的BUG使咱們決定採用C3P0做爲數據庫鏈接池。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">調整後的方案: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">操做系統Windows2003 server版本 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JDK1.4 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat 5.0.30 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">數據庫鏈接池C3P0 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">僅採用負載平衡,不採用集羣。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">軟件的配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Apache配置:主要配置httpd.conf和新增長的文件workers.properties </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Httpd.conf: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#一個鏈接的最大請求數量 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">MaxKeepAliveRequests 10000 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#NT環境,只能配置這個參數來提供性能 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><IfModule mpm_winnt.c> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#每一個進程的線程數,最大1920。NT只啓動父子兩個進程,不能設置啓動多個進程 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">ThreadsPerChild 1900 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">每一個子進程可以處理的最大請求數 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">MaxRequestsPerChild 10000 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"></IfModule> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># 加載mod_jk </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">LoadModule jk_module modules/mod_jk.so </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># 配置mod_jk </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkWorkersFile conf/workers.properties </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkLogFile logs/mod_jk.log </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkLogLevel info </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#請求分發,對jsp文件,.do等動態請求交由tomcat處理 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">DocumentRoot "C:/Apache/htdocs" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkMount /.jsp loadbalancer </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkMount /.do loadbalancer </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkMount /servlet/ loadbalancer </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#關掉主機Lookup,若是爲on,很影響性能,能夠有10多秒鐘的延遲。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">HostnameLookups Off </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#緩存配置 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">LoadModule cache_module modules/mod_cache.so </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">LoadModule disk_cache_module modules/mod_disk_cache.so </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">LoadModule mem_cache_module modules/mod_mem_cache.so </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><IfModule mod_cache.c> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> CacheForce</span><a href="http://www.haogongju.net/tag/com" rel="nofollow" title="Com" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">Com</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">pletion 100 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> CacheDefaultExpire 3600 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> CacheMaxExpire 86400 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> CacheLastModifiedFactor 0.1 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> <IfModule mod_disk_cache.c> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">CacheEnable disk / </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">CacheRoot c:/cacheroot </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">CacheSize 327680 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">CacheDirLength 4 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">CacheDirLevels 5 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">CacheGcInterval 4 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> </IfModule> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> <IfModule mod_mem_cache.c> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">CacheEnable mem / </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">MCacheSize 8192 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">MCacheMaxObjectCount 10000 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">MCacheMinObjectSize 1 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">MCacheMaxObjectSize 51200 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> </IfModule> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"></IfModule> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker. Properties文件 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># workers.properties ,能夠參考 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">::</span><a href="http://www.haogongju.net/tag/URL" rel="nofollow" title="URL" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">URL</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">::http://jakarta.apache.org/tomcat/connectors-doc/config/workers.html </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># In Unix, we use forward slashes: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">ps=/ </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># list the workers by name </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.list=tomcat1, tomcat2, loadbalancer </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ------------------------ </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># First tomcat server </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ------------------------ </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.port=8009 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.host=localhost </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.type=ajp13 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Specify the size of the open connection cache. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#worker.tomcat1.cachesize </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Specifies the load balance factor when used with </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># a load balancing worker. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Note: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ----> lbfactor must be > 0 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ----> Low lbfactor means less work done by the worker. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.lbfactor=900 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ------------------------ </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Second tomcat server </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ------------------------ </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.port=8009 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.host=202.88.8.101 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.type=ajp13 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Specify the size of the open connection cache. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">#worker.tomcat1.cachesize </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Specifies the load balance factor when used with </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># a load balancing worker. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Note: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ----> lbfactor must be > 0 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ----> Low lbfactor means less work done by the worker. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.tomcat1.lbfactor=2000 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ------------------------ </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Load Balancer worker </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ------------------------ </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># The loadbalancer (type lb) worker performs weighted round-robin </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># load balancing with sticky sessions. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># Note: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># ----> If a worker dies, the load balancer will check its state </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># once in a while. Until then all work is redirected to peer </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># worker. </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.loadbalancer.type=lb </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">worker.loadbalancer.balanced_workers=tomcat1,tomcat2 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># END workers.properties </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"># </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat1配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><!--配置server.xml </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">去掉8080端口,即註釋掉以下代碼:--> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><Connector </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> enableLookups="false" redirectPort="8443" acceptCount="100" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> debug="0" connectionTimeout="20000" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> disableUploadTimeout="true" /> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><!--配置8009端口以下:--> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><Connector port="8009" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">maxThreads="500" minSpareThreads="400" maxSpareThreads="450" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> enableLookups="false" redirectPort="8443" debug="0" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> protocol="AJP/1.3" /> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><!--配置引擎--> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><Engine name="Catalina" defaultHost="localhost" debug="0" jvmRoute="tomcat1"> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">啓動內存配置,開發configure tomcat程序便可配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Initial memory pool: 200 M </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Maxinum memory pool:300M </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat2配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">配置和tomcat1差很少,須要改動的地方以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><!--配置引擎--> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><Engine name="Catalina" defaultHost="localhost" debug="0" jvmRoute="tomcat2"> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">啓動內存配置,開發configure tomcat程序便可配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Initial memory pool: 512 M </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Maxinum memory pool:768M </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Mysql配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Server類型:Dedicated MySQL Server Machine </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Database usage:Transational Database Only </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">併發鏈接數量:Online Transaction Processing(OLTP) </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">字符集:UTF8 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">數據庫鏈接池的配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">咱們採用的是spring 框架,配置以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><property name="hibernateProperties"> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><props> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.connection.url">jdbc:mysql://202.88.1.103/db</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.connection.username">sa</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.connection.password"></prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.show_sql">false</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.use_sql_comments">false</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.cglib.use_reflection_optimizer">true</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.max_fetch_depth">2</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.c3p0.max_size">200</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.c3p0.min_size">5</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.c3p0.timeout">12000</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.c3p0.max_statements">50</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><prop key="hibernate.c3p0.acquire_increment">1</prop> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"></props> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"></property> </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">其餘的沒有額外配置。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">LoadRunner 常見問題: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(1)sofeware caused connction:這種狀況,通常是腳本有問題,或者loadrunner有問題。解決方法:從新啓動機器,或者從新錄製腳本,估計是loadrunner的bug。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(2)cannot connect to server:沒法鏈接到服務器。這種狀況是服務器的配置有問題,服務器沒法承受過多的併發鏈接了。須要優化服務器的配置, </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">如操做系統採用windows 2003 server, </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">優化tomcat配置:maxThreads="500" minSpareThreads="400" maxSpareThreads="450"。可是tomcat 最多支持500個併發訪問 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">優化apache配置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">ThreadsPerChild 1900 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">MaxRequestsPerChild 10000 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">其餘的錯誤如: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Action.c(10): Error -27791: Server has shut down the connection prematurely </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">HTTP Status-Code=503 (Service Temporarily Unavailable) </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">通常都是因爲服務器配置不夠好引發的,按照問題(2)處理,若是仍舊不行,須要優化硬件和調整程序了。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Apache問題: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(1) File does not exist: C:/Apache/htdocs/fav</span><a href="http://www.haogongju.net/tag/icon" rel="nofollow" title="icon" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">icon</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">.ico: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">這個問題是apache,htdocs目錄沒有favicon.ico文件引發的,該文件是網站的圖標,僅在firefox,myIE等</span><a href="http://www.haogongju.net/tag/%E6%B5%8F%E8%A7%88%E5%99%A8" rel="nofollow" title="瀏覽器" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">瀏覽器</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">出現。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(2) 圖片沒法顯示: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">配置apache後,卻沒法顯示圖片。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">解決方法:把程序的圖片,按照程序結構copy到apache的htdocs目錄下。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">(3) 沒法處理請求: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">當咱們輸入 *.do 命令後,apache確返回錯誤信息,而鏈接tomcat卻沒有問題。緣由是沒有把.do命令轉發給tomcat處理。解決方法以下: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">在apache配置文件中配置以下內容: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">DocumentRoot "C:/Apache/htdocs" </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkMount /.jsp loadbalancer </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">JkMount /.do loadbalancer </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">總結: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">網站的壓力測試,涉及的知識面挺廣的,不只要熟悉壓力測試工具,還要知道如何配置和優化應用服務器和數據庫,而且須要知道如何優化網絡、操做系統、硬件系統。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">測試中不只要善於發現問題,要知道如何解決。最重要的一點,要有良好的測試方法。剛開始測試時,能夠從最簡單的測試腳本入手,不須要太複雜的腳 本,這樣便於發現問題。如咱們剛開始時,就從一個簡單的下載登錄</span><a href="http://www.haogongju.net/tag/%E7%95%8C%E9%9D%A2" rel="nofollow" title="界面" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">界面</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">的腳本入手,測試一個tomcat的壓力負載。一個簡單的獲取登錄的腳本,幫助咱們優 化了 tomcat的配置;後來再測試數據庫鏈接,也是一個簡單的數據庫鏈接腳本,幫助咱們優化了數據庫鏈接池;而後利用這些簡單的腳本,測試apache的負 載平衡,優化了apache配置。最後運行復雜的腳本,模擬多種角色的用戶在不一樣時間下的處理,以測試網站壓力負載。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">4 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">1.Tomcat默承認以使用的java內存爲128MB,在較大型的應用項目中,這點內存是不夠的,須要調大。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Windows下,在文件{tomcat_home}/bin/catalina.bat,Unix下,在文件{tomcat_home}/bin/catalina.sh的前面,增長以下設置: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> JAVA_OPTS='-Xms【初始化內存大小】 -Xmx【可使用的最大內存】' </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 須要把這個兩個參數值調大。例如: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> JAVA_OPTS='-Xms256m -Xmx512m' </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 表示初始化內存爲256MB,可使用的最大內存爲512MB。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">2. 操做系統 性能優化 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">默認windows下打開文件數是2000;在linux下是1024; </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">vi /etc/profile 加入ulimit -n 4096就把linux改爲打開文件最大數爲4096 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">3. 禁用DNS查詢 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"> 當web應用程序向要記錄客戶端的信息時,它也會記錄客戶端的IP地址或者經過</span><a href="http://www.haogongju.net/tag/%E5%9F%9F%E5%90%8D" rel="nofollow" title="域名" style="color:rgb(51,51,51);text-decoration:none;font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;" target="_blank">域名</a><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">服務器查找機器名轉換爲IP地址。DNS查詢須要佔用網絡,而且包 括可能從不少很遠的服務器或者不起做用的服務器上去獲取對應的IP的過程,這樣會消耗必定的時間。爲了消除DNS查詢對性能的影響咱們能夠關閉DNS查 詢,方式是修改server.xml文件中的enableLookups參數值: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">4. 在Tomcat5對這些參數進行了調整,請看下錶: </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">屬性名 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">描述 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">maxThreads </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat使用線程來處理接收的每一個請求。這個值表示Tomcat可建立的最大的線程數。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">acceptCount </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">指定當全部可使用的處理請求的線程數都被使用時,能夠放處處理隊列中的請求數,超過這個數的請求將不予處理。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">connnectionTimeout </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">網絡鏈接超時,單位:毫秒。設置爲0表示永不超時,這樣設置有隱患的。一般可設置爲30000毫秒。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">minSpareThreads </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">Tomcat初始化時建立的線程數。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">maxSpareThreads </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">一旦建立的線程超過這個值,Tomcat就會關閉再也不須要的socket線程。 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">5.在web下不顯示目錄列表 </span><br style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;"><span style="color:rgb(51,51,51);font-family:Arial, '宋體', sans-serif;font-size:16px;line-height:30px;">在web.xml中把listings改爲false就好了 </span> </div>java