仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 558|回复: 7
打印 上一主题 下一主题

[CentOS(社区)] 来一发CentOS下top下令引发体系负载降低

[复制链接]
金色的骷髅 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-14 20:15:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!体系情况:CentOS6.5x86_64


1、成绩体现
体系负载降低,某一个核的cpu资本被top历程耗尽,以下图所示:


2、剖析历程


<olclass="list-paddingleft-2"style="padding-right:0px;padding-left:20px;margin:0px;color:rgb(85,85,85);font-family:宋体,ArialNarrow,arial,serif;font-size:14px;line-height:28px;"><listyle="padding:0px;margin:0px0px0px20px;">经由过程strace下令打印top历程信息,呈现大批反复的体系挪用,以下:



检察top历程的fd信息以下:

经由过程以上信息揣度,top历程的输出输入非常,触发select前往文件形貌符,可是文件形貌符未处置或处置不妥形成select无穷触发,堕入逝世轮回,占用一个核的cpu资本。
<listyle="padding:0px;margin:0px0px0px20px;">下载procps-3.2.8检察top源码,在第3398行找到了相干挪用。如代码所示尺度输出被放到了select挪用里,由于尺度输出毛病招致触发select前往fd,无tv时长的守候。
<listyle="padding:0px;margin:0px0px0px20px;">
[size=1em][size=1em]longfile_flags;

[size=1em]intrc;
[size=1em]charc;
[size=1em]fd_setfs;
[size=1em]FD_ZERO(&fs);
[size=1em]FD_SET(STDIN_FILENO,&fs);
[size=1em]file_flags=fcntl(STDIN_FILENO,F_GETFL);
[size=1em]if(file_flags==-1)file_flags=0;
[size=1em]fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK|file_flags);
[size=1em]
[size=1em]//check1st,incasetvzeroed(bysighandler)beforeitgotset
[size=1em]rc=chin(0,&c,1);
[size=1em]if(rc<=0){
[size=1em]//EOFisprettymucha"canthappen"exceptforakernelbug.
[size=1em]//WeshouldquicklydieviaSIGHUP,andthusnotspinhere.
[size=1em]//if(rc==0)end_pgm(0);/*EOFfromterminal*/
[size=1em]fcntl(STDIN_FILENO,F_SETFL,file_flags);
[size=1em]select(1,&fs,NULL,NULL,&tv);
[size=1em]fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK|file_flags);
[size=1em]}
[size=1em]if(chin(0,&c,1)>0){
[size=1em]fcntl(STDIN_FILENO,F_SETFL,file_flags);
[size=1em]do_key((unsigned)c);
[size=1em]}else{
[size=1em]fcntl(STDIN_FILENO,F_SETFL,file_flags);
[size=1em]}



<listyle="padding:0px;margin:0px0px0px20px;">尺度输出的处置代码以下:
<listyle="padding:0px;margin:0px0px0px20px;"><divstyle="padding:0px;margin:0px;"><divclass="syntaxhighlightercpp"id="highlighter_426957"style="width:680px;padding:0px!important;margin:0.3em0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;bottom:auto!important;float:none!important;left:auto!important;line-height:1.1em!important;outline:0px!important;overflow-y:visible!important;overflow-x:auto!important;position:relative!important;right:auto!important;top:auto!important;vertical-align:baseline!important;box-sizing:content-box!important;font-family:Consolas,BitstreamVeraSansMono,CourierNew,Courier,monospace!important;font-size:1em!important;min-height:inherit!important;">
<divclass="container"style="padding:0px!important;margin:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;bottom:auto!important;float:none!important;left:auto!important;line-height:1.1em!important;outline:0px!important;overflow:visible!important;position:relative!important;right:auto!important;top:auto!important;vertical-align:baseline!important;width:auto!important;box-sizing:content-box!important;font-size:1em!important;min-height:inherit!important;"><divclass="linenumber1index0alt2"style="white-space:nowrap;padding:0px1em!important;margin:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;bottom:auto!important;float:none!important;left:auto!important;line-height:1.1em!important;outline:0px!important;overflow:visible!important;position:static!important;right:auto!important;top:auto!important;vertical-align:baseline!important;width:auto!important;box-sizing:content-box!important;font-size:1em!important;min-height:inherit!important;">static
乐观 该用户已被删除
沙发
发表于 2015-1-15 10:00:55 | 只看该作者

来一发CentOS下top下令引发体系负载降低

撸过
飘灵儿 该用户已被删除
板凳
发表于 2015-1-24 20:31:06 | 只看该作者
一定要学好命令,shell是命令语言,命令解释程序及程序设计语言的统称,shell也负责用户和操作系统之间的沟通。
admin 该用户已被删除
地板
发表于 2015-2-2 15:42:18 来自手机 | 只看该作者
查阅经典工具书和Howto,特别是Howto是全球数以万计的Linux、Unix的经验总结非常有参考价值通常40%的问题同样可以解决。
精灵巫婆 该用户已被删除
5#
发表于 2015-2-8 03:35:33 | 只看该作者
工具书对于学习者而言是相当重要的。一本错误观念的工具书却会让新手整个误入歧途。目前国内关于Linux的书籍有很多不过精品的不多。
再现理想 该用户已被删除
6#
发表于 2015-2-24 21:50:00 | 只看该作者
一定要养成在命令行下工作的习惯,要知道X-window只是运行在命令行模式下的一个应用程序。在命令行下学习虽然一开始进度较慢。
因胸联盟 该用户已被删除
7#
发表于 2015-3-7 16:59:27 | 只看该作者
学习Linux应具备的。[书籍+网络资源]
简单生活 该用户已被删除
8#
发表于 2015-3-15 17:23:52 | 只看该作者
安装一个新的软件时先看README,再看INSTALL然后看FAQ,最后才动手安装,这样遇到问题就知道为什么。如果Linux说明文档不看,结果出了问题再去论坛来找答案反而浪费时间。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-18 08:16

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表