How is jstack being used to find the bottlenect of a java program

來源:互聯網
上載者:User

Jstack is a built-in tool of JVM which is used to analyze the performance of java program.It prints the stack information of a process to the standard output of your system.Of cause you can redirect the output of the jstack to a file for later analysis.When
you want to find the bottleneck of a java program,you can use jstack.For example: first,run you program named "myprogram" on the server and then figure out the process id (pid:2133) of your program(you can use "ps" command in linux shell). the last,start the
jstack tool during the running of your program like this:

jstack 2133 > out.txt

then you can analyse the content of "out.txt" to find out the bottlenect of your program.To make the result more accurate,you need to take samples randomly of the program process stack,This is rather simple,right?

But how can the content of the output file of the jstack show you the bottleneck ? To understand this you need to know what do the jstack have done when it works.

When the jstack works,it reads the current stack information of the process,and that's it,that's all the jstack do.The stack information will show you which functions are the process invoking at the point you run jstack and which function is invoked by which.Find
out the most frequently invoked functions(there may be serveral of them) in your program from the stack sample files you take. These "Most Frequently Invoked Functions" is right the bottleneck of your program. 

why is  the  "Most Frequently Invoked Functions" the bottleneck of the program? Now let's make an explaination. The jstack caputre the stack information at one point during the running of the program, if some funcions' call information frequently appears
in the jstack output sample file,that's indicating that the functions execution may take a long relatively long time,which is the reason why their stack information being easily caputured by jstack. So we can come to a conclusion:the most frequently appeared
functions in the jstack output information are the bottlenecks of the program.

Do you understand now ?

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.