{"id":3176,"date":"2013-07-15T08:13:46","date_gmt":"2013-07-15T13:13:46","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=3176"},"modified":"2013-07-15T08:16:14","modified_gmt":"2013-07-15T13:16:14","slug":"determining-the-source-of-high-java-cpu","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2013\/07\/15\/determining-the-source-of-high-java-cpu\/","title":{"rendered":"Determining the source of high java CPU"},"content":{"rendered":"<p>This post is related to a situtation in which you find yourself with high CPU utilization, but can&#8217;t determine the source.   This will gather thread dumps and the CPU used by each thread.  For the threads that use a large amount of CPU, you can convert the PID to a hexadecimal nid, and get the thread stack trace in the dump.<\/p>\n<p>This script is useful for the java HotSpot compiler.<\/p>\n<p>For example, if in the output generated below you determine that between two runs of the script PID 25221 is using a lot of CPU, you can get the nid (thread id, essentially) by doing the following&#8230;<\/p>\n<pre lang=\"text\">\r\n-bash-4.1$ printf \"%x\\n\" 25221\r\n6285\r\n-bash-4.1$\r\n<\/pre>\n<p>You can then search the thread dump for that thread by searching for nid=0x6285, and examine its stack trace.<\/p>\n<p>The complete gathering script is shown below.<\/p>\n<pre lang=\"text\">\r\n#!\/bin\/sh\r\n<<HEADER\r\n-------------------------------------------------------------------------------------------------\r\nAuthor:         Steve Howard\r\nDate:           July 15, 2013\r\nPurpose:        Record thread dump and CPU used by each thread during a period of interest.\r\n-------------------------------------------------------------------------------------------------\r\nHEADER\r\n\r\nPID=$(jps | grep Main | awk '{print $1}')\r\necho $PID\r\nDATE=$(date '+%Y%m%d%H%M')\r\njstack $PID > ${DATE}_dump.txt\r\nps -eLfp $PID | awk '{print $4,$9}' >> ${DATE}_dump.txt<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This post is related to a situtation in which you find yourself with high CPU utilization, but can&#8217;t determine the source. This will gather thread dumps and the CPU used by each thread. For the threads that use a large&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2013\/07\/15\/determining-the-source-of-high-java-cpu\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[24,25,28,27],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3176"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3176"}],"version-history":[{"count":5,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3176\/revisions"}],"predecessor-version":[{"id":3185,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3176\/revisions\/3185"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3176"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}