﻿<?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-maxchen's blog-随笔分类-linux技术</title><link>http://www.blogjava.net/kelly859/category/51593.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 15 Apr 2014 09:11:51 GMT</lastBuildDate><pubDate>Tue, 15 Apr 2014 09:11:51 GMT</pubDate><ttl>60</ttl><item><title>Linux网卡中断使单个CPU过载</title><link>http://www.blogjava.net/kelly859/archive/2012/11/28/392137.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Wed, 28 Nov 2012 06:59:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/11/28/392137.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/392137.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/11/28/392137.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/392137.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/392137.html</trackback:ping><description><![CDATA[<p align="center" style="margin-top:3.6pt;margin-right:0cm; margin-bottom:7.2pt;margin-left:0cm;text-align:center;text-autospace:ideograph-other"><a name="技术项目 - Linux网卡中断使单个CPU过载"><strong><span style="font-size:12.0pt;font-family:宋体;">技术项目</span></strong></a><strong><span style="font-size:12.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> - Linux</span></strong><strong><span style="font-size:12.0pt;font-family:宋体;">网卡中断使单个</span></strong><strong><span style="font-size:12.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">CPU</span></strong><strong><span style="font-size:12.0pt;font-family:宋体;">过载</span></strong><strong></strong></p>  <p align="right" style="text-align:right;text-autospace:ideograph-other; word-break:break-all"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">By Steve Mushero</span></p>  <p align="right" style="text-align:right;text-autospace:ideograph-other">&nbsp;</p>  <p align="left"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Linux</span><span style="font-family:宋体;Times New Roman&quot;;">内核在性能方面已经经历了很长一段时间的考验，尤其是</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">2.6/3.x</span><span style="font-family: 宋体;Times New Roman&quot;;">内核。然而，在高</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">IO</span><span style="font-family:宋体;Times New Roman&quot;;">，尤其是网络方面的情况下，对中断的处理可能成为问题。我们已经</span> <span style="font-family:宋体;Times New Roman&quot;;">在拥有一个或多个饱和</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">1Gbps</span><span style="font-family:宋体;Times New Roman&quot;;">网卡的高性能系统上发现过这个问题，近来在有许多小包并发（大约</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">10000packets/second</span><span style="font-family:宋体;Times New Roman&quot;;">）超载的虚拟机上</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;">也发现了这个问题。</span></p>  <p align="left"><span style="font-family:宋体;Times New Roman&quot;;">原因很清楚：在最简单的模式中，内核通过硬件中断的方式来处理每个来自于网卡的包。但是随着</span> <span style="font-family:宋体;Times New Roman&quot;;">数据包速率的增长，带来的中断渐渐超过了单个</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;Times New Roman&quot;;">可处理的范围。单</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;Times New Roman&quot;;">概念很重要，系统管理员对此往往认识不足。在一个普通的</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">4-16</span><span style="font-family:宋体;Times New Roman&quot;;">核的系统中，因</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;">为整体</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family: 宋体;Times New Roman&quot;;">的使用率在</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">6-25%</span><span style="font-family:宋体;Times New Roman&quot;;">左右并且系统看上去很正常，所以一个过载的内核很难被发现，。但是系统将运行很慢，并且会在没有告警，没有</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">dmesg</span><span style="font-family:宋体;Times New Roman&quot;;">日</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;">志，没有明显征兆的情况下严重丢包。</span></p>  <p align="left"><span style="font-family:宋体;Times New Roman&quot;;">但是你使用</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">top</span><span style="font-family:宋体;Times New Roman&quot;;">查看多个</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;Times New Roman&quot;;">模式</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">(</span><span style="font-family:宋体;Times New Roman&quot;;">运行</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">top</span><span style="font-family:宋体;Times New Roman&quot;;">，接着键入</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">1)</span><span style="font-family:宋体;Times New Roman&quot;;">时，</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">%si </span><span style="font-family:宋体;Times New Roman&quot;;">列（系统中断）或者</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">mpstat</span><span style="font-family:宋体;Times New Roman&quot;;">命令中</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> irq</span><span style="font-family:宋体;Times New Roman&quot;;">列</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">(mpstat -P ALL 1)</span><span style="font-family:宋体;Times New Roman&quot;;">，在一些繁忙的系统中你会发现中断明显很高，通过经进一步</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">mpstat</span><span style="font-family:宋体;Times New Roman&quot;;">使用，你会看到哪个</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;Times New Roman&quot;;">或者哪个设备存在问题。</span></p>  <p align="left"><span style="font-family:宋体;Times New Roman&quot;;">你需要一个较新版本的</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">mpstat</span><span style="font-family:宋体;Times New Roman&quot;;">，可以运行</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">-I </span><span style="font-family:宋体;Times New Roman&quot;;">模式，用以列出</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">irq</span><span style="font-family:宋体;Times New Roman&quot;;">负载，运行如下命令：</span></p>  <p align="left"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">mpstat -I SUM -P ALL 1</span></p>  <p align="left"><span style="font-family:宋体;Times New Roman&quot;;">超过</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">5000/</span><span style="font-family:宋体;Times New Roman&quot;;">秒</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> </span><span style="font-family:宋体;Times New Roman&quot;;">有点繁忙，</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> 1</span><span style="font-family: 宋体;Times New Roman&quot;;">万</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">-2</span><span style="font-family:宋体;Times New Roman&quot;;">万</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">/</span><span style="font-family:宋体;Times New Roman&quot;;">秒相当高了。</span></p>  <p align="left"><span style="font-family:宋体;Times New Roman&quot;;">运行如下命令来确认那个设备</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">/</span><span style="font-family:宋体;Times New Roman&quot;;">项目导致负载：</span></p>  <p align="left"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">mpstat -I CPU -P ALL 1</span></p>  <p align="left"><span style="font-family:宋体;Times New Roman&quot;;">这个输出很难被阅读，但是你可以跟踪正确的列用来确认哪个中断导致负载，例如：</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">15</span><span style="font-family:宋体;Times New Roman&quot;;">，</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">19</span><span style="font-family:宋体;Times New Roman&quot;;">，</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">995. </span><span style="font-family:宋体;Times New Roman&quot;;">你也可以定义你想查看的</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span></p>  <p align="left"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">mpstat -I CPU -P 3 1 # 3 </span><span style="font-family:宋体;Times New Roman&quot;;">在</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">top,htop</span><span style="font-family:宋体;Times New Roman&quot;;">中可以定位不同的</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;Times New Roman&quot;;">。（</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">top</span><span style="font-family:宋体;Times New Roman&quot;;">和</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">mpstat</span><span style="font-family:宋体;Times New Roman&quot;;">都是从</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">0</span><span style="font-family:宋体;Times New Roman&quot;;">开始，</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">htop</span><span style="font-family:宋体;Times New Roman&quot;;">是从</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">1</span><span style="font-family:宋体;Times New Roman&quot;;">开始计数）</span></p>  <p align="left"><span style="font-family:宋体;Times New Roman&quot;;">记录下中断数，你就可以查看中断表</span> <span style="font-family:宋体;">，</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">"cat /proc/interrupts" </span><span style="font-family:宋体;">找到</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">mpstat's</span><span style="font-family:宋体;">得到的数字，你可以发现是哪个设备在使用中断。这个文件也指示了使用该中断的</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">#</span><span style="font-family:宋体;">可以告诉你是什么导致过载。</span></p>  <p align="left"><span style="font-family:宋体;">需要做什么呢？</span></p>  <p align="left"><span style="font-family:宋体;">首先，确认你是否运行</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">irqbalance</span><span style="font-family:宋体;">，这个是</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">nice</span><span style="font-family:宋体;">守护进程它会自动在</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;">间扩展中断。在繁忙的系统中很重要，尤其是两块网卡，因为默认</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">cpu0 </span><span style="font-family:宋体;">将处理所有中断，系统很容易过载。</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">irqbalance</span><span style="font-family:宋体;">扩散这些中断用以降低负载。为了性能最大化，你可以手动平衡这些中断将套接字和超线程共享内核分</span> <span style="font-family:宋体;">散，但是通常没必要这么麻烦。</span></p>  <p align="left"><span style="font-family:宋体;">但是即使扩展了中断，某块网卡还是可能导致某一个</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family: 宋体;">过载。这取决于你的网卡和驱动，但通常有两种有效的方法来防止这样的事情发生。</span></p>  <p align="left"><span style="font-family:宋体;">第一种是多网卡队列，有些</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Intel</span><span style="font-family: 宋体;">网卡就可以这么做。如果他们有</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">4</span><span style="font-family:宋体;">个队列，就可以有四个</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;">内核同时处理不同的中断用以分散负载。通常驱动会自动这么做，你也可以通过</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">mpstat</span><span style="font-family:宋体;">命令来确认。</span></p>  <p align="left"><span style="font-family:宋体;">第二种，并且通常也是更加重要的，网卡驱动选项</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">&#8212;&#8212;'IRQ coalescing'</span><span style="font-family:宋体;">，中断请求合并。这个选项有着强大的功能，允许网卡在调用中断请求前缓存数个数据包，从而为系统节约大量的时间和负载。举个例子：</span> <span style="font-family:宋体;">如果网卡缓存</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">10</span><span style="font-family:宋体;">个包，那么</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;">负载将大约降低</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">90%</span><span style="font-family:宋体;">。这个功能通常用</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">ethtool</span><span style="font-family:宋体;">工具来控制，使用</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">'-c/-C'</span><span style="font-family:宋体;">参数，但是有些驱动要求在驱动初次</span> <span style="font-family:宋体;">加载时就做好相关设置。如何设置需要查看本机文档。举个例子，有些网卡，譬如我们使用的</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Intel</span><span style="font-family:宋体;">网卡，就有</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">automatic</span><span style="font-family:宋体;">模式可以根据负载自动做到</span> <span style="font-family:宋体;">最优化。</span></p>  <p align="left"><span style="position: absolute;z-index:-2;margin-left:333px;margin-top:1007px;width:423px;height: 108px"><img width="423" height="108" src="file:///C:/DOCUME~1/chenyibo/LOCALS~1/Temp/msohtmlclip1/01/clip_image002.gif" alt="NC Logo EN Blue S_20111104" v:shapes="Picture_x0020_11" /></span><span style="font-family:宋体;">最后，就像我们在虚拟机中看到的一些驱动，它们不支持多队列或者中断请求合并。这种情况下，一旦处理中断的</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">cpu</span><span style="font-family:宋体;">繁忙，就会产生性能瓶颈，除非你更换设备或者驱动。</span></p>  <p align="left"><span style="font-family:宋体;">这是一个复杂的区域，并不广为人知，但有些不错的技术真的可以提高繁忙系统的性能。此外，一些额外的针对性监控，可以帮助到查找和诊断这些难以发现的问题。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">本文由</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> Steve Mushero, </span><span style="font-family:宋体;">联合创始人兼首席执行官发表于</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">2012</span><span style="font-family:宋体;">年</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">4</span><span style="font-family:宋体;">月</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">25</span><span style="font-family:宋体;">日</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">作者简介：</span></p>  <h3><span style="font-size:10.5pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;">Steve Mushero</span></h3>  <h3><span style="font-size:10.5pt;font-weight:normal">云络创始人，首席技术官</span></h3>  <p align="left"><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Steve Mushero</span><span style="font-family:宋体;">先生拥有超过</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">20</span><span style="font-family:宋体;">年在各行业的，国际性的技术管理经验。他曾经担任土豆网的首席技术官，负责</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Intermind</span><span style="font-family:宋体;">的高级管理系统，在</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Beyond Access Communications </span><span style="font-family: 宋体;">和</span><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;"> AirReview</span><span style=" font-family:宋体;">担任首席架构师。他是</span><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Managing White-Collar Job Migration to Asia</span><span style="font-family:宋体;">一书的作者，多项专利的发明者。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">云络网络科技（上海）有限公司持有最终解释权</span> </p>  <p>&nbsp;</p>  <p align="left">转自http://wenku.baidu.com/view/38a764b8f121dd36a32d828e.html</p>  <p><span style="position: absolute;z-index:-1;left:0px;margin-left:336px;margin-top:1011px;width:423px; height:108px"><img width="423" height="108" src="file:///C:/DOCUME~1/chenyibo/LOCALS~1/Temp/msohtmlclip1/01/clip_image002.gif" alt="NC Logo EN Blue S_20111104" v:shapes="_x0000_s1027" /></span></p><img src ="http://www.blogjava.net/kelly859/aggbug/392137.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-11-28 14:59 <a href="http://www.blogjava.net/kelly859/archive/2012/11/28/392137.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux iostat监测IO状态</title><link>http://www.blogjava.net/kelly859/archive/2012/05/01/377093.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 30 Apr 2012 17:41:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/05/01/377093.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/377093.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/05/01/377093.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/377093.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/377093.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">Linux系统出现了性能问题，一般我们可以通过top、iostat、free、vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">1. 基本使用</p><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-family: Fixedsys, 'Courier New', Courier, monospace; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #222222; border-left-width: 6px; border-left-style: solid; border-left-color: #1664d9; color: #00cc00; font-size: 1em; line-height: normal; overflow-x: scroll; overflow-y: scroll; width: 582px; ">$iostat -d -k 1 10</div> </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">参数 -d 表示，显示设备（磁盘）使用状态；-k某些使用block为单位的列强制使用Kilobytes为单位；1 10表示，数据显示每隔1秒刷新一次，共显示10次。</p><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-family: Fixedsys, 'Courier New', Courier, monospace; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #222222; border-left-width: 6px; border-left-style: solid; border-left-color: #1664d9; color: #00cc00; font-size: 1em; line-height: normal; overflow-x: scroll; overflow-y: scroll; width: 582px; ">$iostat -d -k 1 10 Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn sda              39.29        21.14         1.44  441339807   29990031 sda1              0.00         0.00         0.00       1623        523 sda2              1.32         1.43         4.54   29834273   94827104 sda3              6.30         0.85        24.95   17816289  520725244 sda5              0.85         0.46         3.40    9543503   70970116 sda6              0.00         0.00         0.00        550        236 sda7              0.00         0.00         0.00        406          0 sda8              0.00         0.00         0.00        406          0 sda9              0.00         0.00         0.00        406          0 sda10            60.68        18.35        71.43  383002263 1490928140  Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn sda             327.55      5159.18       102.04       5056        100 sda1              0.00         0.00         0.00          0          0 </div> </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">tps：该设备每秒的传输次数（Indicate the number of transfers per second that were issued to the device.）。&#8220;一次传输&#8221;意思是&#8220;一次I/O请求&#8221;。多个逻辑请求可能会被合并为&#8220;一次I/O请求&#8221;。&#8220;一次传输&#8221;请求的大小是未知的。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">kB_read/s：每秒从设备（drive expressed）读取的数据量；kB_wrtn/s：每秒向设备（drive expressed）写入的数据量；kB_read：读取的总数据量；kB_wrtn：写入的总数量数据量；这些单位都为Kilobytes。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">上面的例子中，我们可以看到磁盘sda以及它的各个分区的统计数据，当时统计的磁盘总TPS是39.29，下面是各个分区的TPS。（因为是瞬间值，所以总TPS并不严格等于各个分区TPS的总和）</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">2. -x 参数</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">使用-x参数我们可以获得更多统计信息。</p><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-family: Fixedsys, 'Courier New', Courier, monospace; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #222222; border-left-width: 6px; border-left-style: solid; border-left-color: #1664d9; color: #00cc00; font-size: 1em; line-height: normal; overflow-x: scroll; overflow-y: scroll; width: 582px; ">iostat -d -x -k 1 10 Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util sda          1.56  28.31  7.80 31.49   42.51    2.92    21.26     1.46     1.16     0.03    0.79   2.62  10.28 Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util sda          2.00  20.00 381.00  7.00 12320.00  216.00  6160.00   108.00    32.31     1.75    4.50   2.17  84.20 </div> </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">rrqm/s：每秒这个设备相关的读取请求有多少被Merge了（当系统调用需要读取数据的时候，VFS将请求发到各个FS，如果FS发现不同的读取请求读取的是相同Block的数据，FS会将这个请求合并Merge）；wrqm/s：每秒这个设备相关的写入请求有多少被Merge了。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">rsec/s：每秒读取的扇区数；wsec/：每秒写入的扇区数。r/s：The number of read requests that were issued to the device per second；w/s：The number of write requests that were issued to the device per second；</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">await：每一个IO请求的处理的平均时间（单位是微秒毫秒）。这里可以理解为IO的响应时间，一般地系统IO响应时间应该低于5ms，如果大于10ms就比较大了。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">%util：在统计时间内所有处理IO时间，除以总共统计时间。例如，如果统计间隔1秒，该设备有0.8秒在处理IO，而0.2秒闲置，那么该设备的%util = 0.8/1 = 80%，所以该参数暗示了设备的繁忙程度。一般地，如果该参数是100%表示设备已经接近满负荷运行了（当然如果是多磁盘，即使%util是100%，因为磁盘的并发能力，所以磁盘使用未必就到了瓶颈）。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">3. -c 参数</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">iostat还可以用来获取cpu部分状态值：</p><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-family: Fixedsys, 'Courier New', Courier, monospace; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #222222; border-left-width: 6px; border-left-style: solid; border-left-color: #1664d9; color: #00cc00; font-size: 1em; line-height: normal; overflow-x: scroll; overflow-y: scroll; width: 582px; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; ">iostat -c 1 10</strong> avg-cpu:  %user   %nice    %sys %iowait   %idle            1.98    0.00    0.35   11.45   86.22 avg-cpu:  %user   %nice    %sys %iowait   %idle            1.62    0.00    0.25   34.46   63.67</div> </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">4. 常见用法</p><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-family: Fixedsys, 'Courier New', Courier, monospace; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #222222; border-left-width: 6px; border-left-style: solid; border-left-color: #1664d9; color: #00cc00; font-size: 1em; line-height: normal; overflow-x: scroll; overflow-y: scroll; width: 582px; ">$iostat -d -k 1 10        #查看TPS和吞吐量信息 iostat -d -x -k 1 10      #查看设备使用率（%util）、响应时间（await） iostat -c 1 10            #查看cpu状态 </div> </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">5. 实例分析</p><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-family: Fixedsys, 'Courier New', Courier, monospace; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #222222; border-left-width: 6px; border-left-style: solid; border-left-color: #1664d9; color: #00cc00; font-size: 1em; line-height: normal; overflow-x: scroll; overflow-y: scroll; width: 582px; ">$$iostat -d -k 1 |grep sda10 Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn sda10            60.72        18.95        71.53  395637647 1493241908 sda10           299.02      4266.67       129.41       4352        132 sda10           483.84      4589.90      4117.17       4544       4076 sda10           218.00      3360.00       100.00       3360        100 sda10           546.00      8784.00       124.00       8784        124 sda10           827.00     13232.00       136.00      13232        136</div> </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">上面看到，磁盘每秒传输次数平均约400；每秒磁盘读取约5MB，写入约1MB。</p><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; font-family: Fixedsys, 'Courier New', Courier, monospace; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #222222; border-left-width: 6px; border-left-style: solid; border-left-color: #1664d9; color: #00cc00; font-size: 1em; line-height: normal; overflow-x: scroll; overflow-y: scroll; width: 582px; ">iostat -d -x -k 1 Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util sda          1.56  28.31  7.84 31.50   43.65    3.16    21.82     1.58     1.19     0.03    0.80   2.61  10.29 sda          1.98  24.75 419.80  6.93 13465.35  253.47  6732.67   126.73    32.15     2.00    4.70   2.00  85.25 sda          3.06  41.84 444.90 54.08 14204.08 2048.98  7102.04  1024.49    32.57     2.10    4.21   1.85  92.24</div> </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">可以看到磁盘的平均响应时间&lt;5ms，磁盘使用率&gt;80。磁盘响应正常，但是已经很繁忙了。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 12px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; text-indent: 28px; text-align: justify; color: #333333; line-height: 22px; background-color: #ffffff; ">参考文献：</p><ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 55px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; color: #333333; line-height: 22px; background-color: #ffffff; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Linux man iostat</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><a href="http://www.xaprb.com/blog/2010/01/09/how-linux-iostat-computes-its-results/" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0054b3; outline-style: none; outline-width: initial; outline-color: initial; ">How Linux iostat computes its results</a></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><a href="http://www.mjmwired.net/kernel/Documentation/iostats.txt" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0054b3; outline-style: none; outline-width: initial; outline-color: initial; ">Linux iostat<br /></a><br />原文地址：<a href="http://www.orczhou.com/index.php/2010/03/iostat-detail/">http://www.orczhou.com/index.php/2010/03/iostat-detail/</a></li></ol><img src ="http://www.blogjava.net/kelly859/aggbug/377093.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-05-01 01:41 <a href="http://www.blogjava.net/kelly859/archive/2012/05/01/377093.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux下根据/proc/stat计算CPU使用情况算法详解</title><link>http://www.blogjava.net/kelly859/archive/2012/05/01/377092.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 30 Apr 2012 16:39:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/05/01/377092.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/377092.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/05/01/377092.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/377092.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/377092.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 本文是介绍在Linux/unix下如何根据/proc/stat文件的信息计算得到CPU使用率。大多情况下自己做系统监控时都会用到这个文件首先找来一段扫盲文字&#8220;在linux下，CPU利用率分为用户态，系统态和空闲态，分别表示CPU处于用户态执行的时间，系统内核执行的时间，和空闲系统进程执行的时间。平时所说的CPU利用率是指：CPU执行非系统空闲进程的时间 / CPU总的执行时间。在内核中...&nbsp;&nbsp;<a href='http://www.blogjava.net/kelly859/archive/2012/05/01/377092.html'>阅读全文</a><img src ="http://www.blogjava.net/kelly859/aggbug/377092.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-05-01 00:39 <a href="http://www.blogjava.net/kelly859/archive/2012/05/01/377092.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Vmstat命令详解</title><link>http://www.blogjava.net/kelly859/archive/2012/05/01/377091.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 30 Apr 2012 16:25:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/05/01/377091.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/377091.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/05/01/377091.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/377091.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/377091.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Procs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r列表示运行和等待cpu时间片的进程数，这个值如果长期大于系统CPU的个数，说明CPU不足，需要增加CPU。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b列表示在等待资源的进程数，比如正在等待I/O、或者内存交换等。...&nbsp;&nbsp;<a href='http://www.blogjava.net/kelly859/archive/2012/05/01/377091.html'>阅读全文</a><img src ="http://www.blogjava.net/kelly859/aggbug/377091.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-05-01 00:25 <a href="http://www.blogjava.net/kelly859/archive/2012/05/01/377091.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>理解Load Average做好压力测试</title><link>http://www.blogjava.net/kelly859/archive/2012/04/30/377090.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 30 Apr 2012 15:25:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/04/30/377090.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/377090.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/04/30/377090.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/377090.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/377090.html</trackback:ping><description><![CDATA[<p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><br />SIP<span style="line-height: 15px; font-family: 宋体; ">的第四期结束了，因为控制策略的丰富，早先的的压力测试结果已经无法反映在高并发和高压力下</span>SIP<span style="line-height: 15px; font-family: 宋体; ">的运行状况，因此需要重新作压力测试。跟在测试人员后面做了快一周的压力测试，压力测试的报告也正式出炉，本来也就算是告一段落，但第二天测试人员说要修改报告，由于这次作压力测试的同学是第一次作，有一个指标没有注意，因此需要修改几个测试结果。那个没有注意的指标就是</span>load average<span style="line-height: 15px; font-family: 宋体; ">，他和我一样开始只是注意了</span>CPU<span style="line-height: 15px; font-family: 宋体; ">，内存的使用状况，而没有太注意这个指标，这个指标与他们通常的限制（</span>10<span style="line-height: 15px; font-family: 宋体; ">左右）有差别。重新测试的结果由于这个指标被要求压低，最后的报告显然不如原来的好看。自己也没有深入过压力测试，但是觉得不搞明白对将来机器配置和扩容都会有影响，因此去问了</span>DBA<span style="line-height: 15px; font-family: 宋体; ">和</span>SA<span style="line-height: 15px; font-family: 宋体; ">，得到的结果相差很大，看来不得不自己去找找问题的根本所在了。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">通过下面的几个部分的了解，可以一步一步的找出</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">在压力测试中真正的作用。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><strong><span style="font-size: 12pt; ">CPU</span></strong><strong><span style="font-size: 12pt; font-family: 宋体; ">时间片</span></strong></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">为了提高程序执行效率，大家在很多应用中都采用了多线程模式，这样可以将原来的序列化执行变为并行执行，任务的分解以及并行执行能够极大地提高程序的运行效率。但这都是代码级别的表现，而硬件是如何支持的呢？那就要靠</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的时间片模式来说明这一切。程序的任何指令的执行往往都会要竞争</span>CPU<span style="line-height: 15px; font-family: 宋体; ">这个最宝贵的资源，不论你的程序分成了多少个线程去执行不同的任务，他们都必须排队等待获取这个资源来计算和处理命令。先看看单</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的情况。下面两图描述了时间片模式和非时间片模式下的线程执行的情况：<br /></span></p><p align="center" style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; text-align: center; "><span style="line-height: 14px; font-size: 9pt; font-family: 宋体; "><img height="389" alt="" src="http://www.blogjava.net/images/blogjava_net/cenwenchu/CPU1.GIF" width="505" border="0" /><br />图</span><span style="line-height: 14px; font-size: 9pt; ">&nbsp;1&nbsp;</span><span style="line-height: 14px; font-size: 9pt; font-family: 宋体; ">非时间片线程执行情况<br /></span></p><p align="center" style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; text-align: center; "><span style="line-height: 14px; font-size: 9pt; font-family: 宋体; "><img height="402" alt="" src="http://www.blogjava.net/images/blogjava_net/cenwenchu/CPU2.GIF" width="487" border="0" /><br />图</span><span style="line-height: 14px; font-size: 9pt; ">&nbsp;2&nbsp;</span><span style="line-height: 14px; font-size: 9pt; font-family: 宋体; ">非时间片线程执行情况</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">在图一中可以看到，任何线程如果都排队等待</span>CPU<span style="line-height: 15px; font-family: 宋体; ">资源的获取，那么所谓的多线程就没有任何实际意义。图二中的</span>CPU Manager<span style="line-height: 15px; font-family: 宋体; ">只是我虚拟的一个角色，由它来分配和管理</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的使用状况，此时多线程将会在运行过程中都有机会得到</span>CPU<span style="line-height: 15px; font-family: 宋体; ">资源，也真正实现了在单</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的情况下实现多线程并行处理。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">多</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的情况只是单</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的扩展，当所有的</span>CPU<span style="line-height: 15px; font-family: 宋体; ">都满负荷运作的时候，就会对每一个</span>CPU<span style="line-height: 15px; font-family: 宋体; ">采用时间片的方式来提高效率。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">在</span>Linux<span style="line-height: 15px; font-family: 宋体; ">的内核处理过程中，每一个进程默认会有一个固定的时间片来执行命令（默认为</span>1/100<span style="line-height: 15px; font-family: 宋体; ">秒），这段时间内进程被分配到</span>CPU<span style="line-height: 15px; font-family: 宋体; ">，然后独占使用。如果使用完，同时未到时间片的规定时间，那么就主动放弃</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的占用，如果到时间片尚未完成工作，那么</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的使用权也会被收回，进程将会被中断挂起等待下一个时间片。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><strong><span style="font-size: 12pt; ">CPU</span></strong><strong><span style="font-size: 12pt; font-family: 宋体; ">利用率和</span></strong><strong><span style="font-size: 12pt; ">Load Average</span></strong><strong><span style="font-size: 12pt; font-family: 宋体; ">的区别</span></strong></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">压力测试不仅需要对业务场景的并发用户等压力参数作模拟，同时也需要在压力测试过程中随时关注机器的性能情况，来确保压力测试的有效性。当服务器长期处于一种超负荷的情况下运行，所能接收的压力并不是我们所认为的可接受的压力。就好比项目经理在给一个人估工作量的时候，每天都让这个人工作</span>12<span style="line-height: 15px; font-family: 宋体; ">个小时，那么所制定的项目计划就不是一个合理的计划，那个人迟早会垮掉，而影响整体的项目进度。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">CPU<span style="line-height: 15px; font-family: 宋体; ">利用率在过去常常被我们这些外行认为是判断机器是否已经到了满负荷的一个标准，看到</span>50%-60%<span style="line-height: 15px; font-family: 宋体; ">的使用率就认为机器就已经压到了临界了。</span>CPU<span style="line-height: 15px; font-family: 宋体; ">利用率，顾名思义就是对于</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的使用状况，这是对一个时间段内</span>CPU<span style="line-height: 15px; font-family: 宋体; ">使用状况的统计，通过这个指标可以看出在某一个时间段内</span>CPU<span style="line-height: 15px; font-family: 宋体; ">被占用的情况，如果被占用时间很高，那么就需要考虑</span>CPU<span style="line-height: 15px; font-family: 宋体; ">是否已经处于超负荷运作，长期超负荷运作对于机器本身来说是一种损害，因此必须将</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的利用率控制在一定的比例下，以保证机器的正常运作。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">Load Average<span style="line-height: 15px; font-family: 宋体; ">是</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的</span>Load<span style="line-height: 15px; font-family: 宋体; ">，它所包含的信息不是</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的使用率状况，而是在一段时间内</span>CPU<span style="line-height: 15px; font-family: 宋体; ">正在处理以及等待</span>CPU<span style="line-height: 15px; font-family: 宋体; ">处理的进程数之和的统计信息，也就是</span>CPU<span style="line-height: 15px; font-family: 宋体; ">使用队列的长度的统计信息。为什么要统计这个信息，这个信息的对于压力测试的影响究竟是怎么样的，那就通过一个类比来解释</span>CPU<span style="line-height: 15px; font-family: 宋体; ">利用率和</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">的区别以及对于压力测试的指导意义。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">我们将</span>CPU<span style="line-height: 15px; font-family: 宋体; ">就类比为电话亭，每一个进程都是一个需要打电话的人。现在一共有</span>4<span style="line-height: 15px; font-family: 宋体; ">个电话亭（就好比我们的机器有</span>4<span style="line-height: 15px; font-family: 宋体; ">核），有</span>10<span style="line-height: 15px; font-family: 宋体; ">个人需要打电话。现在使用电话的规则是管理员会按照顺序给每一个人轮流分配</span>1<span style="line-height: 15px; font-family: 宋体; ">分钟的使用电话时间，如果使用者在</span>1<span style="line-height: 15px; font-family: 宋体; ">分钟内使用完毕，那么可以立刻将电话使用权返还给管理员，如果到了</span>1<span style="line-height: 15px; font-family: 宋体; ">分钟电话使用者还没有使用完毕，那么需要重新排队，等待再次分配使用。</span></p><p align="center" style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; text-align: center; "><span style="line-height: 14px; font-size: 9pt; font-family: 宋体; "><img height="489" alt="" src="http://www.blogjava.net/images/blogjava_net/cenwenchu/CPU3.GIF" width="653" border="0" /><br />图</span><span style="line-height: 14px; font-size: 9pt; ">&nbsp;3&nbsp;</span><span style="line-height: 14px; font-size: 9pt; font-family: 宋体; ">电话使用场景</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">上图中对于使用电话的用户又作了一次分类，</span>1min<span style="line-height: 15px; font-family: 宋体; ">的代表这些使用者占用电话时间小于等于</span>1min<span style="line-height: 15px; font-family: 宋体; ">，</span>2min<span style="line-height: 15px; font-family: 宋体; ">表示使用者占用电话时间小于等于</span>2min<span style="line-height: 15px; font-family: 宋体; ">，以此类推。根据电话使用规则，</span>1min<span style="line-height: 15px; font-family: 宋体; ">的用户只需要得到一次分配即可完成通话，而其他两类用户需要排队两次到三次。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="line-height: 15px; font-family: 宋体; ">电话的利用率</span>&nbsp;=&nbsp;sum (active use cpu time)/period</p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">每一个分配到电话的使用者使用电话时间的总和去除以统计的时间段。这里需要注意的是是使用电话的时间总和</span>(sum(active use cpu time))<span style="line-height: 15px; font-family: 宋体; ">，这与占用时间的总和</span>(sum(occupy cpu time))<span style="line-height: 15px; font-family: 宋体; ">是有区别的。（例如一个用户得到了一分钟的使用权，在</span>10<span style="line-height: 15px; font-family: 宋体; ">秒钟内打了电话，然后去查询号码本花了</span>20<span style="line-height: 15px; font-family: 宋体; ">秒钟，再用剩下的</span>30<span style="line-height: 15px; font-family: 宋体; ">秒打了另一个电话，那么占用了电话</span>1<span style="line-height: 15px; font-family: 宋体; ">分钟，实际只是使用了</span>40<span style="line-height: 15px; font-family: 宋体; ">秒）</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">电话的</span>Average Load<span style="line-height: 15px; font-family: 宋体; ">体现的是在某一统计时间段内，所有使用电话的人加上等待电话分配的人一个平均统计。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">电话利用率的统计能够反映的是电话被使用的情况，当电话长期处于被使用而没有的到足够的时间休息间歇，那么对于电话硬件来说是一种超负荷的运作，需要调整使用频度。而电话</span>Average Load<span style="line-height: 15px; font-family: 宋体; ">却从另一个角度来展现对于电话使用状态的描述，</span>Average Load<span style="line-height: 15px; font-family: 宋体; ">越高说明对于电话资源的竞争越激烈，电话资源比较短缺。对于资源的申请和维护其实也是需要很大的成本，所以在这种高</span>Average Load<span style="line-height: 15px; font-family: 宋体; ">的情况下电话资源的长期&#8220;热竞争&#8221;也是对于硬件的一种损害。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">低利用率的情况下是否会有高</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">的情况产生呢？理解占有时间和使用时间就可以知道，当分配时间片以后，是否使用完全取决于使用者，因此完全可能出现低利用率高</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">的情况。由此来看，仅仅从</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的使用率来判断</span>CPU<span style="line-height: 15px; font-family: 宋体; ">是否处于一种超负荷的工作状态还是不够的，必须结合</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">来全局的看</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的使用情况和申请情况。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">所以回过头来再看测试部对于</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">的要求，在我们机器为</span>8<span style="line-height: 15px; font-family: 宋体; ">个</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的情况下，控制在</span>10 Load<span style="line-height: 15px; font-family: 宋体; ">左右，也就是每一个</span>CPU<span style="line-height: 15px; font-family: 宋体; ">正在处理一个请求，同时还有</span>2<span style="line-height: 15px; font-family: 宋体; ">个在等待处理。看了看网上很多人的介绍一般来说</span>Load<span style="line-height: 15px; font-family: 宋体; ">简单的计算就是</span>2* CPU<span style="line-height: 15px; font-family: 宋体; ">个数减去</span>1-2<span style="line-height: 15px; font-family: 宋体; ">左右（这个只是网上看来的，未必是一个标准）。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><strong><span style="font-size: 12pt; font-family: 宋体; ">补充几点：</span></strong></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">1<span style="line-height: 15px; font-family: 宋体; ">．对于</span>CPU<span style="line-height: 15px; font-family: 宋体; ">利用率和</span>CPU Load Average<span style="line-height: 15px; font-family: 宋体; ">的结果来判断性能问题。首先低</span>CPU<span style="line-height: 15px; font-family: 宋体; ">利用率不表明</span>CPU<span style="line-height: 15px; font-family: 宋体; ">不是瓶颈，竞争</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的队列长期保持较长也是</span>CPU<span style="line-height: 15px; font-family: 宋体; ">超负荷的一种表现。对于应用来说可能会去花时间在</span>I/O,Socket<span style="line-height: 15px; font-family: 宋体; ">等方面，那么可以考虑是否后这些硬件的速度影响了整体的效率。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">这里最好的样板范例就是我在测试中发现的一个现象：</span>SIP<span style="line-height: 15px; font-family: 宋体; ">当前在处理过程中，为了提高处理效率，将控制策略以及计数信息都放置在</span>Memcached Cache<span style="line-height: 15px; font-family: 宋体; ">里面，当我将</span>Memcached Cache<span style="line-height: 15px; font-family: 宋体; ">配置扩容一倍以后，</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的利用率以及</span>Load<span style="line-height: 15px; font-family: 宋体; ">都有所下降，其实也就是在处理任务的过程中，等待</span>Socket<span style="line-height: 15px; font-family: 宋体; ">的返回对于</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的竞争也产生了影响。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 21pt; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; ">2<span style="line-height: 15px; font-family: 宋体; ">．未来多</span>CPU<span style="line-height: 15px; font-family: 宋体; ">编程的重要性。现在服务器的</span>CPU<span style="line-height: 15px; font-family: 宋体; ">都是多</span>CPU<span style="line-height: 15px; font-family: 宋体; ">了，我们的服务器处理能力已经不再按照摩尔定律来发展。就我上面提到的电话亭场景来看，对于三种不同时间需求的用户来说，采用不同的分配顺序，我们可看到的</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">就会有不同。假设我们统计</span>Load<span style="line-height: 15px; font-family: 宋体; ">的时间段为</span>2<span style="line-height: 15px; font-family: 宋体; ">分钟，如果将电话分配的顺序按照：</span>1min<span style="line-height: 15px; font-family: 宋体; ">的用户，</span>2min<span style="line-height: 15px; font-family: 宋体; ">的用户，</span>3min<span style="line-height: 15px; font-family: 宋体; ">的用户来分配，那么我们的</span>Load Average<span style="line-height: 15px; font-family: 宋体; ">将会最低，采用其他顺序将会有不同的结果。所以未来的多</span>CPU<span style="line-height: 15px; font-family: 宋体; ">编程可以更好的提高</span>CPU<span style="line-height: 15px; font-family: 宋体; ">的利用率，让程序跑的更快。</span></p><p style="font-size: 13px; line-height: 19px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 20px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><span style="line-height: 15px; font-family: 宋体; ">以上所提到的内容未必都是很准确或者正确，如果有任何的偏差也请大家指出，可以纠正一些不清楚的概念。<br /><br /><br /></span><span style="color: #ff0000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; text-indent: 0px; ">原文转至文初的blogjava：</span><a href="http://www.blogjava.net/cenwenchu/archive/2008/06/30/211712.html" target="_blank" style="color: black; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; text-indent: 0px; ">http://www.blogjava.net/cenwenchu/archive/2008/06/30/211712.html</a><span style="color: #ff0000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; text-indent: 0px; ">&nbsp;</span></p><img src ="http://www.blogjava.net/kelly859/aggbug/377090.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-04-30 23:25 <a href="http://www.blogjava.net/kelly859/archive/2012/04/30/377090.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux Load average负载详细解释</title><link>http://www.blogjava.net/kelly859/archive/2012/04/30/377089.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 30 Apr 2012 15:18:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/04/30/377089.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/377089.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/04/30/377089.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/377089.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/377089.html</trackback:ping><description><![CDATA[<span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">更有说服力的文章：</span><a target="_blank" href="http://dongyajun.iteye.com/blog/645553" style="color: #006699; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">http://dongyajun.iteye.com/blog/645553</a>&nbsp;<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">我们知道判断一个系统的负载可以使用top，uptime等命令去查看，它分别记录了一分钟、五分钟、以及十五分钟的系统平均负载。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　你可能对于 Linux 的负载均值(load averages)已有了充分的了解。负载均值在 uptime 或者 top 命令中可以看到，它们可能会显示成这个样子：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　</span><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Shell代码&nbsp;<embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=load%20average%3A%200.09%2C%200.05%2C%200.01" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://www.iteye.com/topic/613278" title="收藏这段代码" style="color: #006699; "><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">load&nbsp;average:&nbsp;<span style="color: #c00000; ">0.09</span>,&nbsp;<span style="color: #c00000; ">0.05</span>,&nbsp;<span style="color: #c00000; ">0.01</span>&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　很多人会这样理解负载均值：三个数分别代表不同时间段的系统平均负载(一分钟、五 分钟、以及十五分钟)，它们的数字当然是越小越好。数字越高，说明服务器的负载越 大，这也可能是服务器出现某种问题的信号。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　而事实不完全如此，是什么因素构成了负载均值的大小，以及如何区分它们目前的状况是 &#8220;好&#8221;还是&#8220;糟糕&#8221;?什么时候应该注意哪些不正常的数值?&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">回答这些问题之前，首先需要了解下这些数值背后的些知识。我们先用最简单的例子说明， 一台只配备一块单核处理器的服务器。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><strong style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">行车过桥</strong>&nbsp;<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">一只单核的处理器可以形象得比喻成一条单车道。设想下，你现在需要收取这条道路的过桥 费 &#8212; 忙于处理那些将要过桥的车辆。你首先当然需要了解些信息，例如车辆的载重、以及 还有多少车辆正在等待过桥。如果前面没有车辆在等待，那么你可以告诉后面的司机通过。 如果车辆众多，那么需要告知他们可能需要稍等一会。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　因此，需要些特定的代号表示目前的车流情况，例如：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　0.00 表示目前桥面上没有任何的车流。 实际上这种情况与 0.00 和 1.00 之间是相同的，总而言之很通畅，过往的车辆可以丝毫不用等待的通过。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　1.00 表示刚好是在这座桥的承受范围内。 这种情况不算糟糕，只是车流会有些堵，不过这种情况可能会造成交通越来越慢。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　超过 1.00，那么说明这座桥已经超出负荷，交通严重的拥堵。 那么情况有多糟糕? 例如 2.00 的情况说明车流已经超出了桥所能承受的一倍，那么将有多余过桥一倍的车辆正在焦急的等待。3.00 的话情况就更不妙了，说明这座桥基本上已经快承受不了，还有超出桥负载两倍多的车辆正在等待。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　上面的情况和处理器的负载情况非常相似。一辆汽车的过桥时间就好比是处理器处理某线程 的实际时间。Unix 系统定义的进程运行时长为所有处理器内核的处理时间加上线程 在队列中等待的时间。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　和收过桥费的管理员一样，你当然希望你的汽车(操作)不会被焦急的等待。所以，理想状态 下，都希望负载平均值小于 1.00 。当然不排除部分峰值会超过 1.00，但长此以往保持这 个状态，就说明会有问题，这时候你应该会很焦急。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　&#8220;所以你说的理想负荷为 1.00 ?&#8221;&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　嗯，这种情况其实并不完全正确。负荷 1.00 说明系统已经没有剩余的资源了。在实际情况中 ，有经验的系统管理员都会将这条线划在 0.70：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　&#8220;需要进行调查法则&#8221;： 如果长期你的系统负载在 0.70 上下，那么你需要在事情变得更糟糕之前，花些时间了解其原因。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　&#8220;现在就要修复法则&#8221;：1.00 。 如果你的服务器系统负载长期徘徊于 1.00，那么就应该马上解决这个问题。否则，你将半夜接到你上司的电话，这可不是件令人愉快的事情。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　&#8220;凌晨三点半锻炼身体法则&#8221;：5.00。 如果你的服务器负载超过了 5.00 这个数字，那么你将失去你的睡眠，还得在会议中说明这情况发生的原因，总之千万不要让它发生。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　那么多个处理器呢?我的均值是 3.00，但是系统运行正常!&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　哇喔，你有四个处理器的主机?那么它的负载均值在 3.00 是很正常的。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　在多处理器系统中，负载均值是基于内核的数量决定的。以 100% 负载计算，1.00 表示单个处理器，而 2.00 则说明有两个双处理器，那么 4.00 就说明主机具有四个处理器。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　回到我们上面有关车辆过桥的比喻。1.00 我说过是&#8220;一条单车道的道路&#8221;。那么在单车道 1.00 情况中，说明这桥梁已经被车塞满了。而在双处理器系统中，这意味着多出了一倍的 负载，也就是说还有 50% 的剩余系统资源 &#8212; 因为还有另外条车道可以通行。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　所以，单处理器已经在负载的情况下，双处理器的负载满额的情况是 2.00，它还有一倍的资源可以利用。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><strong style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">多核与多处理器</strong>&nbsp;<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">&nbsp;&nbsp;&nbsp; 先脱离下主题，我们来讨论下多核心处理器与多处理器的区别。从性能的角度上理解，一台主 机拥有多核心的处理器与另台拥有同样数目的处理性能基本上可以认为是相差无几。当然实际 情况会复杂得多，不同数量的缓存、处理器的频率等因素都可能造成性能的差异。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　但即便这些因素造成的实际性能稍有不同，其实系统还是以处理器的核心数量计算负载均值 。这使我们有了两个新的法则：</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　&#8220;有多少核心即为有多少负荷&#8221;法则： 在多核处理中，你的系统均值不应该高于处理器核心的总数量。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">&#8220;核心的核心&#8221;法则： 核心分布在分别几个单个物理处理中并不重要，其实两颗四核的处理器 等于 四个双核处理器 等于 八个单处理器。所以，它应该有八个处理器内核。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　</span><em style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">审视我们自己</em>&nbsp;<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　让我们再来看看 uptime 的输出&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　</span><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Shell代码&nbsp;<embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=~%20%24%20uptime%0A%E3%80%80%E3%80%8023%3A05%20up%2014%20days%2C%206%3A08%2C%207%20users%2C%20load%20averages%3A%200.65%200.42%200.36" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://www.iteye.com/topic/613278" title="收藏这段代码" style="color: #006699; "><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">~&nbsp;$&nbsp;uptime&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">　　<span style="color: #c00000; ">23</span>:<span style="color: #c00000; ">05</span>&nbsp;up&nbsp;<span style="color: #c00000; ">14</span>&nbsp;days,&nbsp;<span style="color: #c00000; ">6</span>:<span style="color: #c00000; ">08</span>,&nbsp;<span style="color: #c00000; ">7</span>&nbsp;users,&nbsp;load&nbsp;averages:&nbsp;<span style="color: #c00000; ">0.65</span>&nbsp;<span style="color: #c00000; ">0.42</span>&nbsp;<span style="color: #c00000; ">0.36</span>&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　这是个双核处理器，从结果也说明有很多的空闲资源。实际情况是即便它的峰值会到 1.7，我也从来没有考虑过它的负载问题。&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　那么，怎么会有三个数字的确让人困扰。我们知道，0.65、0.42、0.36 分别说明上一分钟、最后五分钟以及最后十五分钟的系统负载均值。那么这又带来了一个问题：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　我们以哪个数字为准?一分钟?五分钟?还是十五分钟?&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　其实对于这些数字我们已经谈论了很多，我认为你应该着眼于五分钟或者十五分钟的平均数 值。坦白讲，如果前一分钟的负载情况是 1.00，那么仍可以说明认定服务器情况还是正常的。 但是如果十五分钟的数值仍然保持在 1.00，那么就值得注意了</span><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; color: red; ">(根据我的经验，这时候你应该增加处理器的数量了)。</span>&nbsp;<br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　那么我如何得知我的系统装备了多少核心的处理器?&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　在 Linux 下，可以使用&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　</span><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Shell代码&nbsp;<embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=cat%20%2Fproc%2Fcpuinfo" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://www.iteye.com/topic/613278" title="收藏这段代码" style="color: #006699; "><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">cat&nbsp;/proc/cpuinfo&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　获取你系统上的每个处理器的信息。如果你只想得到数字，那么就使用下面的命令：&nbsp;</span><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; ">　　</span><div id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25px; text-align: left; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-weight: bold; ">Shell代码&nbsp;<embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=grep%20'model%20name'%20%2Fproc%2Fcpuinfo%20%7C%20wc%20-l" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">&nbsp;<a href="http://www.iteye.com/topic/613278" title="收藏这段代码" style="color: #006699; "><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d1d7dc; border-right-color: #d1d7dc; border-bottom-color: #d1d7dc; border-left-color: #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">grep&nbsp;'model&nbsp;name'&nbsp;/proc/cpuinfo&nbsp;|&nbsp;wc&nbsp;-l&nbsp;&nbsp;</li></ol></div><br style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #efefef; " /><img src ="http://www.blogjava.net/kelly859/aggbug/377089.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-04-30 23:18 <a href="http://www.blogjava.net/kelly859/archive/2012/04/30/377089.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux服务器性能评估与优化</title><link>http://www.blogjava.net/kelly859/archive/2012/04/30/377086.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 30 Apr 2012 14:41:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/04/30/377086.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/377086.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/04/30/377086.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/377086.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/377086.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文地址：http://www.517sou.net/Article/104.aspx&nbsp;一、影响Linux服务器性能的因素&nbsp;1.&nbsp;操作系统级&nbsp;&#216;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CPU&#216;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;内存&#216;&n...&nbsp;&nbsp;<a href='http://www.blogjava.net/kelly859/archive/2012/04/30/377086.html'>阅读全文</a><img src ="http://www.blogjava.net/kelly859/aggbug/377086.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-04-30 22:41 <a href="http://www.blogjava.net/kelly859/archive/2012/04/30/377086.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SUSE常用软件安装</title><link>http://www.blogjava.net/kelly859/archive/2012/04/25/376530.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Tue, 24 Apr 2012 16:50:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/04/25/376530.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/376530.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/04/25/376530.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/376530.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/376530.html</trackback:ping><description><![CDATA[<div></div><div><div><strong style="background-color: #00ffff;">安装lrzsz</strong><br />mkdir -p /usr/src/tools</div><div>cd /home/ryan/tools</div><div>wget http://down1.chinaunix.net/distfiles/lrzsz-0.12.20.tar.gz</div><div>tar zxvf lrzsz-0.12.20.tar.gz</div><div>cd lrzsz-0.12.20</div><div>./configure --prefix=/usr/local/lrzsz</div><div>make</div><div>make install</div><div>cd /usr/bin&nbsp;</div><div>ln -s /usr/local/lrzsz/bin/lrz rz &nbsp;&nbsp;</div><div>ln -s /usr/local/lrzsz/bin/lsz sz</div><div>rz</div><strong style="color: #000000; background-color: #00ffff;"><br />安装tomcat&amp;resin</strong><br style="color: #000000; background-color: #00ffff;" />vi &nbsp;catalina.sh&nbsp;</div><div>JAVA_OPTS="$JAVA_OPTS -Xms2048m -Xmx2048m -Xmn512m -XX:PermSize=64M -Xss1000k -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70"</div><div>JAVA_OPTS="$JAVA_OPTS -Xloggc:jvm.log -XX:+PrintGCTimeStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDetails"</div><div>JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.227.2"</div><div><br /><div><div><strong style="color: #000000; background-color: #00ffff;">SUSE修改hostname</strong></div><div>vi /etc/HOSTNAME<br /><div>192.168.227.2<br /><div>vi /etc/hosts</div><div>192.168.227.2 &nbsp; localhost<br /><br /><strong><span style="background-color: #00ffff;">修改IP</span></strong><strong style="background-color: #00ffff;">地址</strong><br style="background-color: #00ffff;" /><div>vi /etc/sysconfig/network/ifcfg-eth0</div><div></div><div>IPADDR=192.168.80.200<br />NETMASK=255.255.255.0<br />BROADCAST=192.168.80.255<br />GATEWAY=192.168.80.2<br />STARTMODE=onboot<br />BOOTPROTO=dhcp<br />USERCONTROL=no<br />FIREWALL=no<br /><br /><div><strong><span style="background-color: #00ffff;">安装sysbench<br /></span></strong><span style="background-color: #00ffff;"><div>wget http://nchc.dl.sourceforge.net/project/sysbench/sysbench/0.4.12/sysbench-0.4.12.tar.gz<br />tar -zxvf sysbench-0.4.12.tar.gz<br /><div>cp /usr/bin/libtool ./</div><div>./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib</div>make&amp;make install<br /><br /><div><strong><span style="background-color: #00ffff;">挂在共享目录<br /></span></strong><span><span style="background-color: #00ffff;"><div>mount -t cifs //192.168.80.1/share/data/share -o username=maxchen,password=123456</div></span></span><span><span style="background-color: #00ffff;"><div>umount -l /data/share</div></span></span><strong><span style="background-color: #00ffff;"><br /></span></strong></div></div></span><strong><span style="background-color: #00ffff;"><br /></span></strong></div></div><div></div></div></div></div></div></div><div></div><img src ="http://www.blogjava.net/kelly859/aggbug/376530.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-04-25 00:50 <a href="http://www.blogjava.net/kelly859/archive/2012/04/25/376530.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>