我在物理機上創建了5台虛擬機,搭建了一個ceph集群,結構如圖:
具體的安裝步驟參考文檔:http://docs.ceph.org.cn/start/
http://www.centoscn.com/CentosServer/test/2015/0521/5489.html
一、磁盤讀寫性能
1. 單個osd磁盤寫性能
[root@lrr-ceph1 osd]# echo 3 > /proc/sys/vm/drop_caches #清除緩存頁,目錄項和inodes
[root@lrr-ceph1 osd]# dd if=/dev/zero of=/var/lib/ceph/osd/lrr01 bs=1G count=1 oflag=direct #執行寫命令
注:兩個OSD同時寫性能
[root@lrr-ceph1 osd]# for i in `mount | grep osd | awk '{print $3}'`; do (dd if=/dev/zero of=$i/lrr01 bs=1G count=1 oflag=direct $) ; done
2. 單個OSD同時讀性能
[root@lrr-ceph1 osd]# dd if=/var/lib/ceph/osd/lrr01 of=/dev/null bs=2G count=1 iflag=direct
0+1 records in
0+1 records out
1073741824 bytes (1.1 GB) copied, 7.13509 s, 150 MB/s
注:兩個OSD同時讀性能
[root@lrr-ceph1 osd]# for i in `mount | grep osd | awk '{print $3}'`; do (dd if=$i/lrr01 of=/dev/null bs=1G count=1 iflag=direct &); done
二、CEPH 性能測試方法
ceph性能的測試包括:RADOS性能測試和RBD性能測試;
Rados性能測試工具:使用ceph自帶的rados bench工具、使用rados losd-gen工具;
RBD性能測試工具:rbd bench-write進行塊設備寫性能測試、fio+rbd ioengine測試、fio +libaio測試。
1. Rados性能測試
1.1 使用ceph自帶的rados bench工具進行測試
該工具的語法是:rados bench -p <pool_name> <seconds> <write|seq|rand> -b <block size> -t --no-cleanup
pool_name:測試所針對的存儲池;
seconds:測試所持續的秒數;
<write|seq|rand>:操作模式,write:寫,seq:順序讀;rand:隨機讀;
-b:block size,即塊大小,默認為 4M;
-t:讀/寫並行數,默認為 16;
--no-cleanup 表示測試完成后不刪除測試用數據。在做讀測試之前,需要使用該參數來運行一遍寫測試來產生測試數據,在全部測試結束后可以運行 rados -p <pool_name> cleanup 來清理所有測試數據。
i 寫測試:
[root@lrr-ceph2 ~]# rados bench -p rbd 10 write --no-cleanup
Maintaining 16 concurrent writes of 4194304 bytes to objects of size 4194304 for up to 10 seconds or 0 objects
Object prefix: benchmark_data_lrr-ceph2_4445
sec Cur ops started finished avg MB/s cur MB/s last lat(s) avg lat(s)
0 0 0 0 0 0 - 0
1 16 16 0 0 0 - 0
2 16 16 0 0 0 - 0
。。。。
17 13 19 6 1.41038 0 - 10.7886
18 13 19 6 1.33207 0 - 10.7886
19 13 19 6 1.26201 0 - 10.7886
Total time run: 19.698032
Total writes made: 19
Write size: 4194304
Object size: 4194304
Bandwidth (MB/sec): 3.85825
Stddev Bandwidth: 0.551976
Max bandwidth (MB/sec): 1.71429
Min bandwidth (MB/sec): 0
Average IOPS: 0
Stddev IOPS: 0
Max IOPS: 0
Min IOPS: 0
Average Latency(s): 15.5797
Stddev Latency(s): 5.09105
Max latency(s): 19.6971
Min latency(s): 5.51094
ii 順序讀測試:
iii 隨機讀測試:
1.2 rados load-gen 工具
該工具的語法為:
# rados -p rbd load-gen --num-objects 初始生成測試用的對象數,默認 200 --min-object-size 測試對象的最小大小,默認 1KB,單位byte --max-object-size 測試對象的最大大小,默認 5GB,單位byte --min-op-len 壓測IO的最小大小,默認 1KB,單位byte --max-op-len 壓測IO的最大大小,默認 2MB,單位byte --max-ops 一次提交的最大IO數,相當於iodepth --target-throughput 一次提交IO的歷史累計吞吐量上限,默認 5MB/s,單位B/s --max-backlog 一次提交IO的吞吐量上限,默認10MB/s,單位B/s --read-percent 讀寫混合中讀的比例,默認80,范圍[0, 100] --run-length 運行的時間,默認60s,單位秒
在 ceph1上運行
rados -p pool100 load-gen --read-percent 0 --min-object-size 1073741824 --max-object-size 1073741824 --max-ops 1 --read-percent 0 --min-op-len 4194304 --max-op-len 4194304 --target-throughput 1073741824 --max_backlog 1073741824
的結果為:
WRITE : oid=obj-y0UPAZyRQNhnabq off=929764660 len=4194304 op 19 completed, throughput=16MB/sec WRITE : oid=obj-nPcOZAc4ebBcnyN off=143211384 len=4194304 op 20 completed, throughput=20MB/sec WRITE : oid=obj-sWGUAzzASPjCcwF off=343875215 len=4194304 op 21 completed, throughput=24MB/sec WRITE : oid=obj-79r25fxxSMgVm11 off=383617425 len=4194304 op 22 completed, throughput=28MB/sec
該命令的含義是:在 1G 的對象上,以 iodepth = 1 順序寫入 block size 為 4M 的總量為 1G 的數據。其平均結果大概在 24MB/s,基本和 rados bench 的結果相當。
在 client 上,同樣的配置,順序寫的BW大概在 20MB/s,順序讀的 BW 大概在 100 MB/s。
可見,與 rados bench 相比,rados load-gen 的特點是可以產生混合類型的測試負載,而 rados bench 只能產生一種類型的負載。但是 load-gen 只能輸出吞吐量,只合適做類似於 4M 這樣的大block size 數據測試,輸出還不包括延遲。
2 rbd性能測試
2.1 使用rbd bench-write 進行塊設備寫性能測試
2.1.1 客戶端准備
在執行如下命令來准備 Ceph 客戶端:
root@client:/var# rbd create bd2 --size 1024 root@client:/var# rbd info --image bd2 rbd image 'bd2': size 1024 MB in 256 objects order 22 (4096 kB objects) block_name_prefix: rb.0.3841.74b0dc51 format: 1 root@client:/var# rbd map bd2 root@client:/var# rbd showmapped id pool image snap device 1 pool1 bd1 - /dev/rbd1 2 rbd bd2 - /dev/rbd2 root@client:/var# mkfs.xfs /dev/rbd2 log stripe unit (4194304 bytes) is too large (maximum is 256KiB) log stripe unit adjusted to 32KiB meta-data=/dev/rbd2 isize=256 agcount=9, agsize=31744 blks = sectsz=512 attr=2, projid32bit=0 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=1024 swidth=1024 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 root@client:/var# mkdir -p /mnt/ceph-bd2 root@client:/var# mount /dev/rbd2 /mnt/ceph-bd2/ root@client:/var# df -h /mnt/ceph-bd2/ Filesystem Size Used Avail Use% Mounted on /dev/rbd2 1014M 33M 982M 4% /mnt/ceph-bd2
2.1.2 測試
rbd bench-write 的語法為:rbd bench-write <RBD image name>,可以帶如下參數:
- --io-size:單位 byte,默認 4096 bytes = 4K
- --io-threads:線程數,默認 16
- --io-total:總寫入字節,單位為字節,默認 1024M
- --io-pattern <seq|rand>:寫模式,默認為 seq 即順序寫
分別在集群 OSD 節點上和客戶端上做測試:
(1)在 OSD 節點上做測試
root@ceph1:~# rbd bench-write bd2 --io-total 171997300 bench-write io_size 4096 io_threads 16 bytes 171997300 pattern seq SEC OPS OPS/SEC BYTES/SEC 1 280 273.19 2237969.65 2 574 286.84 2349818.65 ... 71 20456 288.00 2358395.28 72 20763 288.29 2360852.64 elapsed: 72 ops: 21011 ops/sec: 288.75 bytes/sec: 2363740.27
此時,塊大小為 4k,IOPS 為 289,BW 為 2.36 MB/s (怎么 BW 是 block_size * IOPS 的兩倍呢?)。
(2)在客戶端上做測試
root@client:/home/s1# rbd bench-write pool.host/image.ph2 --io-total 1719973000 --io-size 4096000 bench-write io_size 4096000 io_threads 16 bytes 1719973000 pattern seq SEC OPS OPS/SEC BYTES/SEC 1 5 3.41 27937685.86 2 19 9.04 68193147.96 3 28 8.34 62237889.75 5 36 6.29 46538807.31 ... 39 232 5.86 40792216.64 40 235 5.85 40666942.19 elapsed: 41 ops: 253 ops/sec: 6.06 bytes/sec: 41238190.87
此時 block size 為 4M,IOPS 為 6, BW 為 41.24 MB/s。
root@client:/home/s1# rbd bench-write pool.host/image.ph2 --io-total 1719973000 bench-write io_size 4096 io_threads 16 bytes 1719973000 pattern seq SEC OPS OPS/SEC BYTES/SEC 1 331 329.52 2585220.17 2 660 329.57 2521925.67 3 1004 333.17 2426190.82 4 1331 332.26 2392607.58 5 1646 328.68 2322829.13 6 1986 330.88 2316098.66
此時 block size 為 4K,IOPS 為 330 左右, BW 為 24 MB/s 左右。
備注:從 rbd bench-write vs dd performance confusion 中看起來,rados bench-write 似乎有bug。我所使用的Ceph 是0.80.11 版本,可能補丁還沒有合進來。
2 使用fio+rbd ioengine
運行 apt-get install fio 來安裝 fio 工具。創建 fio 配置文件:
root@client:/home/s1# cat write.fio [write-4M] description="write test with block size of 4M" ioengine=rbd clientname=admin pool=rbd rbdname=bd2 iodepth=32 runtime=120 rw=write #write 表示順序寫,randwrite 表示隨機寫,read 表示順序讀,randread 表示隨機讀 bs=4M
運行 fio 命令,但是出錯:
root@client:/home/s1# fio write.fio fio: engine rbd not loadable fio: failed to load engine rbd Bad option <clientname=admin> Bad option <pool=rbd> Bad option <rbdname=bd2> fio: job write-4M dropped fio: file:ioengines.c:99, func=dlopen, error=rbd: cannot open shared object file: No such file or directory
其原因是因為沒有安裝 fio librbd IO 引擎,因此當前 fio 無法支持 rbd ioengine:
root@client:/home/s1# fio --enghelp Available IO engines: cpuio mmap sync psync vsync pvsync null net netsplice libaio rdma posixaio falloc e4defrag splice sg binject
在運行 apt-get install librbd-dev 命令安裝 librbd 后,fio 還是報同樣的錯誤。參考網上資料,下載 fio 代碼重新編譯 fio:
$ git clone git://git.kernel.dk/fio.git $ cd fio $ ./configure [...] Rados Block Device engine yes [...] $ make
此時 fio 的 ioengine 列表中也有 rbd 了。fio 使用 rbd IO 引擎后,它會讀取 ceph.conf 中的配置去連接 Ceph 集群。
下面是 fio 命令和結果:
root@client:/home/s1/fio# ./fio ../write.fio write-4M: (g=0): rw=write, bs=4M-4M/4M-4M/4M-4M, ioengine=rbd, iodepth=32 fio-2.11-12-g82e6 Starting 1 process rbd engine: RBD version: 0.1.8 Jobs: 1 (f=1): [W(1)] [100.0% done] [0KB/128.0MB/0KB /s] [0/32/0 iops] [eta 00m:00s] write-4M: (groupid=0, jobs=1): err= 0: pid=19190: Sat Jun 4 22:30:00 2016 Description : ["write test with block size of 4M"] write: io=1024.0MB, bw=17397KB/s, iops=4, runt= 60275msec slat (usec): min=129, max=54100, avg=1489.10, stdev=4907.83 clat (msec): min=969, max=15690, avg=7399.86, stdev=1328.55 lat (msec): min=969, max=15696, avg=7401.35, stdev=1328.67 clat percentiles (msec): | 1.00th=[ 971], 5.00th=[ 6325], 10.00th=[ 6325], 20.00th=[ 6521], | 30.00th=[ 6718], 40.00th=[ 7439], 50.00th=[ 7439], 60.00th=[ 7635], | 70.00th=[ 7832], 80.00th=[ 8291], 90.00th=[ 8356], 95.00th=[ 8356], | 99.00th=[14615], 99.50th=[15664], 99.90th=[15664], 99.95th=[15664], | 99.99th=[15664] bw (KB /s): min=245760, max=262669, per=100.00%, avg=259334.50, stdev=6250.72 lat (msec) : 1000=1.17%, >=2000=98.83% cpu : usr=0.24%, sys=0.03%, ctx=50, majf=0, minf=8 IO depths : 1=2.3%, 2=5.5%, 4=12.5%, 8=25.0%, 16=50.4%, 32=4.3%, >=64=0.0% 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=97.0%, 8=0.0%, 16=0.0%, 32=3.0%, 64=0.0%, >=64=0.0% issued : total=r=0/w=256/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0 latency : target=0, window=0, percentile=100.00%, depth=32 Run status group 0 (all jobs): WRITE: io=1024.0MB, aggrb=17396KB/s, minb=17396KB/s, maxb=17396KB/s, mint=60275msec, maxt=60275msec Disk stats (read/write): sda: ios=0/162, merge=0/123, ticks=0/19472, in_queue=19472, util=6.18%