2008年04月 存档

用HPjmeter分析jvm的gc日志和heap dump

2008年04月13日,星期日

HPjmeter下载:
ftp://ftp.hp.com/pub/gsy/HPjmeter_3.0.01.jar

或者:
ftp://ftp.hp.com/pub/gsy/hpjmeter_console_3.0.01.00_windows_setup.exe
ftp://ftp.hp.com/pub/gsy/hpjmeter_console_3.0.01.00_linux_setup.sh

(ftp://ftp.hp.com/pub/gsy 支持目录方式浏览。)

jvm参数设置:
1. -Xloggc:gclog.vgc -XX:+PrintGCTimeStamps -XX:-PrintGCDetails -XX:+UseConcMarkSweepGC

3. -agentlib:hprof
(按Ctrl+C生成 .hprof.txt)

(我在 Openfire的 openfired.vmoptions里添加了如下的的参数:

-Xloggc:gc.log
-XX:+PrintGCTimeStamps
-XX:-PrintGCDetails
-XX:+UseConcMarkSweepGC
-agentlib:hprof

)

运行HPjmeter : java -Xmx384m -jar _3.0.01.jar

File–>Open file –>

选择gclog.vgc参看gc日志。

或者 java.hprof.txt.

其它相关下载:

HPjtune下载:
ftp://ftp.hp.com/pub/gsy/HPjtune-1.3.zip

SAP Memory Analyzer 1.1.1 的Eclipse插件下载:

http://dl2.csdn.net/down1/20071218/18144755624.zip

官方下载地址: MemoryAnalyzer-1.1.1-plugins-only.zip
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e025ff62-1148-2a10-9994-f9436c40fcb9

gcviewer下载:

http://www.tagtraum.com/download/gcviewer-1.28-bin.zip

来源:http://www.tagtraum.com/gcviewer-download.html

http://www.tagtraum.com/gcviewer.html

参考: http://www.javaperformancetuning.com/tools/hpjmeter/index.shtml

http://www.javaperformancetuning.com/

scimark2 benchmark下载:

http://math.nist.gov/scimark2/scimark2lib.jar

来源: http://math.nist.gov/scimark2/download_java.html

jvm可设置的选项参数: http://blogs.sun.com/watt/resource/jvm-options-list.html

http://java.sun.com/docs/performance/index.html

http://java.sun.com/performance/reference/whitepapers/5.0_performance.html

http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html

运行hpjmeter_console_3.0.01.00_windows_setup.exe安装的话,
可以得到两个demo.Java2Demo.eprof和Java2Demo.vgc。
HPjmeter自己生成的hpjmeter.bat 内容如下:
[code]
@echo off

rem Product: HPjmeter Console
rem
rem (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P.
rem
rem Confidential computer software. Valid license from HP required for
rem possession, use or copying. Consistent with FAR 12.211 and 12.212,
rem Commercial Computer Software, Computer Software Documentation, and
rem Technical Data for Commercial Items are licensed to the U.S. Government
rem under vendor's standard commercial license.

rem Parameters (can be processed in any order):
rem 1) hpjmeter.bat -log LEVEL [optional, defaults to OFF. Choices are: FINE, FINER, FINEST, ]
rem 2) hpjmeter.bat -X<switch> [optional]
rem 3) hpjmeter.bat tooloption [optional, currently not used]
rem 4) hpjmeter.bat -help [optional, prints usage message]
rem

setlocal

rem
rem Process commandline arguments if any
rem

set VMOPT=
set OPT=
set LOG_LEVEL=OFF
set HEAPSIZE=-Xmx256m

set ARG=%1
:getarg
if "%ARG%"=="" goto getarg_done
if "%ARG%"=="-log" goto set_log_level
if not "%ARG:-Xmx=""%"=="%ARG%" goto set_heapsize
if not "%ARG:-X=""%"=="%ARG%" goto set_vmopt
if not "%ARG:-D=""%"=="%ARG%" goto set_vmopt
if "%ARG%"=="-help" goto display_help
if not %ARG:-""%=="" goto set_opt
shift
set ARG=%1
goto getarg

:set_log_level
shift
set LOG_LEVEL=%1
shift
set ARG=%1
goto getarg

:set_heapsize
set HEAPSIZE=%ARG%
shift
set ARG=%1
goto getarg

:set_vmopt
set VMOPT=%VMOPT% %ARG%
shift
set ARG=%1
goto getarg

:set_opt
set OPT=%OPT% %ARG%
shift
set ARG=%1
goto getarg

:display_help
echo "Usage: hpjmeter [<options>]"
echo "where each option starting with -X is a Java option,"
echo "otherwise it is an HPjmeter option, or has the '-log <level>' form"
echo "<level> is SEVERE, WARNING, INFO, CONFIG, FINE, FINER, or FINEST"
echo "For example: hpjmeter -Xmx64m -log INFO -Xeprof"
goto end

:getarg_done

rem
rem Set JM_JAVA_HOME
rem

if defined JM_JAVA_HOME goto skipset
set JM_JAVA_HOME=D:\Program Files\Java\jre1.5.0_11
:skipset

rem
rem Absolute path to installed jar files set by InstallShield
rem

set JARBASE=D:\Program Files\HPjmeter\lib

rem
rem Set main class and classpath arguments
rem

set TOOL_NAME=com.hp.jmeter.Console
set JARS=%JARBASE%\HPjmeter.jar
set VMOPT=%VMOPT% -ea -Dcom.hp.jmeter.all.LogLevel=%LOG_LEVEL%

rem
rem Start HP Java Manager Console
rem

start "HPjmeter" /MIN "%JM_JAVA_HOME%\bin\java" %HEAPSIZE% %VMOPT% -cp "%JARS%" "%TOOL_NAME%" %OPT%

:end
endlocal

[/code]

Tags: , , ,

hessian 3.1.5的bug及相关例子

2008年04月12日,星期六

3.1.5的下载地址在:

http://hessian.caucho.com/download/hessian-3.1.5.jar

http://hessian.caucho.com/download/hessian-3.1.5-src.jar

http://hessian.caucho.com/download/hessian-test.jar

来源: http://hessian.caucho.com/#Java

假如客户端以Hessian2协议进行传输数据,以HessianMetaInfoAPI接口方式调用_hessian_getAttribute方法。
那么com.caucho.hessian.server.HessianSkeleton.java里, 在调用的 第  160行的地方,缺少一句  out.close();

其它几个return的地方,也缺少 out.close();

否则会遇到如下的错误信息

Caused by: com.caucho.hessian.io.HessianProtocolException: expected hessian reply at end of file
?
at com.caucho.hessian.io.Hessian2Input.error(Hessian2Input.:2701)
at com.caucho.hessian.io.Hessian2Input.startReply(Hessian2Input.java:405)
at com.lizongbo.hessian.client.HessianProxy.invoke(HessianProxy.java:65)

独立使用 HessianSkeleton进行处理的时候,

//HessianSkeleton hs=null;
//Hessian2Input h2i=null;

try {
h2i.readCall(); //这行代码非常重要,否则无法正确调用invoke。HessianServlet里有类似的调用
// 对应的是   int code = in.read();
//     int major = in.read();
//      int minor = in.read();

//如果不调用该行代码,则Hessian2Input无法解析出数据包
hs.invoke(h2i, h2o);
} catch (Exception e) {
e.printStackTrace();
}

HessianDebugOutputStream存在bug,如果在HessianServlet开启调试模式,则会抛出异常。

调用出错的接口方法是这样定义的:

public java.sql.Date getDay();
HessianDebugOutputStream的代码比较复杂,由于对hessian协议定义不够熟悉,没找到修正bug的方法。

下面是用mina封装后以TCP方式调用hessian的例子
————–

[code]
package com.lizongbo.hessian.server.handlers;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

import org.apache.mina.common.IoSession;

import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
import com.caucho.hessian.server.HessianSkeleton;
import com.lizongbo.hessian.HessianPacketHandler;
import com.lizongbo.hessian.message.HessianCall;
import com.lizongbo.hessian.message.HessianCallResp;
import com.lizongbo.hessian.message.HessianPacket;
import com.lizongbo.hessian.test.Mytest;
import com.lizongbo.hessian.test.Test;
import com.caucho.hessian.io.HessianDebugInputStream;
import java.io.PrintWriter;
import com.caucho.hessian.io.HessianDebugOutputStream;
import com.lizongbo.hessian.BadCommandIDException;

public class HessianCallhandler implements HessianPacketHandler {
private Map<String, HessianSkeleton> hsmap = new HashMap();

public void process(IoSession session, HessianPacket packet) throws
BadCommandIDException {
HessianCall msg = (HessianCall) packet;
if (hsmap.get(msg.getUrl()) == null) {
Test t = new Mytest();
HessianSkeleton hs = new HessianSkeleton(t, Test.class);
hsmap.put(msg.getUrl(), hs);
}

HessianSkeleton hs = hsmap.get(msg.getUrl());
InputStream bai = new ByteArrayInputStream(msg.getCallData());
PrintWriter dbg = new PrintWriter(System.out);
bai = new HessianDebugInputStream(bai, dbg); //增加调试输出,如果不需要调试,则屏蔽该行即可。
Hessian2Input h2i = new Hessian2Input(bai);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
////OutputStream bao2 = new HessianDebugOutputStream(bao, dbg); //增加调试输出,如果不需要调试,则屏蔽该行即可。
Hessian2Output h2o = new Hessian2Output(bao);
try {
h2i.readCall();
hs.invoke(h2i, h2o);
} catch (Exception e) {
e.printStackTrace();
}
HessianCallResp callRes = new HessianCallResp();
callRes.setResData(bao.toByteArray());
session.write(callRes);

}

}

[/code]

Tags: , , ,

Openfire 3.5.0 提供了支持QQtransport的gateway

2008年04月12日,星期六

http://618119.com/archives/2008/04/08/79.html

已经提到了 Openfire的相关链接。

http://www.igniterealtime.org/projects/openfire/plugins/gateway.jar

http://www.igniterealtime.org/projects/openfire/plugins.jsp

gateway的版本是 1.2.3,更新时间为: Apr 7, 2008

刚才经过测试是基本可用 的(只有基本的登录和文本聊天功能)。

不保证spark和openfire的QQtransport功能一定可用,有兴趣的可到openfire官方下载源码自行修改。

Tags: , , ,