熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

struts2項目性能調優三步曲(一)

2022-06-13   來源: Java開源技術 

  前一段時間有反映說是一個使用了struts的生產系統的頁面顯示速度太慢登錄後發現確實如此於是進行了一番性能調優的研究和測試

  一根據struts官方的性能調優說明進行了一些參數的修改

  http://strutsapacheorg/x/docs/performancetuninghtml http://cwikiapacheorg/WW/performancetuninghtml

  Turn off logging and devMode(關閉logging和Devmode)

  這個當然沒問題但是全部關閉logging不現實我只是關閉了struts相關package的logging

  Do not use interceptors you do not need把strutsxml中不需要的interceptor統統刪除

  Use the correct HTTP headers (CacheControl & Expires)

  不確定應該如何修改

  Copy the static content from the Struts jar when using the Ajax theme (Dojo) or the Calendar tag關於這點後面會提到

  Create a freemarkerproperties file in your WEBINF/classes directory照做

  Create the freemarkerproperties file and add the following setting (or whatever value you deem fitting)template_update_delay=照做

  Enable Freemarker template caching As of Struts setting the property strutsfreemarkertemplatesCache to true will enable the Struts internal caching of Freemarker templates This property is set to false by default照做

  進行上述修改後發現頁面打開的速度並沒有明顯的提高

  二此時我已經基本鎖定網頁打開速度慢的原因與ajax(或者說是dojo)有關因為dojo的js庫大概有K左右先嘗試使用gzip壓縮javascript減小傳輸量看能否加快頁面的加載速度在Tomcat的serverxml的connector中添加如下配置激活gzip功能compression=on compressionMinSize= noCompressionUserAgents=gozilla traviata compressableMimeType=text/htmltext/xmltext/javascriptapplication/xjavascriptapplication/javascript進行上述修改後發現頁面打開的速度還是沒有明顯的提高

  三經過上述兩個實驗覺得應該是struts所封閉的dojo的性能問題了於是引入JQuery JQuery的js文件最小是K gzip後應該更小頁面的響應速度明顯改善(一個數量級以上的提高)主要原因在於與服務器交互的處理上極大地提升了效率而且頁面處理代碼更加簡潔明了

  最後我刪除了所有的<shead theme=ajax/>和 <shead/>(如果頁面中加入<shead />那麼在Struts生成的html中後包含dojojs)使用JQuery來完成所有的Ajax和javascript功能


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29170.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.