磁盘写入速度比读取速度慢得多

我有一个运行CentOS的VPS服务器(WiredTree)。

遇到一些性能问题后,我使用以下脚本为磁盘读/写速度创build了一个简单的基准:

echo Write to disk dd if=/dev/zero of=test1 bs=1048576 count=2048 echo Read from disk dd if=test1 of=/dev/null bs=1048576 

这是一个示例输出:

 [bizwayz@host perf]./benchmark Write to disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 11.2601 seconds, 191 MB/s Read from disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 0.789302 seconds, 2.7 GB/s [bizwayz@host perf]./benchmark Write to disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 3.69129 seconds, 582 MB/s Read from disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 0.789897 seconds, 2.7 GB/s [bizwayz@host perf]./benchmark Write to disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 9.56615 seconds, 224 MB/s Read from disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 0.882664 seconds, 2.4 GB/s [bizwayz@host perf]./benchmark Write to disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 3.52512 seconds, 609 MB/s Read from disk 2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 0.784007 seconds, 2.7 GB/s 

我的问题是,写入速度是否比读取速度慢是正常的。

您正在运行VPS服务器。 这意味着物理计算机上还有其他客户端,他们如何使用这些磁盘会影响读取和写入性能。

通常在RAID10上,读取速率大约是写入速率的1/2。 但是,由于存在大量未知variables,因此可能有另一个客户端正在写入大量磁盘,这就是为什么您看到写入速度变慢的原因。

与他们打开一张票不能伤害,但与VPS,这是你通常会看到的。 VPS是为了方便和价值,而不是性能。

编辑:可以肯定,caching是一个问题在这里,但我的观点仍然适用。

请确保使用fdatasync命令运行dd命令,以确保它实际上将文件数据刷新到磁盘,而不是仅默认情况下内核执行的内存。 即:

 dd bs=1M count=512 if=/dev/zero of=test conv=fdatasync 

是的,这很正常。 你的文件只有2GB左右,完全适合caching。 它实际上从来没有从磁盘读取,只是从caching中读取。 使文件大小至less大10倍,以获得任何有意义的结果,甚至更多,取决于你的RAM大小(2倍的RAM是一个很好的起点)。

我真的很想有一个2.7 GB /秒的读取速度的磁盘:)

testing技术中的一个问题是Linux中的内部系统缓冲function正在被利用,这大大扭曲了您的结果。

一般来说,磁盘写入当然比磁盘读取慢。 在逻辑文件级写入可能会慢得多,因为有(1)磁盘分配过程,(2)更新目录信息等等。 因此,当文件级写入发生时有更多的操作,它不是一个简单的primefaces操作,与文件级读操作很容易地进行比较。

在基准testing中,您需要清除每次testing之间的缓冲区caching….或者在每一步之间重新启动您的机器:-)。 顺便说一句,我相信有一个简单的方法来做到这一点,写一些适用/ proc区域。

编辑:caching清理过程:

  sync && echo 3 > /proc/sys/vm/drop_caches 

您应该在每个dd命令之前执行此操作。