以下の条件でセッション数の増加によるメモリ使用量の推移を測定してみました。
- OS : WindowsXP
- CPU : Pentium4 1.6GHz
- Memory : 1.00GB
- APサーバ : jakarta-tomcat-4.1.29 on j2sdk1.4.2_02
- APサーバの起動オプション : -server -verbose:gc -Xmx512m -Xms128m
- クライアント : Javaアプリケーション
- その他 : 純粋にセッションを作成するだけで、セッションに対してオブジェクトの設定は行っていない。
/**
* クライアントアプリケーション
*/
package test;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class Test2 extends Thread {
public void run() {
try {
URL url = new URL("http://localhost:8080/test/createSession");
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
InputStream is = connection.getInputStream();
byte bytes = new byte[4096];
is.read(bytes);
//System.out.println(new String(bytes));
//System.out.println(connection.getHeaderFields());
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args) throws Exception {
System.gc();
for (int i = 0; i < 60000; i++) {
Thread thread = new Test2();
//thread.start();
thread.run();
}
System.out.println("done.");
}
}
/*
* セッションリスナ
*/
package test;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class CountHttpSessionListener implements HttpSessionListener {
int count = 0;
public CountHttpSessionListener() {
super();
public void sessionCreated(HttpSessionEvent arg0) {
count++;
System.out.println("#########################################");
System.out.println("created count = " + count + ":" + arg0);
Runtime runtime = Runtime.getRuntime();
System.out.println("total=" + runtime.totalMemory());
System.out.println("free=" + runtime.freeMemory());
System.out.println("max=" + runtime.maxMemory());
System.out.println("#########################################");
}
public void sessionDestroyed(HttpSessionEvent arg0) {
count--;
System.out.println("#########################################");
System.out.println("destroyed count = " + count + ":" + arg0);
Runtime runtime = Runtime.getRuntime();
System.out.println("total=" + runtime.totalMemory());
System.out.println("free=" + runtime.freeMemory());
System.out.println("max=" + runtime.maxMemory());
System.out.println("#########################################");
}
}