linux 内存性能诊断
<p><strong>内存性能分析命令,以及内存性能分析方法</strong></p>
<h2>Linux 内存性能分析常用命令</h2>
<ul>
<li>
<h3>top</h3>
<p>top 命令经常用来监控 Linux 的系统状况,比如 CPU、内存的使用情况,如下图所示:
<img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/3dd1cc78e50ed479472958a4a1db1c73" alt="" /></p>
<pre><code>#图中第四行显示为系统内存状态
total: 物理内存总量
used: 使用中的内存总量
free: 空闲内存总量
buffers: 缓存的内存量
#图中第五行显示 swap 交换分区
total: 交换区总量
used: 使用的交换区总量
free: 空闲交换区总量
cached: 缓冲的交换区总量</code></pre>
<p>系统性能评估标准:</p>
</li>
</ul>
<table>
<thead>
<tr>
<th>影响性能因素</th>
<th>好</th>
<th>坏</th>
<th>糟糕</th>
</tr>
</thead>
<tbody>
<tr>
<td>内存</td>
<td>Swap In(si)=0 Swap Out(so)=0</td>
<td>Per CPU with 10 page/s</td>
<td>More Swap In & Swap Out</td>
</tr>
</tbody>
</table>
<ul>
<li>
<h3>vmstat</h3>
<p>vmstat 是 Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存、进程、IO 读写、CPU 活动等进行监视,如下图所示:
<img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/87ba49e64e8f5ed111bf6dec6ac89309" alt="" /></p>
<pre><code>memory 部分
swpd:切换到内存交换区的内存大小;
free:当前空闲的物理内存;
buff:baffers cached 内存大小;
swap:
si:内存进入内存交换区的内存大小;
so:由内存进入磁盘,也就是由内存交换区进入内存的内存大小;</code></pre>
</li>
</ul>
<h2>Linux 内存性能诊断</h2>
<p>使用 vmstat 来进行分析,如下所示:
<code>vmstat 1 10</code>
<img src="http://60.191.64.5:16100/server/index.php?s=/api/attachment/visitFile/sign/7b74cd0800d47f7b223635c1885d5f56" alt="" /></p>
<ul>
<li>
<p><strong>MEMORY</strong></p>
<pre><code>swap:切换到交换内存上的内存(默认以 KB 为单位)。如果 SWAP 的值不为 0,或者还比较大,比如超过 100 MB 了,但是 SI 和 SO 的值长期为 0,这种情况我们可以不用担心,不会影响系统性能。
free:空闲的物理内存。
buff:作为 buffer cache 的内存,对块设备的读写进行缓冲。
cache:作为 page cache 的内存,文件系统的 cache 如果 cache 的值大的时候,说明 cache 处的文件数多,如果频繁访问到的文件都能被 cache,那么磁盘的读 IO bi 会非常小。</code></pre>
</li>
<li><strong>SWAP</strong>
<pre><code>si:交换内存使用,由磁盘调入内存。
so:交换内存使用,由内存调入磁盘。</code></pre></li>
</ul>