Linux 存储速度测试脚本

通常就是 计算读写一定大小的块耗费的时间 ,本身有速度输出
基本的测试如下 
磁盘读速度
#time dd if=[mountpoint] of=/dev/null bs=4096k count=2000
测试数据大小为:4096k×2000
磁盘写速度
#time dd if=/dev/zero of=[mountpoint] bs=4096k count=2000
测试数据大小为:4096k×2000
[mountpoint]替换为你实际的挂载点
以上都是测试 2000个 4M块的速度 可以通过改变 bs大小来分析不同级别块的性能

# 结论:
SSD+lvm的情况下,btrfs效率不如ext4;
btrfs比ext4更依赖内存做缓存, 所以卸载文件系统时需要的时间也更长;
btrfs跨2个设备读写能力是单设备的1.5倍,而不是线性增长;
ext4+lvm(strip 2)写能力是单设备的1.5倍,而非线性增长;

# 如果创建时给出了多个设备, btrfs将跨越多个设备, 貌似这样btrfs会自动负
# 载均衡, 且随便挂载一个都行; 但速度只能提升50%, 而不是线性关系.
# mkfs.btrfs /dev/sdb1 /dev/sdc1
/dev/sdb1             150G   56K  148G   1% /mnt/b
/dev/sdc1             150G   56K  148G   1% /mnt/c
# vi /etc/fstab
/dev/sdb1       /mnt/b          btrfs   noatime,nodiratime,nossd 0 0
/dev/sdc1       /mnt/c          btrfs   noatime,nodiratime,nossd 0 0

squid75 /mnt # mount -a
squid75 /mnt # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.6G  3.8G  60% /
udev                   10M  108K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/sdb1             150G   56K  148G   1% /mnt/b
/dev/sdc1             150G   56K  148G   1% /mnt/c
squid75 /mnt # cd b
squid75 /mnt/b # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 16.1637 s, 324 MB/s

real    0m16.167s
user    0m0.013s
sys     0m5.530s
squid75 /mnt/b # cd ../c
squid75 /mnt/c # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 16.696 s, 314 MB/s

real    0m18.117s
user    0m0.023s
sys     0m7.387s
squid75 /mnt/c #
squid75 /mnt/c # ..
squid75 /mnt # umount b c
squid75 /mnt # vi /etc/fstab
squid75 /mnt # mount -a
squid75 /mnt # rm -f b/haha c/haha
# 打过dd命令以后过一小会时间, 从atop里才能看到开始写数据了
squid75 /mnt/b # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 15.6941 s, 334 MB/s

real    0m15.697s
user    0m0.008s
sys     0m5.508s
squid75 /mnt/b # cd ../c
squid75 /mnt/c # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 15.3801 s, 341 MB/s

real    0m17.827s
user    0m0.009s
sys     0m7.484s
squid75 /mnt/c # ..
squid75 /mnt # umount b c
squid75 /mnt # mkfs.btrfs /dev/sdb1
WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using
fs created label (null) on /dev/sdb1
        nodesize 4096 leafsize 4096 sectorsize 4096 size 74.53GB
Btrfs Btrfs v0.19
Btrfs Btrfs v0.19
squid75 /mnt # mkfs.btrfs /dev/sdc1
WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using
fs created label (null) on /dev/sdc1
        nodesize 4096 leafsize 4096 sectorsize 4096 size 74.53GB
Btrfs Btrfs v0.19
squid75 /mnt # mount -a
squid75 /mnt # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.6G  3.8G  60% /
udev                   10M  108K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/sdb1              75G   56K   73G   1% /mnt/b
/dev/sdc1              75G   56K   73G   1% /mnt/c
squid75 /mnt # cd b
squid75 /mnt/b # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 25.3402 s, 207 MB/s

real    0m25.344s
user    0m0.015s
sys     0m5.562s
squid75 /mnt/b # cd ../c
squid75 /mnt/c # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 23.3695 s, 224 MB/s
real    0m23.373s
user    0m0.008s
sys     0m7.435s
squid75 /mnt/c # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.6G  3.8G  60% /
udev                   10M  108K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/sdb1              75G  4.9G   68G   7% /mnt/b
/dev/sdc1              75G  2.4G   71G   4% /mnt/c
squid75 /mnt/c # ..
squid75 /mnt # umount b c       # 时间较长
squid75 /mnt # mount -a
squid75 /mnt # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.6G  3.8G  60% /
udev                   10M  108K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/sdb1              75G  4.9G   68G   7% /mnt/b
/dev/sdc1              75G  4.9G   68G   7% /mnt/c
# 再看看ext4的表现
squid75 /mnt # mkfs.ext4 /dev/sd[bc]1
mke2fs 1.41.12 (17-May-2010)
mkfs.ext4: invalid blocks count - /dev/sdc1
squid75 /mnt # mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
4890624 inodes, 19537040 blocks
976852 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
597 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
squid75 /mnt # mkfs.ext4 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
4890624 inodes, 19537040 blocks
976852 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
597 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
squid75 /mnt # vi /etc/fstab
/dev/sdb1       /mnt/b          ext4    noatime,nodiratime 0 0
/dev/sdc1       /mnt/c          ext4    noatime,nodiratime 0 0
squid75 /mnt # mount -a
squid75 /mnt # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.6G  3.8G  60% /
udev                   10M  108K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/sdb1              74G  180M   70G   1% /mnt/b
/dev/sdc1              74G  180M   70G   1% /mnt/c
squid75 /mnt # cd b/
squid75 /mnt/b # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 22.3715 s, 234 MB/s

real    0m22.376s
user    0m0.015s
sys     0m8.670s
squid75 /mnt/b # cd ../c
squid75 /mnt/c # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 29.0778 s, 180 MB/s

real    0m29.082s
user    0m0.011s
sys     0m11.646s
# ext4使用了内存做缓存,命令行返回以后,后台仍在写.
squid75 /mnt/c # ..
squid75 /mnt # umount b c       # 这步比btrfs快一些
# 再测试一下LVM性能
squid75 /mnt # pvcreate /dev/sd[bc]1
  Physical volume "/dev/sdb1" successfully created
  Physical volume "/dev/sdc1" successfully created
squid75 /mnt # vgcreate cs /dev/sd[bc]1
  Volume group "cs" successfully created
squid75 /mnt # vgs
  VG   #PV #LV #SN Attr   VSize   VFree 
  cs     2   0   0 wz--n- 149.05g 149.05g
  lg     1   1   0 wz--n- 287.89g 237.89g
squid75 /mnt # lvcreate -n cs -L 140G cs
  Logical volume "cs" created
squid75 /mnt # lvremove /dev/cs/cs
Do you really want to remove active logical volume cs? [y/n]: y
  Logical volume "cs" successfully removed
squid75 /mnt # lvcreate -i 2 -n cs -L 140G cs
  Using default stripesize 64.00 KiB
  Logical volume "cs" created
squid75 /mnt # vi /etc/fstab
/dev/cs/cs      /mnt/c          ext4    noatime,nodiratime 0 0
squid75 /mnt # time mkfs.ext4 -m0 /dev/cs/cs
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=16 blocks, Stripe width=32 blocks
9175040 inodes, 36700160 blocks
0 blocks (0.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

real    0m18.553s
user    0m0.232s
sys     0m5.105s
squid75 /mnt # mount -a
squid75 /mnt # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.6G  3.8G  60% /
udev                   10M  112K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/mapper/cs-cs     138G  188M  138G   1% /mnt/c
squid75 /mnt # cd c
squid75 /mnt/c # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 15.3254 s, 342 MB/s

real    0m15.330s
user    0m0.010s
sys     0m8.887s
squid75 /mnt/c # pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda3  lg   lvm2 a-   287.89g 237.89g
  /dev/sdb1  cs   lvm2 a-    74.52g   4.52g
  /dev/sdc1  cs   lvm2 a-    74.52g   4.52g
squid75 /mnt/c # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.6G  3.8G  60% /
udev                   10M  112K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/mapper/cs-cs     138G  5.1G  133G   4% /mnt/c
# btrfs + lvm, ssd mode
squid75 /mnt # mkfs.btrfs /dev/cs/cs >/dev/null
squid75 /mnt # vi /etc/fstab
/dev/cs/cs      /mnt/c          btrfs   noatime,nodiratime 0 0
squid75 /mnt # mount -a
squid75 /mnt # df
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.9G  5.7G  3.8G  61% /
udev                   10M  112K  9.9M   2% /dev
shm                    16G     0   16G   0% /dev/shm
/dev/sda1             198M   32M  156M  17% /boot
/dev/mapper/lg-s       50G   56K   48G   1% /mnt/s
svcdir                2.0M  140K  1.9M   7% /var/lib/init.d
/dev/mapper/cs-cs     140G   56K  138G   1% /mnt/c
squid75 /mnt # cd c
squid75 /mnt/c # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 27.3223 s, 192 MB/s

real    0m27.326s
user    0m0.011s
sys     0m10.306s
squid75 /mnt/c # ..
squid75 /mnt # umount c         # 时间较长
# btrfs + lvm, nossd
squid75 ~ # vi /etc/fstab
/dev/cs/cs      /mnt/c          btrfs   noatime,nodiratime,nossd 0 0
squid75 /mnt/c # time dd if=/dev/zero of=haha bs=1M count=5000
5000+0 records in
5000+0 records out
5242880000 bytes (5.2 GB) copied, 28.8519 s, 182 MB/s

real    0m28.858s
user    0m0.004s
sys     0m9.376s
squid75 /mnt/c # ..
squid75 /mnt # time umount c

real    0m1.657s
user    0m0.000s
sys     0m1.575s
# 结论:
SSD+lvm的情况下,btrfs效率不如ext4;
btrfs比ext4更依赖内存做缓存, 所以卸载文件系统时需要的时间也更长;
btrfs跨2个设备读写能力是单设备的1.5倍,而不是线性增长;
ext4+lvm(strip 2)写能力是单设备的1.5倍,而非线性增长;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值