前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >通过RAID或者LVM提高云硬盘读写性能

通过RAID或者LVM提高云硬盘读写性能

原创
作者头像
隔壁没老王
发布2025-01-21 16:23:59
发布2025-01-21 16:23:59
1250
举报

背景

查看腾讯云云硬盘文档可以发现,高性能云硬盘的上限为 150MB/s,SSD的上限为 260MB/s,SSD性能是高性能的大约1.7倍,

但是要查看 价钱的话,SSD是高性能的大约2.8倍


那么我们如何花更少的money,实现更高的性能,这里的方法是叠加2块高性能云硬盘来实现300MB/s的读写速度。

接下来我们看看如何实现:


  • 系统环境 系统:CentOS Linux release 7.9.2009 (Core) 数据盘:500G高性能*2

方法一:通过RAID 提搞读写性能

我们这里使用的是软RAID,也就是通过软件方式实现。

需要使用raid0 ,raid1不适用。

关于RAID介绍可参考文档

代码语言:shell
复制
1、安装raid工具
[root@test ~]# yum install mdadm -y 

2、创建raid
[root@test ~]# mdadm --create /dev/md0 --level=0 --raid-devices=2  /dev/vd[b,c]
/dev/md0:raid设备
--level=0:raid级别,指定raid0
--raid-devices=2 :指定用2块设备组成raid0
/dev/vd[b,c]  : 具体是哪2块设备,这里是vdb和vdc

3、格式化
[root@test ~]# mkfs.ext4  /dev/md0 

4、挂载
[root@test ~]# mount /dev/md0  /data/

5、测试
[root@test ~]# dd if=/dev/zero  of=/data/aaa bs=100M count=100
100+0 records in
100+0 records out
10485760000 bytes (10 GB) copied, 30.1766 s, 347 MB/s
[root@test ~]# 

###结果可以到347 MB/s。

6、也可以用iostat命令查看实时的硬盘读写速度
[root@test ~]# iostat  -x 1 
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.51    0.00   12.12   80.81    0.00    6.57

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
vda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
scd0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
vdb               0.00     0.00    0.00  600.00     0.00 153600.00   512.00   252.78  421.30    0.00  421.30   1.58  95.10
vdc               0.00     0.00    0.00  602.00     0.00 154112.00   512.00   251.39  417.60    0.00  417.60   1.54  92.70
md0               0.00     0.00    0.00 1196.00     0.00 306176.00   512.00     0.00    0.00    0.00    0.00   0.00   0.00

### 可以看到2块磁盘组成的md0的写入速度是 306176kB/s
### vdb和vdc这2块磁盘的写入速度各为150MB/s左右

方法二:通过LVM 提高读写性能

LVM 逻辑卷有两种读写策略:线性和条带。

线性方式(linear):以一块盘为基础进行读写。当数据写入到一个物理卷(盘)时,写满后才会开始写入下一个物理卷。这种方式的性能较低,因为它无法充分利用多个盘的并行读写能力。

条带方式(striped):以多块盘并行读写数据。数据被分成大小相等的条带,然后同时写入到多个物理卷中的相应条带位置。这样可以充分利用多个盘的并行读写能力,从而提高读写性能。

参考文档:https://blog.csdn.net/hezuijiudexiaobai/article/details/131793079


这里必须得使用条带方式(striped),要不然无法发挥2块盘的全部性能。

  • 测试线性方式(linear)的读写性能
代码语言:shell
复制
1、创建pv
[root@test ~]# pvcreate /dev/vd[b,c]
2、创建vg
[root@test ~]# vgcreate lvm_vg /dev/vd[b,c]
3、创建lv
[root@test ~]# lvcreate -L 999G -n lvm_lv lvm_vg
4、格式化
[root@test ~]# mkfs.ext4  /dev/lvm_vg/lvm_lv 
5、挂载
[root@test ~]# mount /dev/lvm_vg/lvm_lv /data/
6、测试读写性能
[root@test ~]# dd if=/dev/zero  of=/data/aaa bs=100M count=100
100+0 records in
100+0 records out
10485760000 bytes (10 GB) copied, 61.1841 s, 171 MB/s
# 大概是171 MB/s,达不到我们想要的效果。
# 使用iostat查看,只有1块磁盘在写入
Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
vda               0.00    13.00    0.00    4.00     0.00    68.00    34.00     0.01    1.50    0.00    1.50   1.00   0.40
scd0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
vdb               0.00    19.00    0.00  318.00     0.00 153128.00   963.07   245.55  772.16    0.00  772.16   3.15 100.10
vdc               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
dm-0              0.00     0.00    0.00  334.00     0.00 151060.00   904.55   275.06  742.75    0.00  742.75   2.99 100.00
  • 测试条带方式(striped) 的读写性能
代码语言:shell
复制
### 条带方式(striped)和线性方式(linear) 的创建区别就是创建lv的时候需要使用-i指定stripes 参数,几块磁盘就指定为几。

1、其他步骤省略,创建lv:
[root@test ~]# lvcreate -i 2 -L 999G -n lvm_lv lvm_vg

2、测试写入速度
[root@test ~]# dd if=/dev/zero  of=/data/aaa bs=100M count=100
100+0 records in
100+0 records out
10485760000 bytes (10 GB) copied, 29.9987 s, 350 MB/s
[root@test ~]# 

# 使用iostat命令查看io分布在2块磁盘,各150M左右,dm-0的写入速度在 300MB左右,符合预期。
Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
vda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
scd0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
vdb               0.00  2077.00    2.00  346.00     8.00 153200.00   880.51   262.75  755.04   20.50  759.29   2.87  99.80
vdc               0.00  2077.00    0.00  344.00     0.00 153472.00   892.28   252.73  734.68    0.00  734.68   2.84  97.80
dm-0              0.00     0.00    2.00 4848.00     8.00 310272.00   127.95  3513.06  748.45   20.50  748.75   0.21 100.00
  • 补充

?如何查看自己的lv 是条带方式(striped)还是 线性方式(linear) ?

lvdisplay -m 命令查看 --- Segments --- 的 Type。

代码语言:shell
复制
### 条带方式(striped)
root@test ~]# lvdisplay  -m 
  --- Logical volume ---
  LV Path                /dev/lvm_vg/lvm_lv
  LV Name                lvm_lv
  VG Name                lvm_vg
  LV UUID                YVjhDa-eOt1-K849-Ej3E-cpIc-CVFR-kM8L2d
  LV Write Access        read/write
  LV Creation host, time test, 2025-01-21 15:58:03 +0800
  LV Status              available
  # open                 1
  LV Size                999.00 GiB
  Current LE             255744
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:0
   
  --- Segments ---
  Logical extents 0 to 255743:
    Type                striped
    Stripes             2
    Stripe size         64.00 KiB
    Stripe 0:
      Physical volume   /dev/vdb
      Physical extents  0 to 127871
    Stripe 1:
      Physical volume   /dev/vdc
      Physical extents  0 to 127871


###  线性方式(linear)
[root@test ~]# lvdisplay  -m /dev/lvm_vg/lvm_lv 
  --- Logical volume ---
  LV Path                /dev/lvm_vg/lvm_lv
  LV Name                lvm_lv
  VG Name                lvm_vg
  LV UUID                dtbUBV-MTvp-pBA8-lOy4-4bD3-3uZD-TmiKfj
  LV Write Access        read/write
  LV Creation host, time test, 2025-01-21 16:08:59 +0800
  LV Status              available
  # open                 1
  LV Size                999.00 GiB
  Current LE             255744
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:0
   
  --- Segments ---
  Logical extents 0 to 127998:
    Type                linear
    Physical volume     /dev/vdb
    Physical extents    0 to 127998
   
  Logical extents 127999 to 255743:
    Type                linear
    Physical volume     /dev/vdc
    Physical extents    0 to 127744
   
   
[root@test ~]# 

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 背景
    • 方法一:通过RAID 提搞读写性能
    • 方法二:通过LVM 提高读写性能
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档