2013년 2월 27일 수요일

[펌] JMX를 이용한 Tomcat 6/7 Monitoring(JDBC)포함

원문 : http://www.javapattern.info/454

Tomcat JMX 접속 모니터링 설정 및 확인 방법

1. Tomcat 설치 - 7.0.X

2. tomcat user/role setting
[jboss@ip-10-31-156-81 bin]$ vi ../conf/tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="admin-gui" />
  <role rolename="manager" />
  <role rolename="manager-gui" />
  <role rolename="manager-script" />
  <role rolename="manager-jmx" />
  <role rolename="manager-status" />
  <user username="tomcat" password="s3cret" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status" />
</tomcat-users>

------------------------------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<tomcat-user>
   <role rolename="admin-gui" />
   <role rolename="manager" />
   <role rolename="manager-gui" />
   <role rolename="manager-script" />
   <role rolename="manager-jmx" />
   <role rolename="manager-status" />
   <user username="tomcat" password="" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status" />
1
2
3
4
5
6
7
8
9
10
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="admin-gui" />
  <role rolename="manager" />
  <role rolename="manager-gui" />
  <role rolename="manager-script" />
  <role rolename="manager-jmx" />
  <role rolename="manager-status" />
  <user username="tomcat" password="s3cret" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status" />
</tomcat-users>
------------------------------------------------------------

3. Web Browser를 위한 URL String Query
http://host-ip:port/manager/jmxproxy/?qry=*:*
------------------------------------------------------------
O<SPAN style="LINE-HEIGHT: normal; WHITE-SPACE: pre-wrap">K - Number of results: 106</SPAN><DIV><PRE style="LINE-HEIGHT: normal; WORD-WRAP: break-word; WHITE-SPACE: pre-wrap">Name: Catalina:type=ThreadPool,name="ajp-apr-8009"modelerType: org.apache.tomcat.util.modeler.BaseModelMBean
useSendfile: false
minSpareThreads: 10
 acceptorThreadPriority: 5
maxThreads: 200
sSLEnabled: false
sSLVerifyDepth: 10
 pollerThreadCount: 1
localPort: 8009
 connectionCount: 1
 currentThreadCount: 0
keepAliveTimeout: -1
threadPriority: 5
useComet: trues
SLCipherSuite: ALL
 soLinger: -1
sslEnabledProtocolsArray: Array[java.lang.String] of length 0
sendfileCount: 0
socketProperties: org.apache.tomcat.util.net.SocketProperties@556ca3d5
bindOnInit: true
backlog: 100
port: 8009
 usePolling: true
deferAccept: true
running: true
algorithm: SunX509
 pollTime: 2000
useCometTimeout: false
name: ajp-apr-8009
 sendfileSize: 1024
 maxHeaderCount: 100
 clientAuth: false
keepAliveCount: 0
tcpNoDelay: true
maxConnections: 8192
sSLVerifyClient: none
 maxKeepAliveRequests: 100
keystoreType: JKS
keystoreFile: /home/jboss/.keystore
 paused: false
sSLHonorCipherOrder: false
sSLProtocol: all
 sessionTimeout: 86400
 ciphersArray: Array[java.lang.String] of length 0
 sslProtocol: TLS
acceptorThreadCount: 1
 sendfileThreadCount: 1
soTimeout: -1
 currentThreadsBusy: 0
 daemon: true
sSLInsecureRenegotiation: false</PRE></DIV>
-----------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
O<SPAN style="LINE-HEIGHT: normal; WHITE-SPACE: pre-wrap">K - Number of results: 106</SPAN><DIV><PRE style="LINE-HEIGHT: normal; WORD-WRAP: break-word; WHITE-SPACE: pre-wrap">Name: Catalina:type=ThreadPool,name="ajp-apr-8009"
modelerType: org.apache.tomcat.util.modeler.BaseModelMBean
useSendfile: false
minSpareThreads: 10
acceptorThreadPriority: 5
maxThreads: 200
sSLEnabled: false
sSLVerifyDepth: 10
pollerThreadCount: 1
localPort: 8009
connectionCount: 1
currentThreadCount: 0
keepAliveTimeout: -1
threadPriority: 5
useComet: true
sSLCipherSuite: ALL
soLinger: -1
sslEnabledProtocolsArray: Array[java.lang.String] of length 0
sendfileCount: 0
socketProperties: org.apache.tomcat.util.net.SocketProperties@556ca3d5
bindOnInit: true
backlog: 100
port: 8009
usePolling: true
deferAccept: true
running: true
algorithm: SunX509
pollTime: 2000
useCometTimeout: false
name: ajp-apr-8009
sendfileSize: 1024
maxHeaderCount: 100
clientAuth: false
keepAliveCount: 0
tcpNoDelay: true
maxConnections: 8192
sSLVerifyClient: none
maxKeepAliveRequests: 100
keystoreType: JKS
keystoreFile: /home/jboss/.keystore
paused: false
sSLHonorCipherOrder: false
sSLProtocol: all
sessionTimeout: 86400
ciphersArray: Array[java.lang.String] of length 0
sslProtocol: TLS
acceptorThreadCount: 1
sendfileThreadCount: 1
soTimeout: -1
currentThreadsBusy: 0
daemon: true
sSLInsecureRenegotiation: false</PRE></DIV>


4. 위의 리스트내역 중 Name에 해당하는 부분을 URL의 Quer를 붙여넣으면 각 MBean에 대한 항목 확인 가능
예: http://host-ip:port/manager/jmxproxy/?qry=Catalina:type=DataSource,context=/host-manager,host=localhost,class=javax.sql.DataSource,name="jdbc/readPool"

2013년 2월 25일 월요일

[펌] RMI 사용시 -XX:+DisableExplicitGC 옵션 관련

원글 : http://logonjava.blogspot.kr/2010/07/java-distributed-gc-and.html
자바 프로그램에서 OutOfMemoryError 는 흔하게 발생하지만, 그 원인이 무척 다양하기 때문에 단순하게 메모리 부족으로 판단해서는 안된다.

에러 메시지에서 구분할 수 있는 세 가지는 1. heap memory가 부족한 경우, 2. perm area memory가 부족한 경우, 3. 새로운 thread를 생성할 수 없는 경우이다.

heap memory가 부족한 것은 JVM에 지정한 최대 heap 메모리 크기보다 더 큰 메모리 영역을 사용하려고 시도했기 때문인데 application이 memory leak을 발생시켜 사용 메모리가 점점 증가하는 경우라면 application의 leak을 해결하든지, 주기적으로 JVM을 재구동하든지 해야 한다. 그것이 아니라 순간적으로 큰 메모리를 사용할 가능성이 높은 applicaiton이라면 JVM의 최대 heap 크기를 늘려줘야 할 것이다.

이와 달리 perm area 부족의 경우는 조금 다른데 Sun(지금은 Oracle)의 HotSpot JVM에서는 permanent area 에 String 상수 풀이나 define된 클래스 정보들을 두고 있다.

보통의 경우 상수 풀이나 클래스 정보는 한번 load되면 unload할 일이 없지만, application의 특성에 따라 pluggable module 이 필요한 경우 이를 구현하기 위해 동적으로 ClassLoader를 생성하고 삭제하는 방법을 흔히 사용하는데, 이때 클래스 정보들이 적절히 unload되지 않으면 perm area에서도 memory leak이 생기게 된다.
즉, perm area에서의 memory leak은 ClassLoader 객체가 제대로 garbage collect 되지 않을 때 발생한다.

application에서 memory leak이 발생시키지 않은 경우에도 gc 옵션을 잘못 지정하여 발생할 수도 있는데, 흔히 발생했던 원인 중 하나는 JVM에서 CMS (Concurrent Mark and Sweep) gc 알고리즘을 지정한 경우이다.

CMS gc 알고리즘에서는 기본값으로는 perm area 에 대해 gc를 하지 않는다.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6329603

이 경우 해결책은 CMS 알고리즘을 쓰지 않거나 다음 옵션을 추가하는 것이다.

-XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled

최근에 이와 다른 이유로 perm area 에서 OutOfMemoryError가 나는 경우가 있어, heap dump를 분석해본 적이 있다. 뜻밖에도 remote 객체가 ClassLoader를 reference하고 있어서 ClassLoader가 gc되지 못한 경우였다.
RMI 혹은 EJB (JRMP)를 사용하는 application이었는데 gc가 안정적으로 실행되도록 -XX:+DisableExplicitGC 옵션을 켜놓았었다.

-XX:+DisableExplicitGC 옵션은 System.gc() 메소드를 호출해도 아무 일이 일어나지 않도록 한다.
이 때문에 분산 gc가 제대로 수행되지 않아서 ClassLoader가 gc되지 못하였고, 결국 perm area가 full이 났던 것이다.

자바의 분산 gc (distributed gc, 즉 원격 객체에 대한 gc) 알고리즘은 기본적으로 60초마다 System.gc() 메커니즘에 따라 full gc를 요청하게 된다.
이때, 더 이상 사용하지 않는 원격 객체에 대한 참조 count를 떨어뜨리고, 더 이상 원격 객체에 대한 참조가 없으면 unexport를 하게 된다.

이 간격을 늘리려면 기본값인 60,000(60초)을 3,6000,000(1시간) 정도로 바꿔주면 된다.

-Dsun.rmi.dgc.client.gcInterval=36000000
-Dsun.rmi.dgc.server.gcInterval=36000000

분산 gc가 발생할 때마다 full gc가 일어나는 것 때문에 시스템 성능이 급격히 떨어지는 것을 막기 위해 다음 요청이 접수되었다.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5025281

Sun에서는 JDK 1.6부터는 다음 JVM 옵션을 사용할 수 있도록 개선하였다. 또 dgc 간격 기본값을 1분에서 1시간으로 늘렸다.

-XX:+ExplicitGCInvokesConcurrent

이 옵션이 설정된 경우는 System.gc()가 호출되더라도 gc 알고리즘이 concurrent gc 인 경우 full gc가 일어나는 것이 아니라 concurrent gc 를 실행한다.

따라서, RMI나 EJB를 사용하는 경우의 HotSpot VM 튜닝은 다음을 권장한다.

1. -XX:+DisableExplicitGC 은 설정하지 않는 게 좋다.
2. JDK 1.5 이하일 경우에는 dgc interval을 늘려준다. 보통 1시간 정도면 괜찮다.

 -Dsun.rmi.dgc.client.gcInterval=36000000
 -Dsun.rmi.dgc.server.gcInterval=36000000

3. JDK 1.6 이상일 경우에는 다음 옵션만 켜주면 큰 문제가 없다. dgc interval은 기본값이 이미 1시간으로 변경되어 있으므로 수정할 필요가 없다.

-XX:+ExplicitGCInvokesConcurrent

2013년 2월 19일 화요일

윈도우즈에서 tail 쓰기

윈도우에서 유닉스처럼 tail 을 쓰기 위해서는

1. 윈도우용 tail 파일을 받는다 (비주얼스튜디오가있다면 sourceforge.net 에서 직접 컴파일 해봐도 .......64bit용은 없는듯..) \
http://tailforwin32.sourceforge.net/

2. 윈도우가 제공하는 툴킷에 포함되어있다. (베타버전인듯. Windows Server 2003; Windows XP만 된다고 하는데.....dll 들이 많아서 설치해보진 않음..)
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en&displaylang=en#Instructions

즐겁게 일하자~

열정, 소신, 의지, 희망.........
열정, 소신, 의지, 희망..........

소리에 놀라지 않는 사자와 같이 그물에 걸리지 않는 바람과 같이 무소의 뿔처럼 혼자서 가라

[펌] 박명수 어록

공부 안하면 더울 때 더운데서 일하고 추울때 추운데서 일한다

시작이 반이다가 아니라 시작은 시작일뿐이다

세상은 넓고 할일은 많지 않다

늦었다고 생각할때는 이미 늦었다, 그러니 지금 당장 시작하자

교복을 줄일 수록 성적도 내려간다

남자친구를 만들고 싶으면 집에만 있지 말고 얼굴에 뭐라도 찍어 바르고 밖에 남자들이 많이 있는 모임 등에 자주 나가라, 인연을 만들려면 노력을 해야 한다

티끌 모아 봤자 티끌이다

살을 빼고 싶으면 줄넘기를 해서 뛰든지 운동을 해라
운동이 싫으면 바지 치수 큰 거를 사입든지 해라

가는말이 고우면 얕본다

즐길수 없으면 피하라
고생끝에 골병난다

나까지 나설 필요 없다

참을 인이 세번이면 호구
포기하면 편하다

안되면 말고

잘생긴 놈은 얼굴값을 하고 못생긴 놈은 꼴값을 한다

'내 너 그럴줄 알았다'_알았으면 제발미리 말을 해줘라

대문으로 가난이 찾아오면 사랑은 창문으로 도망간다

부모 욕 하는건 참아도 내 욕 하는건 못참는다
일찍 일어나는 새가 피곤하다

일찍 일어나는 벌레가 잡아먹힌다

효도는 셀프

어려운 길은 길이 아니다

개천에서 용난놈 사귀면 개천으로 빨려들어간다

새벽에 먹는 맥주와 치킨은 0칼로리

성형으로 이뻐진게 아니라 하기 전이 이뻤던거다

내일도 할 수 있는 일을 굳이 오늘 할 필요는 없다

남자는 애 아니면 개

성공은 1퍼센트의 재능과 99퍼센트의 빽

예술은 비싸고 인생은 더럽다

하나를 보고 열을 알면 무당

원수는 회사에서 만난다

티끌모아 티끌

헌신하면 헌신짝된다

동정할거면 돈으로 줘라

2013년 2월 8일 금요일

Jboss jsp hot-deploy 방법

대부분 WAS 의 기본 Production mode 정책은 jsp 에 대해 hot-deploy 되지 않는 것이다.
그러나 개발 편의를 위해 대부분 해당 설정을 지원해줘야한다..

Jboss  에서는 다음과 같이 가능하다 (추가 방법은 확인중)

 1) web.xml 의 시간을 최신으로 변경 (유닉스 touch 명령어 등..)
    - jsp 파일을 반영 후 web.xml 의 파일 시간을 최신으로 바꿔주면 jsp 재컴파일이 일어난다.

 2) web.xml 에 다음과 같은 항목 추가
   <init-param>
  <param-name>development</param-name>
  <param-value> true </param-value>
  </init-param>
   ==> WAS 자체를 develpment 모드로 띄우는 것이라 우선 다른 방법을 써야할 듯 하다.