加载中…
个人资料
jdmaverick
jdmaverick
  • 博客等级:
  • 博客积分:0
  • 博客访问:490
  • 关注人气:0
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

VisualVM, Sliver Bullet for Troubleshooting

(2009-06-20 20:29:20)
标签:

java

visualvm

author

jd

杂谈

As a college student in a famous university of China, I am participated in National Key Laboratory to develop a mobile multimedia system. In this project, Red5, an open source flash server written in Java, is chosen as streaming server. As a Sun Certificated Java Programmer, I am responsible for developing Java components to extend the functions Red5 currently provides. In this article, I will share some experience about how VisualVM facilitates Java development and makes the developing of complex projects an easier job.

 VisualVM, <wbr>Sliver <wbr>Bullet <wbr>for <wbr>Troubleshooting

The system architecture is showed above. It models a client/server-based multimedia system. The central server is responsible for registration, authentication, multimedia storage and live stream publishing. Considering all the media in user’s computer is not in FLV format, each received media have to be processed before being published by Red5. As our system enables live stream publishing, the delay of uploading, processing and downloading have to be minimized. My job is developing a Java program to optimize this procedure. In the process of developing an optimization program, VisualVM plays a very important role.

 

VisualVM Installation

 

Installation was as easy as usual, the version I use is JDK6u14; however, when started for the fist time, the VisualVM warned that Local Application Cannot Be Detected. Though website is provided to solve the problem, https://visualvm.dev.java.net/ is not accessible in China. I searched other Java forums to solve this problem and make VisualVM run.

Find the Bottleneck

Firstly, I tested the video processing component in local computer. The GUI of video processing component is illustrated as follows

VisualVM, <wbr>Sliver <wbr>Bullet <wbr>for <wbr>Troubleshooting.

 

When the media is processing, it is using 49.5%percent of my 1.59GHz Sempron, which is showed in the Figure below. As performance is the major concern of my job, I used tools provided by VisualVM to find out where the problem lies. In the beginning, I select a short piece of film in AVI format to process. It took 20 minutes to convert a 10M video and this speed, of course, was unbearable. Even worse, when the conversion was finished, some threads may still keep the references of the original video, which make the component can not successfully exit.

VisualVM, <wbr>Sliver <wbr>Bullet <wbr>for <wbr>Troubleshooting

When I opened the snapshot view I find out how much time each method consumed. Fortunately, I get explicit information from VisualVM and get to know where to optimize. In our code, there is a sort() function, it was called 2867 times and occupied 48.9% of time. I scrutinized the code and only to find that the sort () function was realized in bubble sort!! So I changed to use Java API, which largely improved the performance.

 

Secondly, the transmission component was always down. Sometimes it uploaded files that were damaged and sometimes it keeps running for no reason. In order to solve this subtle problem, I used VisualVM again to what was happening inside the component. In this component, a thread pool was used to enable the access of more than one user. Through VisualVM, I found that the number of threads was consistently increasing rather than kept stable. Then I checked the code about the thread pool and found that a function was not written correctly and resulted in creating a new thread each time the users requested. The threads is showed is the Figure below. When the error is fixed, my compoent can run smoothly.

VisualVM, <wbr>Sliver <wbr>Bullet <wbr>for <wbr>Troubleshooting

Conclusion

VisulaVM is really a useful tool for troubleshooting. Personally I think it is easier to use than JProfiler. I am a SCJP who have passion for the latest technology developed by Sun. VisualVM is one of Sun’s 27 years innovations and it shows the brilliance of Sun’s engineers.

0

阅读 收藏 转载 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

新浪公司 版权所有