﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-JAVA-文章分类-Linux/mysql调优</title><link>http://www.blogjava.net/zzzlyr/category/55323.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 10 Dec 2018 08:18:49 GMT</lastBuildDate><pubDate>Mon, 10 Dec 2018 08:18:49 GMT</pubDate><ttl>60</ttl><item><title>生产服务CPU100%问题快速定位</title><link>http://www.blogjava.net/zzzlyr/articles/433541.html</link><dc:creator>张钊钊</dc:creator><author>张钊钊</author><pubDate>Mon, 10 Dec 2018 07:59:00 GMT</pubDate><guid>http://www.blogjava.net/zzzlyr/articles/433541.html</guid><wfw:comment>http://www.blogjava.net/zzzlyr/comments/433541.html</wfw:comment><comments>http://www.blogjava.net/zzzlyr/articles/433541.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zzzlyr/comments/commentRss/433541.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zzzlyr/services/trackbacks/433541.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: tahoma, 宋体; font-size: 13px; text-align: justify; background-color: #fafafc;">或者按Shift+p</span>公司生产服务上常常出现 CPU 100% 问题，需要快速定位问题出现在那里，以下备注解决方法步骤：<br /><br /><div>1: 工具：top方法：</div><div>&#8226;<span style="white-space:pre">	</span>执行top -c ，显示进程运行信息列表</div><div>&#8226;<span style="white-space:pre">	</span>键入P (大写p)，进程按照CPU使用率排序&nbsp; （<span style="color: #333333; font-family: tahoma, 宋体; font-size: 13px; text-align: justify; background-color: #fafafc;">输入大写P，则结果按CPU占用降序排序。输入大写M，结果按内存占用降序排序。(注：大写P可以在capslock状态输入p，</span><span style="color: #333333; font-family: tahoma, 宋体; font-size: 13px; text-align: justify; background-color: #fafafc;">或者按Shift+p)<br /></span><img src="http://p99.pstatp.com/large/3224000379ba9d9d0956" alt="&#231;&#186;&#191;&#228;&#184;&#230;&#229;&#161;CPU100%&#233;&#151;&#174;&#233;&#162;&#229;&#191;&#171;&#233;&#229;&#174;&#228;&#189;&#229;&#174;&#230;" /><br />如上图找出最耗CPU 进程 10765<br /><span style="font-size: 13px; color: #333333; font-family: tahoma, 宋体; line-height: 22.4px; text-align: justify; background-color: #fafafc;"><strong>统计信息区</strong></span><p style="font-size: 13px; color: #333333; font-family: tahoma, 宋体; line-height: 22.4px; text-align: justify; background-color: #fafafc;">前五行是系统整体的统计信息。第一行是任务队列信息，同 uptime 命令的执行结果。其内容如下：</p><div style="font-size: 13px; word-wrap: break-word; font-family: tahoma, 宋体; line-height: 22.4px; text-align: justify; background-color: #fafafc;"><table cellspacing="1" border="0" style="color: #333333; border-style: solid; border-color: #90a080; margin: 10px; background-color: #90a080;"><tbody><tr><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">01:06:48</td><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">当前时间</td></tr><tr><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">up 1:22</td><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">系统运行时间，格式为时:分</td></tr><tr><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">1 user</td><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">当前登录用户数</td></tr><tr><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">load average: 0.06, 0.60, 0.48</td><td style="font-family: Verdana, Helvetica, Arial; font-size: 14px; word-wrap: break-word; line-height: 1.6; padding: 2px 5px; margin: 0px; background-color: #ffffff;">系统负载，即任务队列的平均长度。<br />三个数值分别为 1分钟、5分钟、15分钟前到现在的平均值。</td></tr></tbody></table><br /><font color="#333333">步骤二：找出最耗CPU的线程</font><br /><ol style="color: #333333;"><li>&nbsp; &nbsp;top -Hp 10765 显示一个进程的线程运行信息列表</li><li>键入shift +p 线程按照CPU使用率降序排序</li></ol><font color="#333333">&nbsp;步骤三： 把 10765 转化成16进制(因为堆栈是线程id是十六进制)</font><br /><font color="#333333">&nbsp; &nbsp; &nbsp;命令： printf '%x' 10765&nbsp; &nbsp;输出结果：2a0d</font><br /><br /><font color="#333333">步骤四： 使用JVM命令&nbsp; jstatck&nbsp;</font><br /><font color="#333333">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jstack 10765 | grep '2a0d' -C5 --color&nbsp; &nbsp; &nbsp;打印堆栈信息，通过id 过滤到线程的堆栈信息。</font><br /><br /><br /><font color="#333333">以下是top 其它常用命令：</font><br /><br /><p style="color: #000000; line-height: 1.5; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; text-align: start; background-color: #ffffff;">附常用操作:</p><div style="margin: 5px 0px; text-align: start; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: &quot;Courier New&quot; !important;">top   <span style="color: #008000; line-height: 1.5 !important;">//</span><span style="color: #008000; line-height: 1.5 !important;">每隔5秒显式所有进程的资源占用情况</span><span style="color: #008000; line-height: 1.5 !important;"><br /></span>top -d <span style="color: #800080; line-height: 1.5 !important;">2</span>  <span style="color: #008000; line-height: 1.5 !important;">//</span><span style="color: #008000; line-height: 1.5 !important;">每隔2秒显式所有进程的资源占用情况</span><span style="color: #008000; line-height: 1.5 !important;"><br /></span>top -c  <span style="color: #008000; line-height: 1.5 !important;">//</span><span style="color: #008000; line-height: 1.5 !important;">每隔5秒显式进程的资源占用情况，并显示进程的命令行参数(默认只有进程名)</span><span style="color: #008000; line-height: 1.5 !important;"><br /></span>top -p <font color="#800080">1111 </font>-p <span style="color: #800080; line-height: 1.5 !important;">6789</span><span style="color: #008000; line-height: 1.5 !important;">//</span><span style="color: #008000; line-height: 1.5 !important;">每隔5秒显示pid是1111和pid是6789的两个进程的资源占用情况</span><span style="color: #008000; line-height: 1.5 !important;"><br /></span>top -d <span style="color: #800080; line-height: 1.5 !important;">2</span> -c -p <font color="#800080">1111</font><span style="color: #008000; line-height: 1.5 !important;">//</span><span style="color: #008000; line-height: 1.5 !important;">每隔2秒显示pid是1111的进程的资源使用情况，并显式该进程启动的命令行参数</span><font color="#333333" style="font-family: tahoma, 宋体; font-size: 13px; text-align: justify;">&nbsp; &nbsp;</font><font color="#333333" style="font-family: tahoma, 宋体; font-size: 13px; text-align: justify;">&nbsp; &nbsp; &nbsp;</font></pre></div></div></div><img src ="http://www.blogjava.net/zzzlyr/aggbug/433541.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zzzlyr/" target="_blank">张钊钊</a> 2018-12-10 15:59 <a href="http://www.blogjava.net/zzzlyr/articles/433541.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>