<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TQ 试用 WP &#187; Linux Performance_Tuning</title>
	<atom:link href="http://tq.freehostia.com.freehostia.com/tag/linux-performance_tuning/feed" rel="self" type="application/rss+xml" />
	<link>http://tq.freehostia.com.freehostia.com</link>
	<description>TQ 试用中... ...</description>
	<lastBuildDate>Fri, 19 Mar 2010 06:07:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>高可用集群&#8212;&#8212;HA</title>
		<link>http://tq.freehostia.com.freehostia.com/2009/10/%e9%ab%98%e5%8f%af%e7%94%a8%e9%9b%86%e7%be%a4ha.html</link>
		<comments>http://tq.freehostia.com.freehostia.com/2009/10/%e9%ab%98%e5%8f%af%e7%94%a8%e9%9b%86%e7%be%a4ha.html#comments</comments>
		<pubDate>Sun, 11 Oct 2009 08:19:00 +0000</pubDate>
		<dc:creator>TQ</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Performance_Tuning]]></category>

		<guid isPermaLink="false">http://tq.freehostia.com.freehostia.com/2009/10/%e9%ab%98%e5%8f%af%e7%94%a8%e9%9b%86%e7%be%a4ha.html</guid>
		<description><![CDATA[高可用集群——HA
2008年3月10日
当日小结：
 掌握使用heartbeat对Director做高可用集群HA（High Availability）。

“数据源”和“单一故障点（SOPE）”需要做HA集群。 
HA方式：（三种）
主从方式HA：
... ]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>高可用集群——HA</strong></p>
<p>2008年3月10日</p>
<p><strong>当日小结：</strong></p>
<p><strong> </strong><strong>掌握使用heartbeat对Director做高可用集群HA（High Availability）。</strong></p>
<p><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image0012.gif"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image001" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image001_thumb2.gif" border="0" alt="clip_image001" width="520" height="234" /></a></p>
<p><strong>“数据源”和“单一故障点（</strong><strong>SOPE</strong><strong>）”需要做</strong><strong>HA</strong><strong>集群。</strong><strong> </strong></p>
<p><strong>HA</strong><strong>方式：（三种）</strong></p>
<p><strong><span style="text-decoration: underline;">主从方式HA：</span></strong></p>
<p><strong><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image0021.gif"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image002" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image002_thumb1.gif" border="0" alt="clip_image002" width="516" height="232" /></a></strong><strong> </strong></p>
<p><strong>主从方式</strong><strong>HA</strong><strong>：从服务平时不运行。只有当主服务</strong><strong>DOWN</strong><strong>掉时，从服务才马上启用。</strong><strong> </strong></p>
<p><strong> </strong></p>
<p><strong><span style="text-decoration: underline;">对称方式HA：</span></strong></p>
<p><strong><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image003.gif"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image003" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image003_thumb.gif" border="0" alt="clip_image003" width="454" height="136" /></a></strong><strong> </strong></p>
<p><strong>现在，一般的陈列柜都有双控制器，可以有来个服务同时进行读写。</strong><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong><span style="text-decoration: underline;">集群方式HA：</span></strong></p>
<p><strong><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image004.gif"><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="clip_image004" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image004_thumb.gif" border="0" alt="clip_image004" width="472" height="201" /></a></strong><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> <span id="more-235"></span></strong></p>
<p><strong>安装heartbeat：</strong></p>
<p><strong>＃</strong><strong>rpm -ivh *.rpm &#8211;force &#8211;nodeps</strong></p>
<p><strong> </strong></p>
<p><strong>＃</strong><strong>cp /usr/share/doc/heart-2.1.2/ha.cf /etc/ha.d/ </strong><strong>＃</strong><strong>主配置文件。</strong><strong> </strong></p>
<p><strong>＃</strong><strong>cp /usr/share/doc/heart-2.1.2/haresources /etc/ha.d/ </strong><strong>＃</strong><strong>切换配置文件。</strong><strong> </strong></p>
<p><strong>＃</strong><strong>cp /usr/share/doc/heart-2.1.2/authkeys /etc/ha.d/ </strong><strong>＃</strong><strong>认证文件。</strong><strong> </strong></p>
<p><strong>＃</strong><strong>cp /usr/share/doc/heartbeat-ldirectord2.1.2/ldirectord.cf /etc/ha.d/ </strong></p>
<p><strong>＃</strong><strong>查看</strong><strong>real server</strong><strong>是否正常工作的文件。</strong><strong></strong></p>
<p><strong></strong> </p>
<p><strong>Director</strong><strong>的</strong><strong>HA</strong><strong>集群：</strong><strong></strong></p>
<p><strong><span style="text-decoration: underline;">主Director：</span></strong></p>
<p><strong>/etc/ha.d/ha.cf </strong><strong>＃</strong><strong>主配置文件</strong><strong></strong></p>
<p><strong>写：</strong><strong>debugfile /var/log/ha-debug</strong></p>
<p><strong>logfile /var/log/ha-log</strong></p>
<p><strong>logfacility local0</strong></p>
<p><strong>keepalive 2 </strong><strong>＃</strong><strong>一分钟内进行</strong><strong>2</strong><strong>秒心跳。</strong><strong></strong></p>
<p><strong>deadtime 10 </strong><strong>＃</strong><strong>10</strong><strong>秒没心跳为“死心跳”。</strong><strong></strong></p>
<p><strong>warntime 6 </strong><strong>＃</strong><strong>6</strong><strong>秒没心跳，就警告。</strong><strong></strong></p>
<p><strong>initdead 120 </strong><strong>＃</strong><strong>开机</strong><strong>120</strong><strong>秒“死心跳”。</strong><strong></strong></p>
<p><strong>udpport 694 </strong><strong>＃</strong><strong>网卡心跳。用</strong><strong>UDP</strong><strong>：</strong><strong>694</strong><strong>端口。</strong><strong></strong></p>
<p><strong>#band 19200 </strong><strong>＃</strong><strong>波特率，串口心跳。</strong><strong></strong></p>
<p><strong>#serial /dev/ttyS0 </strong><strong>＃</strong><strong>linux</strong><strong>的串口设备。</strong><strong></strong></p>
<p><strong>#bcast eth0 </strong><strong>＃</strong><strong>广播心跳。</strong><strong></strong></p>
<p><strong>#mcast eth0 225.0.0.1 694 1 0 </strong><strong>＃</strong><strong>组播心跳。</strong><strong></strong></p>
<p><strong>#ucast eth0 <span style="text-decoration: underline;">192.168.0.68</span> </strong><strong>＃</strong><strong>UDP </strong><strong>点到点通信。<span style="text-decoration: underline;">设对方</span></strong><strong><span style="text-decoration: underline;">IP</span></strong><strong>。</strong><strong></strong></p>
<p><strong>auto_failback on </strong><strong>＃</strong><strong>on</strong><strong>：从<span style="text-decoration: underline;">从服务器</span>再切换回<span style="text-decoration: underline;">主服务器</span>。</strong><strong></strong></p>
<p><strong></strong><strong>＃</strong><strong>off</strong><strong>：主服务器</strong><strong>DOWN</strong><strong>掉→从服务器启动，主服务器</strong><strong>UP</strong><strong>了，不自动切换回主服务器，还是由从服务器运行。</strong><strong></strong></p>
<p><strong>#stonith baytech /etc/ha.d/conf/stonith.baytech</strong></p>
<p><strong>#stonith_host * baytech 10.0.0.3 mylogin mysecretpassword</strong></p>
<p><strong></strong><strong>＃</strong><strong>设置可编程电源控制器</strong><strong></strong></p>
<p><strong>watchdog /dev/watchdog </strong><strong>＃</strong><strong>软看门狗，要＃</strong><strong>modprobe softdog</strong><strong></strong></p>
<p><strong>node tq.com </strong><strong>＃</strong><strong>必须用主机名。写在前为主</strong><strong>Server</strong><strong>，写在后为从</strong><strong>Server</strong><strong>。</strong><strong></strong></p>
<p><strong>node cz.com </strong><strong>＃</strong><strong>要在</strong><strong>/etc/hosts</strong><strong>文件中对应</strong><strong>IP</strong><strong>。写：</strong><strong>192.168.0.66 tq.com</strong></p>
<p><strong>192.168.0.168 cz.com</strong></p>
<p><strong>ping 192.168.0.68 </strong><strong>＃</strong><strong>仲裁</strong><strong></strong></p>
<p><strong>respawn hacluster</strong><strong>（或</strong><strong>root</strong><strong>）</strong><strong> /usr/lib/heartbeat/ipfail</strong></p>
<p><strong>apiauth ipfail gid=haclient</strong><strong>（或</strong><strong>root</strong><strong>）</strong><strong> uid=hacluster</strong><strong>（或</strong><strong>root</strong><strong>）</strong><strong></strong></p>
<p><strong></strong> </p>
<p><strong>/etc/ha.d/authkeys </strong><strong>认证文件。</strong><strong></strong></p>
<p><strong>写：</strong><strong>auth 1</strong></p>
<p><strong>1 crc</strong></p>
<p><strong><span style="text-decoration: underline;">＃</span></strong><strong><span style="text-decoration: underline;">chmod 600 /etc/ha.d/authkeys</span></strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p><strong>/etc/ha.d/haresources </strong><strong>切换配置文件。</strong><strong></strong></p>
<p><strong><span style="text-decoration: underline;">切换三要素</span></strong>：① VIP；</p>
<p>② server scripts 脚本</p>
<p>③ fs 文件系统。（当Director(无存储时)时，不用切换fs）</p>
<p>无存储时，写：tq.com IPaddr::VIP/24<span style="text-decoration: underline;">/</span><span style="text-decoration: underline;">eth0:1</span> ipvsadm ldirectord</p>
<p>当有存储时，写：node1 10.0.0.170 Filesystem::/dev/sda1::/data1::ext2</p>
<p><strong>＃</strong><strong>ipvsadm</strong><strong>配置并</strong><strong>save</strong><strong>。</strong><strong></strong></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="227"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
<p><strong>＃</strong><strong>scp</strong> /etc/ha.d/ha.cf 到<span style="text-decoration: underline;">从服务</span></p>
<p>/etc/ha.d/haresoures</p>
<p>/etc/ha.d/suthkeys</p>
<p>/etc/hosts</p>
<p>/etc/sysconfig/ipvsadm</p>
<p><strong>＃</strong><strong>service heartbeat start</strong></p>
<p><strong>＃</strong><strong>chkconfig ipvsadm off</strong></p>
<p><strong>＃</strong><strong>service ipvsadm stop</strong></p>
<p><strong>/etc/ha.d/ldirectord.cf </strong><strong>查看</strong><strong>real server</strong><strong>是否正常工作。</strong><strong></strong></p>
<p>checktimeout=10 <strong>＃</strong>10秒看不到，把real server的ipvsadm中-w权值清“0”。</p>
<p>checkinterval=5 <strong>＃</strong>每隔5秒访问一下real server</p>
<p>fallback=127.0.0.1:80</p>
<p>autoreload=yes <strong>＃</strong>再把/etc/sysconfig/ipvsadm中的-w权值设为“1”。</p>
<p>logfile=”/var/log/ldirectord.log”</p>
<p>#logfile=”local0”</p>
<p>＃＃虚拟服务</p>
<p>virtual=VIP:80</p>
<p>real=RIP1:80 gate <strong>＃</strong>DR（LVS）方式是gate。NAT（LVS）方式是masq。</p>
<p>隧道方式是ipip。</p>
<p>real=RIP2:80 gate</p>
<p>fallback=127.0.0.1:80 gate</p>
<p>service=http</p>
<p>request=”index.html” <strong>＃</strong>apache的htdocs/目录下index.html文件中，要有“Test Page”这8个字符。</p>
<p>receive=”Test Page”</p>
<p>#virtualhost=some.domain.com.au</p>
<p>scheduler=rr</p>
<p>protocol=tcp</p>
<p>checktype=negotiate</p>
<p>checkport=80</p>
<p>#virtualhost=www.x.y.z</p>
<p><strong><span style="text-decoration: underline;">从Director：</span></strong></p>
<p>① <strong>＃</strong><strong>vim /etc/ha.d/ha.cf</strong></p>
<p>写对方IP：ucase eth0 192.168.0.66</p>
<p>② 看一下，hostname</p>
<p>③ ＃chkconfig ipvsadm off</p>
<p>＃service ipvsadm stop</p>
<p>＃chmod 600 /etc/ha.d/authkeys</p>
<p><strong>查看：</strong><strong></strong></p>
<p>＃ipvsadm -L</p>
<p>＃ifconfig <span style="text-decoration: underline;">eth0:1</span></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tq.freehostia.com.freehostia.com/2009/10/%e9%ab%98%e5%8f%af%e7%94%a8%e9%9b%86%e7%be%a4ha.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>调优小结（一）&amp;&amp; linux_Performance_Tuning_1</title>
		<link>http://tq.freehostia.com.freehostia.com/2009/10/%e8%b0%83%e4%bc%98%e5%b0%8f%e7%bb%93%ef%bc%88%e4%b8%80%ef%bc%89-linux_performance_tuning_1.html</link>
		<comments>http://tq.freehostia.com.freehostia.com/2009/10/%e8%b0%83%e4%bc%98%e5%b0%8f%e7%bb%93%ef%bc%88%e4%b8%80%ef%bc%89-linux_performance_tuning_1.html#comments</comments>
		<pubDate>Sun, 11 Oct 2009 08:04:00 +0000</pubDate>
		<dc:creator>TQ</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Performance_Tuning]]></category>

		<guid isPermaLink="false">http://tq.freehostia.com.freehostia.com/2009/10/%e8%b0%83%e4%bc%98%e5%b0%8f%e7%bb%93%ef%bc%88%e4%b8%80%ef%bc%89-linux_performance_tuning_1.html</guid>
		<description><![CDATA[调优小结（一）
2008年3月3日
Linux调优：从底层编程的角度考虑。
① 先调优应用程序Application
② 再调优操作系统OS
③ 再调优硬件
调优：
① 计算机体系结构：冯·诺伊曼模型。
② Linux系统及硬... ]]></description>
			<content:encoded><![CDATA[<blockquote><p><b>调优小结（一）</b>
<p>2008年3月3日
<p><b><u>Linux</u></b><b><u>调优</u></b><b>：从底层编程的角度考虑。</b>
<p><b>① </b><b>先调优应用程序Application</b>
<p><b>② </b><b>再调优操作系统OS</b>
<p><b>③ </b><b>再调优硬件</b>
<p><b>调优：</b>
<p><b>① </b><b>计算机体系结构：冯·诺伊曼模型。</b>
<p><b>② </b><b>Linux</b><b>系统及硬件常见性能问题及分析工具。</b>
<p><b>命令：ps、top、vmstat、iostat、mpstat、lsof、strace、ltrace、pmap、ipcs</b>
<p><b></b><b>③ /proc文件系统及内核参数调整。</b>
<p><b>一、计算机体系结构</b>
<p><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image0011.gif"><img title="system_configuration" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="266" alt="system_configuration" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image001_thumb1.gif" width="480" border="0"></a>
<p>CPU的<u>X86指令集</u>兼容386指令集以后的指令集。
<p>Windows中：.com 文件，编译成机器代码。
<p>.exe 文件，编译成操作系统（windows）的API，一少部分编译成机器代码。
<p><u>.com </u><u>文件执行最快，直接执行机器代码。</u>
<p>windows微内核（最核心）
<p><b>注：</b>grub就是机器代码。
<p><b>IA-32</b><b>体系结构：</b>
<p><b>一、CPU：</b>
<p>RISC：精简指令集。
<p>CISC：复杂指令集。
<p>64位：① X86-64：支持大内存2<sup>64</sup>＝16G
<p>② 科学计算（整数计算）2<sup>64</sup>位。
<p><b></b>
<p><b>二、内存：</b>
<p><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image002.gif"><img title="memory" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="201" alt="memory" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image002_thumb.gif" width="460" border="0"></a>
<p><u>服务器端需要大缓存。</u>
<p>内存：EDO：50MH<sub>Z</sub>
<p>SDRAM：66MH<sub>Z</sub>～133MH<sub>Z</sub>
<p>DDR1：266MH<sub>Z</sub>～400MH<sub>Z</sub> 上升沿、下降沿都执行一次，翻倍了。
<p>DDR2：533MH<sub>Z</sub>～800MH<sub>Z</sub>
<p><u></u>
<p><b>三、总线：</b>
<p><u>PCI</u><u>总线</u>：
<p>4B（32bit）×33 MH<sub>Z</sub>/s＝133MB/s
<p>8B（64bit）×33 MH<sub>Z</sub>/s＝266MB/s
<p>8B（64bit）×66 MH<sub>Z</sub>/s＝512MB/s
<p><b></b>
<p><u>PCI-X</u><u>总线</u>＝1GB/s
<p><u>USB</u><u>总线</u>：都是480Mb/s，是点对点（Point-to-Point）的Share Switch架构。
<p><u>PCI-E</u><u>总线</u>：是点对点（Point-to-Point）的Share Switch架构，每条回路都为250MB/s。
<p>1X：250MB/s
<p>16X：4GB/s
<p><u>IDE</u><u>总线</u>：133Mbps＝16MB/s ，寻道时间：8ms（毫秒） 一秒，125H<sub>Z</sub>
<p><b>二、Linux系统及硬件常见性能问题及分析工具</b>
<p><b>命令：ps、top、vmstat、iostat、mpstat、lsof、strace、ltrace、pmap、ipcs</b>
<p><u>检查系统时的步骤</u>：
<p>① ＃free
<p>② ＃ps aux
<p>③ 先备份<u></u>
<p>④ 再进行调整。
<p><u></u>
<p><b>[root@vm51: ~]#<u>top</u></b>
<p><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image004.jpg"><img title="clip_image004" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="233" alt="clip_image004" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image004_thumb.jpg" width="557" border="0"></a>
<p><b>[root@vm51: ~]#<u>uptime</u></b>
<p>15:02:22 up 9:55, 2 users, load average: 0.00, 0.00, 0.00
<p><b>注：top和uptime都是调用/proc/loadavg</b>
<p><u>load average</u>：1秒、5秒、15秒 等待执行任务的平均时间。
<p><b>说明：</b><b>load average</b><b>值高时，可能是：① I/O 慢设备读写；② 内存不足。</b>
<p><b></b><b>内存不足会引起I/O wait高，CPU占用高。内存不足，三个都高。</b>
<p><b></b>
<p><u>CPU</u><u>（s）</u>:<br />
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="246">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p>用top命令时，
<p>按”1”：可看每个CPU占用％。
<p>按”m”：以内存占用率排序。
<p>按”r”：renice 一个进程。
<p>按”k”：kill一个进程。</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>%us：用户占用CPU％
<p>%sy：系统空间占用CPU％
<p>%ni：高优先级占用CPU％
<p>%id：空闲CPU％
<p>%wa：等待硬盘占CPU％
<p>%hi：硬中断占CPU％
<p>%si：软中断占CPU％
<p><b>说明</b>：内存还没用空，就有用SWAP了，是内存慌恐机制引起的。
<p><b>说明：</b>
<p>buffer：在硬件中的缓存。只关心硬件，其内容不被关心。
<p>cache：写文件时用的缓存。关心文件、路径。
<p><b>[root@vm51: ~]#<u>ps -aux</u></b>
<p>Warning: bad syntax, perhaps a bogus &#8216;-&#8217;? See /usr/share/doc/procps-3.2.7/FAQ
<p>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
<p>root 1 0.0 0.2 2036 644 ? Ss 05:06 0:03 init [3]
<p>root 2 0.0 0.0 0 0 ? S 05:06 0:00 [migration/0]
<p>root 3 0.0 0.0 0 0 ? SN 05:06 0:00 [ksoftirqd/0]
<p>root 4 0.0 0.0 0 0 ? S 05:06 0:00 [watchdog/0]
<p>root 5 0.0 0.0 0 0 ? S 05:06 0:00 [migration/1]
<p>root 6 0.0 0.0 0 0 ? SN 05:06 0:00 [ksoftirqd/1]
<p>root 7 0.0 0.0 0 0 ? S 05:06 0:00 [watchdog/1]
<p>TIME:从开机到现在占用CPU累计时间。
<p>COMMAND：进程名字。有[]的只占内核空间（内核线程），是kill不掉的。
<p><u>Linux</u><u>中一页内存4K。</u>
<p>SATA：状态字。
<p>R：正在运行running。
<p>S：可中断休眠。
<p>s：会话session。一堆具有相同父进程的进程，表示下面有“子进程”，此为“父进程”。
<p>l：有线程。共享相同（工作单元）资源的进程。（省内存）
<p>＋：前置进程。当前tty的第一个进程。
<p>＜：高优先级进程。 nice值：-20最高～19最低
<p>N：低优先级进程。
<p>L：有内存锁。所占的内存不会被交换到SWAP中。
<p>D：不可中断休眠。deep sleep深度休眠，多了说明慢速设备I/O多。
<p>T：暂停进程。
<p>Z：僵尸进程。（儿子死了，父不回收。不占资源，占PID，占内存1.7K，不能被kill）
<p><a href="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image005.gif"><img title="clip_image005" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="295" alt="clip_image005" src="http://tq.freehostia.com.freehostia.com/wp-content/uploads/2009/10/clip_image005_thumb.gif" width="512" border="0"></a>
<p>说明：
<p>① 进程之间有封闭的内存。如果超出封闭内存范围，叫“内存溢出”。
<p>② 多线程可充分利用CPU。线程之间通讯方便、容易。
<p>③ 线程之间切换付出代价较小。
<p><b>命令：#<u>pmap PID</u> 查看调用到什么库</b>
<p><b>[root@vm51: ~]#<u>pmap 1</u></b>
<p>1: init [3]
<p>00546000 100K r-x&#8211; /lib/ld-2.5.so
<p>0055f000 4K r-x&#8211; /lib/ld-2.5.so
<p>00560000 4K rwx&#8211; /lib/ld-2.5.so
<p>00563000 1244K r-x&#8211; /lib/libc-2.5.so
<p>0069a000 8K r-x&#8211; /lib/libc-2.5.so
<p>0069c000 4K rwx&#8211; /lib/libc-2.5.so
<p>0069d000 12K rwx&#8211; [ anon ]
<p>006cb000 8K r-x&#8211; /lib/libdl-2.5.so
<p>006cd000 4K r-x&#8211; /lib/libdl-2.5.so
<p>006ce000 4K rwx&#8211; /lib/libdl-2.5.so
<p>008df000 236K r-x&#8211; /lib/libsepol.so.1
<p>0091a000 4K rwx&#8211; /lib/libsepol.so.1
<p>0091b000 40K rwx&#8211; [ anon ]
<p>00927000 84K r-x&#8211; /lib/libselinux.so.1
<p>0093c000 8K rwx&#8211; /lib/libselinux.so.1
<p>00dec000 4K r-x&#8211; [ anon ]
<p>08048000 32K r-x&#8211; /sbin/init
<p>08050000 4K rw&#8212; /sbin/init
<p>088ec000 132K rw&#8212; [ anon ]
<p>b7fb3000 8K rw&#8212; [ anon ]
<p>b7fc2000 4K rw&#8212; [ anon ]
<p>bff27000 88K rw&#8212; [ stack ]
<p>total 2036K
<p><b>命令：<u>#vmstat</u></b>
<p><b>[root@vm51: ~]#<u>vmstat 2 3</u></b>
<p>procs &#8212;&#8212;&#8212;&#8211;memory&#8212;&#8212;&#8212;- &#8212;swap&#8211; &#8212;&#8211;io&#8212;- &#8211;system&#8211; &#8212;&#8211;cpu&#8212;&#8212;
<p>r b swpd free buff cache si so bi bo in cs us sy id wa st
<p>0 0 8 10412 73608 116576 0 0 7 4 506 28 0 1 98 0 0
<p>0 0 8 10412 73608 116576 0 0 0 0 1015 35 0 0 100 0 0
<p>0 0 8 10412 73608 116576 0 0 0 0 1012 37 0 0 100 0 0
<p>r：在CPU等待要执行任务的个数。
<p>b：在CPU等待要进行块设备操作的个数。
<p>si/so：swapin：从磁盘读。
<p>swapout：写入到磁盘。
<p>bi/bo：blockin/blockout
<p>in：中断。
<p>cs：内容切换。
<p>us：用户占用CPU％
<p>sy：系统空间占用CPU％
<p>id：空闲CPU％
<p>wa：等待硬盘占CPU％ bi/bo高会导致wa高
<p><b>说明：没有si、so、bi、bo但r很高，说明CPU不行了，要换高性能的CPU了。</b>
<p><b>安装sysstat包会有<u>iostat、sar、mpstat</u>这三个命令。</b>
<p><b>[root@vm51: /mnt/Server]#rpm -ivh sysstat-7.0.0-3.el5.i386.rpm</b>
<p><b>[root@vm51: ~]#vmstat -d 1 1 </b><b>每隔1秒刷新 </b><b>就刷1次</b><b></b>
<p>disk- &#8212;&#8212;&#8212;&#8212;reads&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;writes&#8212;&#8212;&#8212;&#8211; &#8212;&#8211;IO&#8212;&#8212;
<p>total merged sectors ms total merged sectors ms cur sec
<p>ram0 0 0 0 0 0 0 0 0 0 0
<p>ram1 0 0 0 0 0 0 0 0 0 0
<p>ram2 0 0 0 0 0 0 0 0 0 0
<p>ram3 0 0 0 0 0 0 0 0 0 0
<p>ram4 0 0 0 0 0 0 0 0 0 0
<p>ram5 0 0 0 0 0 0 0 0 0 0
<p>ram6 0 0 0 0 0 0 0 0 0 0
<p>ram7 0 0 0 0 0 0 0 0 0 0
<p>ram8 0 0 0 0 0 0 0 0 0 0
<p>ram9 0 0 0 0 0 0 0 0 0 0
<p>ram10 0 0 0 0 0 0 0 0 0 0
<p>ram11 0 0 0 0 0 0 0 0 0 0
<p>ram12 0 0 0 0 0 0 0 0 0 0
<p>ram13 0 0 0 0 0 0 0 0 0 0
<p>ram14 0 0 0 0 0 0 0 0 0 0
<p>ram15 0 0 0 0 0 0 0 0 0 0
<p>sda 4636 2835 126957 19796 1679 2472 33208 24702 0 16
<p>hdc 195 116 1444 345 0 0 0 0 0 0
<p>fd0 0 0 0 0 0 0 0 0 0 0
<p>md0 0 0 0 0 0 0 0 0 0 0
<p><b>[root@vm51: ~]#sar -d 1 2 </b><b>可看现在到之后2秒的数据</b>
<p>Linux 2.6.18-8.el5 (vm51.com) 01/23/2008
<p>04:20:14 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
<p>04:20:15 PM dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
<p>04:20:15 PM dev22-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
<p>04:20:15 PM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
<p>04:20:16 PM dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
<p>04:20:16 PM dev22-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
<p>Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
<p>Average: dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
<p>Average: dev22-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
<p>tps：每秒读取次数
<p><b>sar </b><b>命令行的常用格式：</b><b><br />sar [options] [-A] [-o file] t [n] <br /></b>在命令行中，n 和t 两个参数组合起来定义采样间隔和次数，t为采样间隔，是必须有<br />的参数，n为采样次数，是可选的，默认值是1，-o file表示将命令结果以二进制格式<br />存放在文件中，file 在此处不是关键字，是文件名。options 为命令行选项，sar命令<br />的选项很多，下面只列出常用选项：<br />-A：所有报告的总和。<br />-u：CPU利用率<br />-v：进程、I节点、文件和锁表状态。<br />-d：硬盘使用报告。 （看过去数据）<br />-r：没有使用的内存页面和硬盘块。<br />-q：看CPU负载。<br />-g：串口I/O的情况。<br />-b：缓冲区使用情况。<br />-a：文件读写情况。<br />-c：系统调用情况。<br />-R：进程的活动情况。<br />-y：终端设备活动情况。<br />-w：系统交换活动。
<p><b>[root@vm51: ~]#<u>mpstat</u> </b><b>用于看多CPU</b><b></b>
<p>Linux 2.6.18-8.el5 (vm51.com) 01/23/2008
<p>04:28:57 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
<p>04:28:57 PM all 0.73 0.00 2.24 0.80 0.05 0.14 0.00 96.03 1013.95
<p><b>ipcs </b><b>进程间通讯。</b>
<p><b>[root@vm51: ~]#ipcs </b>
<p>&#8212;&#8212; Shared Memory Segments &#8212;&#8212;&#8211;共享内存
<p>key shmid owner perms bytes nattch status
<p>&#8212;&#8212; Semaphore Arrays &#8212;&#8212;&#8211;信号灯：两进程之间协调用
<p>key semid owner perms nsems
<p>&#8212;&#8212; Message Queues &#8212;&#8212;&#8211;消息队列
<p>key msqid owner perms used-bytes messages
<p><b>[root@vm51: ~]#ipcrm -m shmid</b><b>（共享ID） 删SHM共享内存（Orecal时用）</b>
<p><b>lsof</b><b>、strace、ltrace命令：</b>
<p>lsof 刷/proc文件系统
<p><b>[root@vm51: ~]#lsof -p 1 -p</b><b>：PID</b><b></b>
<p>COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
<p>init 1 root cwd DIR 8,1 4096 2 /
<p>init 1 root rtd DIR 8,1 4096 2 /
<p>init 1 root txt REG 8,1 38620 654239 /sbin/init
<p>init 1 root mem REG 8,1 121684 427404 /lib/ld-2.5.so
<p>init 1 root mem REG 8,1 1576952 427405 /lib/libc-2.5.so
<p>init 1 root mem REG 8,1 16528 427406 /lib/libdl-2.5.so
<p>init 1 root mem REG 8,1 242880 427422 /lib/libsepol.so.1
<p>init 1 root mem REG 8,1 93512 427423 /lib/libselinux.so.1
<p>init 1 root 10u FIFO 0,16 927 /dev/initctl
<p><b>[root@vm51: ~]#watch lsof -p PID </b>
<p><b>[root@vm51: ~]#strace -p PID </b><b>显示系统调用，追踪程序在干什么</b>
<p><b>[root@vm51: ~]#strace apachectl start</b>
<p><b>[root@vm51: ~]#ltrace /bin/ls</b>
<p><b>[root@vm51: ~]#time /bin/ls </b><b>看执行命令用了多少时间</b>
<p>anaconda-ks.cfg Desktop install.log install.log.syslog password tq tqwjj u
<p>real 0m0.013s
<p>user 0m0.001s
<p>sys 0m0.011s
<p><b>三、/proc文件系统及内核参数调整</b>
<p>/proc/interrupts 中断
<p>/proc/ioports I/O资源
<p>/proc/meminfo 内存信息
<p>/proc/cpuinfo CPU信息
<p>/proc/devices 设备文件
<p><b>例：</b>
<p><b>[root@vm51: ~]#vim /etc/modprobe.conf</b>
<p>alias scsi_hostadapter mptbase
<p>alias scsi_hostadapter1 mptspi
<p>alias snd-card-0 snd-ens1371
<p>options snd-card-0 index=0
<p>options snd-ens1371 index=0
<p>remove snd-ens1371 { /usr/sbin/alsactl store 0 &gt;/dev/null 2&gt;&amp;1 || : ; }; /sbin/modprobe -r &#8211;ignore-remove snd-ens
<p>1371
<p>alias eth0 pcnet32
<p>写:options eth0 irq=10 ioports=
<p>中断冲突时改
<p><b>/proc/sys/</b><b>目录下的文件是要我们改的，即调优。</b>
<p><b>例：</b>
<p>[root@vm51: ~]#cat /proc/sys/net/ipv4/ip_forward
<p>0
<p><b>[root@vm51: ~]#echo &gt; 1 /proc/sys/net/ipv4/ip_forward </b><b>临时修改</b><b></b>
<p><b>[root@vm51: ~]#sysctl -w net.ipv4.ip_forward=1 </b><b>临时修改</b><b></b>
<p>net.ipv4.ip_forward = 1
<p><b>永久生效：</b>
<p><b>[root@vm51: ~]#vim /etc/sysctl.conf</b>
<p><b>写：net.ipv4.ip_forward = 1</b>
<p><b>[root@vm51: ~]#<u>sysctl -p</u> </b><b><u>读取/etc/sysctl.conf配置文件内容，并重新设置一遍。（永久生效）</u></b></p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tq.freehostia.com.freehostia.com/2009/10/%e8%b0%83%e4%bc%98%e5%b0%8f%e7%bb%93%ef%bc%88%e4%b8%80%ef%bc%89-linux_performance_tuning_1.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
