2014. 12. 16. 15:32

When working with large (server side) java application, sometimes it would be nice if you could look inside, to see what thread is taking up so much cpu time, and why. Something similar to the Unix top command, but then showing all threads in one (java) application, instead of all processes in the system.

When I was looking for such a monitoring application, I came accross the 2.0 version of MC4J that provides a “Thread Info” panel that displays threads together with CPU usage; exactly what I needed. Unfortunately, there is only an alpha release of this MC4J version, that is not yet perfectly stable. Moreover, the thread info panel doesn’t handle applications with large amounts of threads very well. As the source code of this version of MC4J is not (yet) publically available, this option turned out to be a dead end.

To my surprise, other applications with such functionality are hard to find. There are probably enough profiling applications that can do the job, but I wanted something simple, something JMX-based, that can used also to monitor applications running in production.

There is however something called JTop, which is a plugin for JConsole. It’s actually a demo for the new (since Java 6) JConsole plugin API, that does show CPU usage per thread. It’s fairly basic and only shows total CPU usage, which is not very usefull. You would expect that (after a year), somebody would have extended the demo to something more useful, but as I couldn’t find anything like that, I thought I should give it a try myself.

The result is a JConsole plugin that displays the top threads, sorted by cpu usage in the last sampling period. It also displays cpu usage history, and an average over the last 10 sampling periods.


 

To avoid ending up with an unresponsive user interface when monitoring applications with large number of threads, I took a few precautions. First of all, the plugin has it’s own refresh rate. It’s independent from the JConsole poll interval, which is 4 seconds by default. For applications with large amounts of threads, this is way too short: only retrieving all thread information can already take 4 or 5 seconds! Although you can change the JConsole poll interval with a command line option, I thought it would be more convenient to be able to change it from the monitoring panel. It’s default set to 10 seconds, which I think is reasonable in most cases. If you notice that cpu usage measurement takes too much of the application under test, just increase the sample period and see the RMI Connection thread that processes these request, sink in the list.

Another precaution was not to list all threads in the table. Displaying thousands of rows in a table is quite useless in any case, and I was afraid it would seriously harm performance. Eventually, diplaying that many rows turned out to be not much of a problem; I guess I still suffer from an prejudice with
respect to Swing performance…

Using MX4J also showed me that in a continuously refreshing table, it’s hard to select a thread in order to see it’s stacktrace. Therefore, in this plugin, tracing a thread is “sticky”: when you click a row in the table, the stacktrace of that thread is shown immediately and is refreshed with each new sample, until you deselect it or select another thread.

Even though having threads sorted by cpu usage is the logical thing to do, it’s not always convenient when you’re studying the results, as rows keeping moving with each refresh. To lock the rows to there current position, click the “fix order” button. The topmost rows (actually all rows with a non-zero cpu usage), will stay where they are. Rows that had a cpu usage of zero, but have a non-zero value in the next sampling periods, will appear just below these rows, to avoid that you oversee any thread that suddenly takes a large amount of cpu time.

You can run the plugin by downloading the jar-file and passing it to JConsole with the plugin option:
jconsole -pluginpath topthreads.jar. When JConsole connects, it should have a seventh tab named “top threads”.

'Java' 카테고리의 다른 글

JVM 현재 설정된 설정값 확인  (0) 2015.06.24
Hotspot JVM GC 방식  (0) 2014.12.09
[모델1] 간단한 로그인 시스템  (0) 2014.11.01
Path 클래스 사용하기  (0) 2014.10.01
singleton 패턴  (0) 2014.10.01
Posted by 아도니우스
2014. 12. 10. 13:18

1. Example of Scriptlet

<html>

<head>

</head>

<%

int count=0;

%>

<body>

Page Count is <% out.println(++count); %>

</body>

</html> 

 

2. Example of JSP Scriptlet Tag

index.html

<form method = "post' action = "welcome.jsp"

Name <input type="text" name = "user">

<input type="submit value="submit">

</form>

 

welcome.jsp

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome Page</title>
    </head>


  <body>
        Hello, <% out.println(user); %>
  </body>
</html

Posted by 아도니우스
2014. 12. 9. 10:13

Hotspot JVM GC 방식 

 

 Young Gen

 Old Gen

 GC 방식

 장/단점

 Serial GC

 Generation Algorithm

 Mark-Compact Algorithm

 1) Old 살아있는 객체 식별(Mark)

 2) 힙 앞부분부터 확인해 살아 있는 것만 남김(Sweep)

 3) 각 개체들이 연속되게 쌓이도록 가장 앞 부분부터 적재(Compact)

- 운영서버에 권고하지 않음

 Parallel GC

 Generation Algorithm

 (Thread 여러개)

 Mark-Compact Algorithm

 Serial GC와 동일하나 Young Gen을 병렬처리 하여 처리량을 늘림으로써 빠르게 객체를 처리할 수 있음

 

 Parallel Old GC

 Generation Algorithm

 (Thread 여러개)

 Parallel Compaction Algorithm (Mark-Summary-Compaction)

Summary 단계는 앞서 GC를 수행한 영역에 대해서 별도로 살아있는 객체를 식별한다는 점(Mark-Sweep-Compaction 차이)

- 기존 Parallel GC에서 Old Gen 처리량도 늘리자는 취지

 CMS

 Parallel Copy Algorithm

 Concurrent Mark-and-Sweep Algorithm

1) Initial Mark

2) Concurrent Mark

3) Remark

4) Concurrent Sweep

- 응답시간 개선에 집중

- 시간 절약 효과

 G1 GC

 Evacution Pause

 Concurrent Marking

1) Concurrent Marker가 각 힙 region 내의 살아있는 object 양 계산(Garbage가 많은 region 선택)

2) Young GC

   살아있는 object는 Survivor region과 Old region으로 이동(Stop-the-copy)

3) Compaction

   Large Chunk 로 Free space 병합 Fragmentaion 방지

  Fast Allocation Free List를 사용하지 않음, Linear 방식, TLAB 방식

- Gen 물리적 구분 사라짐

- 힙을 region으로 나눠 쪼개짐

- Garbage Object로 가득찬 Region 부터 Collection 수행

- copy 작업은 pause Time의 가장 큰 요인

 

※ 참고사이트 : http://dragon1.tistory.com/33

'Java' 카테고리의 다른 글

JVM 현재 설정된 설정값 확인  (0) 2015.06.24
“top threads” plugin for JConsole  (0) 2014.12.16
[모델1] 간단한 로그인 시스템  (0) 2014.11.01
Path 클래스 사용하기  (0) 2014.10.01
singleton 패턴  (0) 2014.10.01
Posted by 아도니우스