通過測試Block Storage效能,可以協助您更好地理解存放裝置的能力,並對其進行相應的最佳化和調整,以確保最佳效能。測試裸盤可以獲得較為真實的Block Storage效能,本文將介紹如何在Linux系統中使用開源測試載入器FIO測試裸盤的關鍵效能指標,包括IOPS(每秒輸入/輸出操作次數)、輸送量(資料轉送速率)和時延(回應時間)。
FIO(Flexible I/O Tester)是一個開源的、強大的I/O效能測試工具,可以用來對存放裝置進行隨機讀寫、順序讀寫等負載測試。
操作步驟
測試裸盤可以獲得較為真實的Block Storage效能。但如果Block Storage裝置中含有分區、檔案系統以及其他資料,直接使用FIO壓測會導致檔案系統異常以及資料丟失,請在測試前提前建立快照做好資料備份。具體操作,請參見手動建立單個快照。
本操作以公用鏡像Alibaba Cloud Linux 3.2104 LTS 64位作業系統為例,請您根據實際環境進行操作。
遠端連線ECS執行個體。
具體操作,請參見使用Workbench登入Linux執行個體。
運行以下命令,查詢Block Storage的裝置名稱。
sudo fdisk -lu命令輸出中,/dev/vda 為系統硬碟,/dev/vdb 和 /dev/vdc 為資料盤,其中 /dev/vdc 尚未分區。
[ecs-a ]$ sudo fdisk -lu Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: F51132A7-67B1-4650-806D-FD0DE6E1210C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 415743 409600 200M EFI System /dev/vda3 415744 83886046 83470303 39.8G Linux filesystem Disk /dev/vdb: 30 GiB, 32212254720 bytes, 62914560 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: C36DF120-8650-4188-8043-AEF9C85F31EF Device Start End Sectors Size Type /dev/vdb1 2048 62912511 62910464 30G Linux filesystem Disk /dev/vdc: 40 GiB, 42949672960 bytes, 83886080 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes如上述命令輸出所示,該執行個體有3塊Block Storage裝置,系統硬碟/dev/vda、資料盤/dev/vdb、/dev/vdc。
運行以下命令,查詢Block Storage裝置是否存在分區和檔案系統。
sudo blkid[ecs-a ]$ sudo blkid /dev/vdb1: UUID="9c32c24f-d2b8-4aa8-8" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="4bd66635-f5f4-4dc0-9bdd-664fd5b8d2fb" /dev/vda2: SEC_TYPE="msdos" UUID="7E" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="82a50cd6-9899-41eb-91fe-7027bf257086" /dev/vda3: LABEL="root" UUID="beef9d8d-ba84-46d9-8" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="e0d4fa20-912d-4e86-943e-6b0368xxxxxx" /dev/vda1: PARTUUID="d083a7cd-a7ea-4898-89d5-8e1510bed584"如上所示,Block Storage裝置/dev/vda與/dev/vdb上存在分區及檔案系統,而結果中未存在/dev/vdc相關的回執資訊,表明/dev/vdc沒有分區及檔案系統。
在測試Block Storage效能前,請確保已經對測試對象進行資料備份,避免資料丟失。具體操作,請參見手動建立單個快照。
說明使用快照會產生計費,更多資訊,請參見快照計費。
運行以下命令,安裝libaio庫和測試載入器FIO。 樣本如下,請根據不同的系統選擇指令。
Alibaba Cloud Linux 2/3版本、CentOS 6及以上版本
說明CentOS 6作業系統版本結束了生命週期(EOL),按照社區規則,CentOS 6的源地址http://mirror.centos.org/centos-6/內容已移除,您在阿里雲上繼續使用預設配置的CentOS 6的源會發生報錯。如果您需要使用CentOS 6系統中的一些安裝包,則需要手動切換源地址。具體操作,請參見CentOS 6 EOL如何切換源?。
sudo yum install libaio libaio-devel fio -yDebian 9及以上版本、Ubuntu14及以上版本
重要由於Debian9和Debian10結束生命週期(EOL),所以如果您使用的是Debian9和Debian10系統的ECS執行個體,請先切換源地址。具體操作,請參見為CentOS/Debian EOL後切換源地址(合入到對應作業系統)。
sudo apt-get update sudo apt-get install libaio* fio -y-
切換路徑。
cd /tmp 運行效能測試命令,具體的命令請參見下文。
關於雲端硬碟的測試命令,請參見雲端硬碟效能測試命令。
關於本地碟的測試命令,請參見本地碟效能測試命令。
查看測試結果,不同雲端硬碟數值不同,以下代碼塊中給出的數值僅作為樣本
IOPS相關測試結果請參考
IOPS=***內容。以下為fio 隨機寫(Rand_Write)測試結果樣本,其中 write 行的 IOPS=2301 為隨機寫效能關鍵計量:Starting 1 process Jobs: 1 (f=0): [f(1)][100.0%][w=9061KiB/s][w=2265 IOPS][eta 00m:00s] Rand_Write Testing: (groupid=0, jobs=1): err= 0: pid=15900: Tue Nov 19 11:28:24 2024 write: IOPS=2301, BW=9206KiB/s (9427kB/s)(1024MiB/113896msec); 0 zone resets slat (usec): min=2, max=1718, avg= 5.43, stdev= 7.98 clat (usec): min=382, max=119809, avg=55606.05, stdev=7040.12 lat (usec): min=394, max=119812, avg=55611.49, stdev=7039.41 clat percentiles (msec): | 1.00th=[ 9], 5.00th=[ 51], 10.00th=[ 51], 20.00th=[ 51], | 30.00th=[ 51], 40.00th=[ 57], 50.00th=[ 60], 60.00th=[ 61], | 70.00th=[ 61], 80.00th=[ 61], 90.00th=[ 61], 95.00th=[ 61], | 99.00th=[ 63], 99.50th=[ 65], 99.90th=[ 67], 99.95th=[ 77], | 99.99th=[ 101] bw ( KiB/s): min= 9000, max=28976, per=100.00%, avg=9213.14, stdev=1317.97, samples=227 iops : min= 2250, max= 7244, avg=2303.28, stdev=329.49, samples=227 lat (usec) : 500=0.01%, 750=0.01%, 1000=0.01% lat (msec) : 2=0.03%, 4=0.45%, 10=0.52%, 20=0.04%, 50=0.82% lat (msec) : 100=98.11%, 250=0.01%輸送量相關測試結果請參考
BW=***內容,如下所示:Jobs: 1 (f=1): [W(1)][100.0%][w=85.0MiB/s][w=85 IOPS][eta 00m:00s] Write_PPS_Testing: (groupid=0, jobs=1): err= 0: pid=17934: Tue Nov 19 11:32:19 2024 write: IOPS=124, BW=124MiB/s (130MB/s)(1024MiB/8229msec); 0 zone resets slat (usec): min=27, max=4026, avg=94.51, stdev=125.97 clat (msec): min=4, max=1154, avg=513.48, stdev=208.14 lat (msec): min=4, max=1154, avg=513.57, stdev=208.15 clat percentiles (msec): | 1.00th=[ 17], 5.00th=[ 75], 10.00th=[ 93], 20.00th=[ 567], | 30.00th=[ 584], 40.00th=[ 584], 50.00th=[ 584], 60.00th=[ 584], | 70.00th=[ 584], 80.00th=[ 584], 90.00th=[ 592], 95.00th=[ 693], | 99.00th=[ 1062], 99.50th=[ 1099], 99.90th=[ 1133], 99.95th=[ 1150], | 99.99th=[ 1150] bw ( KiB/s): min=30720, max=356352, per=96.43%, avg=122881.25, stdev=65548.59, samples=16 iops : min= 30, max= 348, avg=120.00, stdev=64.01, samples=16 lat (msec) : 10=0.49%, 20=0.68%, 50=2.15%, 100=10.74%, 250=1.86% lat (msec) : 500=3.22%, 750=76.46%, 1000=2.73%, 2000=1.66% cpu : usr=0.89%, sys=0.45%, ctx=1025, majf=0, minf=10 IO depths : 1=0.1%, 2=0.2%, 4=0.4%, 8=0.8%, 16=1.6%, 32=3.1%, >=64=93.8% submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% complete : 0=0.0%, 4=99.9%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0% issued rwts: total=0 1024 0 0 short=0 0 0 0 dropped=0 0 0 0時延相關測試結果請參考lat(usec)內容。延遲相關測試結果請參考總延遲統計行
lat (usec): min=254, max=169188, avg=432.25, stdev=487.95,平均延遲約 432 微秒。Jobs: 1 (f=1): [w(1)][100.0%][w=9169KiB/s][w=2292 IOPS][eta 00m:00s] Rand_Write_Latency_Testing: (groupid=0, jobs=1): err= 0: pid=19530: Tue Nov 19 11:38:31 2024 write: IOPS=2301, BW=9206KiB/s (9427kB/s)(1024MiB/113903msec); 0 zone resets slat (usec): min=2, max=19160, avg= 8.68, stdev=40.53 clat (usec): min=3, max=169175, avg=423.57, stdev=486.23 lat (usec): min=254, max=169188, avg=432.25, stdev=487.95 clat percentiles (usec): | 1.00th=[ 334], 5.00th=[ 343], 10.00th=[ 347], 20.00th=[ 351], | 30.00th=[ 355], 40.00th=[ 359], 50.00th=[ 367], 60.00th=[ 371], | 70.00th=[ 379], 80.00th=[ 396], 90.00th=[ 465], 95.00th=[ 562], | 99.00th=[ 1614], 99.50th=[ 2671], 99.90th=[ 5735], 99.95th=[ 6194], | 99.99th=[ 7439] bw ( KiB/s): min= 5840, max=10416, per=100.00%, avg=9211.26, stdev=495.72, samples=227 iops : min= 1460, max= 2604, avg=2302.80, stdev=123.94, samples=227 lat (usec) : 4=0.01%, 10=0.01%, 50=0.01%, 100=0.01%, 250=0.01% lat (usec) : 500=93.01%, 750=4.06%, 1000=0.97% lat (msec) : 2=1.23%, 4=0.42%, 10=0.30%, 20=0.01%, 50=0.01% lat (msec) : 250=0.01% cpu : usr=0.84%, sys=3.00%, ctx=262469, majf=0, minf=10
雲端硬碟效能測試命令
樣本命令中的參數取值僅供參考,/dev/your_device請您根據實際情況,替換為操作步驟2中擷取的待測試Block Storage名稱。例如,如果需要測試的雲端硬碟裝置名稱為/dev/vdb,則需將以下樣本命令中的/dev/your_device替換為/dev/vdb。FIO參數的更多資訊,請參見FIO參數說明。
測試雲端盤的隨機寫IOPS:
sudo fio -direct=1 -iodepth=128 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=Rand_Write_Testing測試雲端盤的隨機讀IOPS:
sudo fio -direct=1 -iodepth=128 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=Rand_Read_Testing測試雲端盤的順序寫輸送量:
sudo fio -direct=1 -iodepth=64 -rw=write -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=Write_PPS_Testing測試雲端盤的順序讀輸送量:
sudo fio -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=Read_PPS_Testing測試雲端盤的隨機寫時延:
sudo fio -direct=1 -iodepth=1 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/dev/your_device -name=Rand_Write_Latency_Testing測試雲端盤的隨機讀時延:
sudo fio -direct=1 -iodepth=1 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/dev/your_device -name=Rand_Read_Latency_Testing
關於各雲端硬碟詳細的測試步驟,請參見測試ESSD雲端硬碟IOPS效能。
本地碟效能測試命令
以下測試命令適用於NVMe SSD本地碟和SATA HDD本地碟。樣本命令中的參數取值僅供參考,/dev/your_device請您根據實際情況,替換為操作步驟2中擷取的待測試Block Storage名稱。例如,如果需要測試的本地碟裝置名稱為/dev/vdb,則需將以下樣本命令中的/dev/your_device替換為/dev/vdb。FIO參數的更多資訊,請參見FIO參數說明。
測試本地碟的隨機寫IOPS:
sudo fio -direct=1 -iodepth=32 -rw=randwrite -ioengine=libaio -bs=4k -numjobs=4 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test測試本地碟的隨機讀IOPS:
sudo fio -direct=1 -iodepth=32 -rw=randread -ioengine=libaio -bs=4k -numjobs=4 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test測試本地碟的順序寫輸送量:
sudo fio -direct=1 -iodepth=128 -rw=write -ioengine=libaio -bs=128k -numjobs=1 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test測試本地碟的順序讀輸送量:
sudo fio -direct=1 -iodepth=128 -rw=read -ioengine=libaio -bs=128k -numjobs=1 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test測試本地碟的隨機寫時延:
sudo fio -direct=1 -iodepth=1 -rw=randwrite -ioengine=libaio -bs=4k -numjobs=1 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test測試本地碟的隨機讀時延:
sudo fio -direct=1 -iodepth=1 -rw=randread -ioengine=libaio -bs=4k -numjobs=1 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test測試本地碟的順序寫時延:
sudo fio -direct=1 -iodepth=1 -rw=write -ioengine=libaio -bs=4k -numjobs=1 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test測試本地碟的順序讀時延:
sudo fio -direct=1 -iodepth=1 -rw=read -ioengine=libaio -bs=4k -numjobs=1 -time_based=1 -runtime=1000 -group_reporting -filename=/dev/your_device -name=test
FIO參數說明
測試命令中有關FIO各參數含義的說明如下表所示。
參數 | 說明 |
direct | 表示是否使用direct I/O。預設值:1。
|
iodepth | 表示測試時的IO隊列深度。例如 |
rw | 表示測試時的讀寫策略。您可以設定為:
|
ioengine | 表示測試時FIO選擇哪種I/O引擎,通常選擇libaio,更符合日常應用模式,更多的選擇請查閱FIO官方文檔。 |
bs | 表示I/O單元的塊大小(block size)。預設值:4 KiB。讀取和寫入的值可以以read、write格式單獨指定,其中任何一個都可以為空白以將該值保留為其預設值。 |
size | 表示測試檔案大小。 FIO會將指定的檔案大小全部讀/寫完成,然後才停止測試,除非受到其他選項(例如運行時)的限制。如果未指定該參數,FIO將使用給定檔案或裝置的完整大小。也可以將大小作為1到100之間的百分比給出。例如指定size=20%,FIO將使用給定檔案或裝置完整大小的20%空間。 |
numjobs | 表示測試的並發線程數。預設值:1。 |
runtime | 表示測試時間,即FIO運行時間長度。 如果未指定該參數,則FIO會持續將上述size指定大小的檔案,以每次bs值為塊大小讀/寫完成。 |
group_reporting | 表示測試結果顯示模式。 如果指定該參數,測試結果會匯總每個進程的統計資訊,而不是以不同任務來統計資訊。 |
filename | 表示待測試的物件路徑,路徑可以是雲端硬碟裝置名稱或者一個檔案地址。本文中的FIO測試全部是以整盤為測試對象,不含檔案系統,即裸盤測試。同時為了避免誤測試到其他盤導致資料被破壞,本樣本地址為/dev/your_device,請您正確替換。 |
name | 表示測試工作名稱,可以隨意設定。例如本樣本的Rand_Write_Testing。 |
有關各參數的更多說明,請參見FIO MAN手冊。