[Java]J2EE application performance optimization
http://www.javaworld.com/javaworld/jw-05-2004/jw-0517-optimization.html
http://www.javaworld.com/javaworld/jw-05-2004/jw-0517-optimization-p2.html
http://www.javaworld.com/javaworld/jw-05-2004/jw-0517-optimization-p3.html
読んだ読んだ。サーバのチューニングとかは大したことは書いてないけど、アプリケーションチューニングは、商用製品を使わないお手軽方法が書いてあった。
①以下のようなLogTimeStampクラスを作成する
import java.util.HashMap; //Import org.apache.log4j.Logger; public class LogTimeStamp { private static HashMap ht = new HashMap(); // Preferably we should use log4j instead of System.out // private static Logger logger = Logger.getLogger("LogTimeStamp"); private static class ThreadExecInfo { long timestamp; int stepno; } public static void LogMsg(String Msg) { LogMsg(Msg, false); } /* * Passing true in the second parameter of this function resets the counter for * the current thread. Otherwise it keeps track of the last invocation and prints * the current counter value and the time difference between the two invocations. */ public static void LogMsg(String Msg, boolean flag) { LogTimeStamp.ThreadExecInfo thr; long timestamp = System.currentTimeMillis(); synchronized (ht) { thr = (LogTimeStamp.ThreadExecInfo) ht.get(Thread.currentThread().getName()); if (thr == null) { thr = new LogTimeStamp.ThreadExecInfo(); ht.put(Thread.currentThread().getName(), thr); } } if (flag == true) { thr.stepno = 0; } if (thr.stepno != 0) { // logger.debug(Thread.currentThread().getName() + ":" + thr.stepno + ":" + // Msg + ":" + (timestamp - thr.timestamp)); System.out.println(Thread.currentThread().getName() + ":" + thr.stepno + ":" + Msg + ":" + (timestamp - thr.timestamp)); } thr.stepno = thr.stepno + 1; thr.timestamp = timestamp; } }
②以下のようにメソッドに埋め込む
public void startingMethod() { ... LogTimeStamp.LogMsg("This is a test message", true); //This is starting point ... LogTimeStamp.LogMsg("One more test message"); //This will become check point 1 method1(); ... }
③ログを取って、analyze.plでログを加工!!
おお。便利じゃ。