- 浏览: 119490 次
文章分类
最新评论
java进程占用cpu高排查-数据库连接过多
原文:http://blog.163.com/xiangfei209@126/blog/static/98695674201622095414808/
物理环境:
线上服务器配置是16g内存,单个物理cpu,四核四线程
系统环境:
线上有一千多个机器24小时不间断调用服务器,该服务器没有做任何缓存,直接操作数据库,
jvm参数:
/usr/share/tomcat7/bin/catalina.sh
<wbr><div><strong>问题场景:</strong></div>
<div> 调用服务器接口很慢,后台也打不开</div>
<div><strong>问题分析:</strong></div>
<div> 业务没有进行密集型IO计算,排查此情况</div>
<div> 操作数据库频繁,该情况有可能</div>
<div> </div>
<div><strong>排查步骤</strong></div>
<div><strong>第一种排查问题方式:</strong></div>
<div>1、通过top命令,观察发现tomcat pid 8509 cpu基本超过125%</div>
<div>2、通过lsof 命令查看nginx和mysql连接数</div>
<div>lsof -i:80 | awk '{print $2}' | uniq -c 查看nginx数量,默认开启了1024个连接,发现不是nginx问题</div>
<div>lsof -i:3306 | awk '{print $2}' | uniq -c 查看数据库连接默认开启了100个,发现数据库连接已经到达95个,可能是数据库太频繁导致</div>
<div><br></div>
<div>3、接下来必须抓取heap dump 和 thread dump 来确定问题所在</div>
<div> <strong>命令行方式:</strong>
</div>
<div> jmap -dump:file=/var/log/jvm-log/heapdump.hprof,format=b8509生成heap dump</div>
<div> jstack -l8509> /var/log/jvm-log/threaddump.log 生成thread dump</div>
<div> <strong>visualVm方式:</strong>
</div>
<div> 配置jmx:</div>
<div> vim /usr/share/tomcat7/bin/catalina.sh</div>
<div> 在其中“# ----- Execute The Requested Command -------------”之前插入一行(中间没有换行),</div>
<div> 内容如下(其中9999为监控端口,若要更换端口请自己填写):CATALINA_OPTS="$CATALINA_OPTS</div>
<div> -Dcom.sun.management.jmxremote</div>
<div> -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.ssl=false - Dcom.sun.management.jmxremote.authenticate=true"</div>
<div> 配置完jmx,然后通过visualVM连接过去,且安装memory pools插件,该插件主要来分析,heap(2新生代+老年代),perm(持久代)内存信息</div>
<div> 看thread heap发现 操作数据库一个方法出现Locked ownable synchronizers</div>
<div> </div>
<div> </div>
<div><strong>第二种排查问题方式:</strong></div>
<div>1、通过top命令,观察发现tomcat pid 8509 cpu已经到达125%<br>
2、找到该进程后,如何定位具体线程或代码呢,首先显示线程列表,并按照CPU占用高的线程排序:<br>
#ps -mp 8509 -o THREAD,tid,time | sort -rn</div>
<div>结果如下:<br>
USER %CPU PRI SCNT WCHAN USER SYSTEM TID TIME<br><div>tomcat7 10.3 19 - futex_ - - 8522 00:10:18</div>
<div>tomcat7 0.3 19 - futex_ - - 8521 00:00:17</div>
<div>tomcat7 0.2 19 - futex_ - - 8622 00:00:10</div>
找到了耗时最高的线程8522,占用CPU时间有10分钟了<br>
将需要的线程ID转换为16进制格式:<br>
# printf "%x\n" 8522<br>
214a<br>
最后打印线程的堆栈信息:<br>
# jstack8509|grep 214a -A 30</div>
<div><br></div>
<div><strong>第三种排查问题方式:</strong></div>
<div>vimshow-busy-java-threads.sh</div>
<div>
<pre class="prettyprint" style="white-space:pre-wrap; padding:2px; border:1px solid rgb(136,136,136)"><pre style="line-height:normal; white-space:pre-wrap; word-wrap:break-word"><span class="com" style="line-height:28px; color:rgb(136,0,0)">#!/bin/bash</span><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)"># @Function</span><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)"># Find out the highest cpu consumed threads of java, and print the stack of these threads.</span><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)">#</span><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)"># @Usage</span><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)"># $ ./show-busy-java-threads.sh</span><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)">#</span><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)"># @author Jerry Lee</span><br style="line-height:28px"><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">readonly</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> PROG</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">`basename $0`</span><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">readonly</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">a COMMAND_LINE</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=(</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$0"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$@"</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">)</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">usage</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">()</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> cat </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)"><<</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">EOF</span><br style="line-height:28px"><span class="typ" style="line-height:28px; color:rgb(102,0,102)">Usage</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">PROG</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">OPTION</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]...</span><br style="line-height:28px"><span class="typ" style="line-height:28px; color:rgb(102,0,102)">Find</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">out</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> the highest cpu consumed threads of java</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">and</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">print</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> the stack of these threads</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">.</span><br style="line-height:28px"><span class="typ" style="line-height:28px; color:rgb(102,0,102)">Example</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">:</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">PROG</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">c </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">10</span><br style="line-height:28px"><br style="line-height:28px"><span class="typ" style="line-height:28px; color:rgb(102,0,102)">Options</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">:</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">p</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">pid find </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">out</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> the highest cpu consumed threads </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">from</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> the specifed java process</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">default</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">from</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> all java process</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">.</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">c</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">count </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">set</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> the thread count to show</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">default</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">is</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">5</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">h</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">help display </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">this</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> help </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">and</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">exit</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">EOF</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">exit</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> $1</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">readonly</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> ARGS</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">`getopt -n "$PROG" -a -o c:p:h -l count:,pid:,help -- "$@"`</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">?</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">ne </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">0</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> usage </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">1</span><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">eval</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">set</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"${ARGS}"</span><br style="line-height:28px"><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">while</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">true</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">;</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">do</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">case</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$1"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">in</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">c</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">|--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">count</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">)</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> count</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$2"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> shift </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">2</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">;;</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">p</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">|--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">pid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">)</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> pid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$2"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> shift </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">2</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">;;</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">h</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">|--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">help</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">)</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> usage</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">;;</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">--)</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> shift</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">break</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">;;</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">esac</span><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">done</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">count</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">count</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">:-</span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">5</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">redEcho</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">()</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">c </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">dev</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">stdout </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="com" style="line-height:28px; color:rgb(136,0,0)"># if stdout is console, turn on color output.</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">ne </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"\033[1;31m"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">n </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$@"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">e </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"\033[0m"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">||</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$@"</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">yellowEcho</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">()</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">c </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">dev</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">stdout </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="com" style="line-height:28px; color:rgb(136,0,0)"># if stdout is console, turn on color output.</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">ne </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"\033[1;33m"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">n </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$@"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">e </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"\033[0m"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">||</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$@"</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">blueEcho</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">()</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">c </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">dev</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">stdout </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="com" style="line-height:28px; color:rgb(136,0,0)"># if stdout is console, turn on color output.</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">ne </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"\033[1;36m"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">n </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$@"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">e </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"\033[0m"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">||</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$@"</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><br style="line-height:28px"><span class="com" style="line-height:28px; color:rgb(136,0,0)"># Check the existence of jstack command!</span><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">if</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">!</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> which jstack </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&></span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">dev</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">null</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">;</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">then</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">z </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$JAVA_HOME"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> redEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"Error: jstack not found on PATH!"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">exit</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">1</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">!</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">f </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$JAVA_HOME/bin/jstack"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> redEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"Error: jstack not found on PATH and $JAVA_HOME/bin/jstack file does NOT exists!"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">exit</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">1</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">!</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">x </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$JAVA_HOME/bin/jstack"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> redEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"Error: jstack not found on PATH and $JAVA_HOME/bin/jstack is NOT executalbe!"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">exit</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">1</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">export</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> PATH</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"$JAVA_HOME/bin:$PATH"</span><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">fi</span><br style="line-height:28px"><br style="line-height:28px"><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">readonly</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> uuid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">`date +%s`</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">_$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">RANDOM</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">_$$</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">cleanupWhenExit</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">()</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> rm </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">tmp</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">uuid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">_</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">*</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&></span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">dev</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">/</span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">null</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">trap </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"cleanupWhenExit"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> EXIT</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">printStackOfThreads</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">()</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> line</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> count</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">1</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">while</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> IFS</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">" "</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> read </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">a line </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">;</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">do</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> pid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">line</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">0</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> threadId</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">line</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">1</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> threadId0x</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"0x`printf %x ${threadId}`"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> user</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">line</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">2</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> pcpu</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">line</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">4</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]}</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">local</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> jstackFile</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">=</span><span class="str" style="line-height:28px; color:rgb(0,136,0)">/tmp/</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">uuid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">_$</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">pid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">!</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">f </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"${jstackFile}"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">if</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"${user}"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">==</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"${USER}"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">];</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">then</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> jstack $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">pid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">></span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">jstackFile</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">else</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">if</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> $UID </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">==</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="lit" style="line-height:28px; color:rgb(0,102,102)">0</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">];</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">then</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> sudo </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">u $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">user</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> jstack $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">pid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">></span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">jstackFile</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">else</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> redEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"[$((count++))] Fail to jstack Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> redEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"User of java process($user) is not current user($USER), need sudo to run again:"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> yellowEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">" sudo ${COMMAND_LINE[@]}"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">continue</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">fi</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">fi</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">||</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> redEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"[$((count++))] Fail to jstack Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> echo</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> rm $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">jstackFile</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">continue</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> blueEcho </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"[$((count++))] Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user}):"</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> sed </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"/nid=${threadId0x} /,/^$/p"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">n $</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">jstackFile</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">done</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><br style="line-height:28px"><br style="line-height:28px"><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)">ps </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="typ" style="line-height:28px; color:rgb(102,0,102)">Leo</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> pid</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">lwp</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">user</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">comm</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">,</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">pcpu </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">--</span><span class="kwd" style="line-height:28px; color:rgb(0,0,136)">no</span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">headers </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">|</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">{</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">[</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">z </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"${pid}"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">]</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">&&</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> awk </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">'$4=="java"{print $0}'</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">||</span><br style="line-height:28px"><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> awk </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">v </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"pid=${pid}"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">'$1==pid,$4=="java"{print $0}'</span><br style="line-height:28px"><span class="pun" style="line-height:28px; color:rgb(102,102,0)">}</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">|</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> sort </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">k5 </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">r </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">-</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">n </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">|</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> head </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">--</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)">lines </span><span class="str" style="line-height:28px; color:rgb(0,136,0)">"${count}"</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> </span><span class="pun" style="line-height:28px; color:rgb(102,102,0)">|</span><span class="pln" style="line-height:28px; color:rgb(0,0,0)"> printStackOfThreads</span></pre></pre>
chmod +show-busy-java-threads.sh</div>
<div>./show-busy-java-threads.sh</div>
<div>参考:https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#beer-show-busy-java-threadssh</div>
<div> </div>
<div><strong>修复问题:</strong></div>
<div>请求频繁的sql语句放到redis,观察一段时间cpu静下来</div>
</wbr>
JAVA_OPTS="$JAVA_OPTS -server -Xms1024M -Xmx2048M -XX:PermSize=256M - XX:MaxPermSize=512M"
相关推荐
### Java进程高CPU占用故障排查 在日常的运维与开发工作中,经常遇到Java应用出现高CPU占用的问题。这类问题不仅会影响系统的稳定性和响应速度,还可能导致服务不可用。因此,对于此类故障的快速定位和解决变得尤为...
通过输入`top`命令,我们可以看到各个进程的CPU和内存使用率,从中找出CPU占用率最高的Java进程。记下该进程的PID(进程ID)。 2. **获取问题线程的TID** 接下来,我们需要找出这个进程中的具体哪个线程导致了CPU...
`top`命令是监控系统资源使用情况的利器,通过它我们可以看到哪个进程占用了最多的CPU资源。在案例中,`top`命令显示进程ID为31737的进程CPU使用率极高。接着,使用`top -Hp 31737`进一步查看该进程内部各个线程的...
- 使用`top`命令查看哪些进程占用了大量的CPU资源,并进一步排查这些进程是否存在性能瓶颈。 - 分析线程转储文件,找出占用CPU时间较长的线程并优化相应的代码逻辑。 3. **文件句柄限制调整**: - 调整系统文件...
- **进程启动确认:** 通过 `ps -ef | grep` 检查特定服务是否启动,如 `ps -ef | grep httpd` 和 `ps -ef | grep java` 分别检查 Apache 和 Java 进程。 - **端口冲突检测:** `netstat -an | grep <port>` 用于检查...
- 数据库连接:检查数据库连接状态。 - JVM工具:利用`jps`, `jinfo`, `jstat`, `jstack`, `jmap`等工具监控JVM状态。 对于Java服务端问题,通常需要结合业务日志、数据库状态、JVM监控以及内存分析等多方面进行...
2. 服务器监视:监控应用服务器和中央服务的负载情况,包括CPU使用率、内存占用、磁盘空间等,及时发现并解决问题。 3. 用户监视:跟踪用户活动,识别登录异常、长时间未活动的会话,以便进行资源管理。 4. 性能监视...
- **CPU使用率**:追踪Java进程的CPU占用,辅助找出高CPU消耗的根源。 - **系统资源监控**:监控服务器的CPU、内存、磁盘和网络使用情况,全面了解系统运行状态。 - **SQL性能监控**:捕获和分析SQL执行情况...
一个典型的例子是,当Java应用出现响应慢的问题时,通过nmon监控可以发现CPU占用过高,进一步定位到特定的Java进程,进而可能发现是某个服务或方法引起的。此时,可以优化代码,减少不必要的计算,或者调整JVM参数,...
- **高CPU使用率**:定位占用CPU的进程或线程,优化代码或调整线程池设置。 - **连接超时**:排查网络问题,优化数据库连接配置,考虑使用连接池。 - **系统崩溃**:查看错误日志,确定故障原因,修复问题或调整...
标签中的“java进程分析”进一步确认了这个工具可以监控和分析Java进程的整体性能,包括CPU使用率、内存使用情况、垃圾收集状态等。这对于优化应用性能、排查问题至关重要。 "jstack"标签则直接关联到了Oracle JDK...
比如,当发现内存占用过高,可能需要查看是否有内存泄漏,或者哪个进程占用了大量内存。此外,文档还可能涉及如何调整系统配置,如修改`swappiness`参数来控制系统何时将进程交换到磁盘,或者设置内存限制以避免单个...
4. 实现了SNMP相关信息的查看,包括网络接口、硬件信息、接口流量、系统信息、运行进程、TCP连接、进程占用资源情况、UDP连接、IP地址配置、ARP表、IP层流量、端口转发表、路由信息等。 5. 提供SNMP Trap接收和显示...
- 使用Thread Dump来分析线程的状态,识别出那些占用CPU较高的线程。 - 通过`top`或`vmstat`命令来监控系统的CPU使用率。 2. **连接池管理**: - 优化数据库连接池的配置,确保连接池的大小适合当前的应用负载。...
- CPU利用率:监控CPU使用情况,过高可能意味着资源紧张。 - 内存使用:检查内存使用情况,防止内存不足导致的问题。 3. Server Processes面板: - PGA Target/Used:显示PGA(程序全局区域)的目标和当前使用量...
要在Spotlight on Oracle中连接Oracle数据库,首先需要在本地机器上配置好Oracle客户端。具体连接步骤如下: 1. 打开Spotlight on Oracle应用程序。 2. 在“Connect to Oracle”对话框中输入Oracle服务器的相关信息...
2. **实时数据获取**:服务器端应定期收集和更新系统状态,如CPU使用率、内存占用、磁盘空间、网络流量等,并将这些信息发送给客户端。这可能需要用到Java的多线程技术,以及系统监控API,如Java Management ...
例如,使用`netstat`命令检查应用与外部服务的连接状态,可以发现潜在的数据库连接过多或资源占用异常等问题。 对于Java应用,内存问题是常见的性能瓶颈,因为处理器速度与内存速度差异导致了缓存一致性问题。...