測試資料量級:10張表,每張表200萬條資料
使用 Sysbench 對資料庫進行壓測,通常分為三個步驟:
prepare,準備資料
run,運作測試模型
cleanup,清理測試資料
測試環境
IP | 核心 | 記憶體 | 磁盤類型 | |
---|---|---|---|---|
實體伺服器 | 10.63.4.59 | 32 | 128 | 機械磁盤 |
雲平台 | 10.63.4.57 | 2 | 8 | 機械磁盤,分布式存儲GlusterFS |
阿裡雲 | 121.40.191.216 | SSD磁盤 |
環境配置不對等的情況下,在容器啟動時通過參數控制容器所使用的相關資源與雲平台一緻
磁盤性能測試
在測試之前首先對個環境磁盤性能使用fio工具進行測試
以下所有測試測試線程為單線程,檔案大小為1G,以每次4k的io進行測試。
- 實體機
随機讀
fio -direct=1 -iodepth=128 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/opt/rainbond/iotest -name=Rand_Read_Testing
随機寫
fio -direct=1 -iodepth=128 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/opt/rainbond/iotest -name=Rand_Write_Testing
順序讀
fio -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/opt/rainbond/iotest/ -name=Read_PPS_Testing
順序寫
fio -direct=1 -iodepth=64 -rw=write -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/opt/rainbond/iotest/ -name=Write_PPS_Testing
fio -direct=1 -iodepth=128 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/grdata/iotest -name=Rand_Read_Testing
fio -direct=1 -iodepth=128 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/grdata/iotest -name=Rand_Write_Testing
fio -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/grdata/iotest -name=Read_PPS_Testing
fio -direct=1 -iodepth=64 -rw=write -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/grdata/iotest -name=Write_PPS_Testing
fio -direct=1 -iodepth=128 -rw=randread -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/root/iotest -name=Rand_Read_Testing
fio -direct=1 -iodepth=128 -rw=randwrite -ioengine=libaio -bs=4k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/root/iotest -name=Rand_Write_Testing
fio -direct=1 -iodepth=64 -rw=read -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/root/iotest/ -name=Read_PPS_Testing
fio -direct=1 -iodepth=64 -rw=write -ioengine=libaio -bs=1024k -size=1G -numjobs=1 -runtime=1000 -group_reporting -directory=/root/iotest/ -name=Write_PPS_Testing
磁盤性能測試結果
測試内容 | IOPS | BW(平均IO帶寬) | |
---|---|---|---|
2680 | 10.5MiB/s | ||
591 | 2364.6KB/s | ||
17.0k | 66.4MiB/s | ||
3405 | 13.3MiB/s | ||
310 | 1240.1KB/s | ||
16.0k | 66.3MiB/s | ||
311MiB/s | |||
102 | 104742KB/s | ||
301 | 302MiB/s | ||
169 | 169MiB/s | ||
15 | 15515KB/s | ||
303 | 303MiB/s |
資料庫測試環境準備
所有環境資料庫均使用容器化部署
由于該測試實體機記憶體CPU較其他環境具有優勢,是以在測試時将容器記憶體CPU限制為8核心8GB
部署機器資訊:
IP:10.63.4.59
密碼: root123
資料庫端口:3308
資料庫密碼:****
運作資料庫
docker run --name test-mysql -m 8192m --cpu-shares=1966 --cpu-quota 478000 --cpu-period 100000 -p 3308:3306 -e MYSQL_ROOT_PASSWORD=**** -v /var/lib/test-mysql:/var/lib/mysql -e --character-set-server=utf8mb4 -e MYSQL_DATABASE=systest -d mysql:5.7
參數解釋
-m 限制記憶體使用量為8GB
--cpus 限制使用cpu核數為2核
--cpu-shares cpu相對權重
--cpu-quota 指定在一個周期内,cpu最多可以有多少時間用來跑這個容器
--cpu-period 指定容器對CPU的使用要在多長時間内做一次重新配置設定
- 雲平台(共享存儲)
被測資料庫為普通環境在鹹陽應用,Mysql5.7(壓測)
資料庫容器ip: 192.168.142.126
資料庫密碼 : ****
運作主控端:10.63.4.64
- 雲平台(本地存儲)
被測資料庫為普通環境在鹹陽應用,Mysql5.7(本地存儲)
資料庫容器ip: 192.168.142.74
被測機:121.40.191.216
密碼:gr123465!
資料庫端口:3306
運作資料庫:
docker run --name test-mysql -m 8192m --cpu-shares=1966 --cpu-quota 478000 --cpu-period 100000 -p 3308:3306 -e MYSQL_ROOT_PASSWORD=**** -v /var/lib/test-mysql:/var/lib/mysql -e --character-set-server=utf8mb4 -e MYSQL_DATABASE=systest -d mysql:5.7
測試過程
為保證測試結果公平,測試前請在測試機先清理資料
#重新整理髒資料到磁盤
sync
#清除cache
echo 3 >/proc/sys/vm/drop_caches
#釋放swap
swapoff -a && swapon -a
- 測試機資訊
測試機IP:10.63.4.57
密碼:****
- 準備
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.63.4.59 --mysql-port=3308 --mysql-db=systest --threads=100 --report-interval=5 --time=100 prepare
- 運作
插入
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.63.4.59 --mysql-port=3308 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
查詢
sysbench /root/sysbench-1.0/tests/include/oltp_legacy/select.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.63.4.59 --mysql-port=3308 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
删除
sysbench /root/sysbench-1.0/tests/include/oltp_legacy/delete.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.63.4.59 --mysql-port=3308 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
讀寫混合
sysbench /root/sysbench-1.0/src/lua/oltp_read_write.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.63.4.59 --mysql-port=3308 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
- 清理
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.63.4.59 --mysql-port=3308 --mysql-db=systest --threads=100 --report-interval=5 --time=100 cleanup
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.126 --mysql-port=3306 --mysql-db=systest --threads=100 --report-interval=5 --time=100 prepare
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.126 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/tests/include/oltp_legacy/select.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.126 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/tests/include/oltp_legacy/delete.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.126 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/src/lua/oltp_read_write.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.83 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.83 --mysql-port=3306 --mysql-db=systest --threads=100 --report-interval=5 --time=100 cleanup
密碼:wlsj0501!
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.74 --mysql-port=3306 --mysql-db=systest --threads=100 --report-interval=5 --time=100 prepare
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.74 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/tests/include/oltp_legacy/select.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.74 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/tests/include/oltp_legacy/delete.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.74 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/src/lua/oltp_read_write.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.74 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /root/sysbench-1.0/src/lua/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=192.168.142.74 --mysql-port=3306 --mysql-db=systest --threads=100 --report-interval=5 --time=100 cleanup
測試機IP:121.41.106.66
sysbench /usr/share/sysbench/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.11.1.160 --mysql-port=3306 --mysql-db=systest --threads=100 --report-interval=5 --time=100 prepare
sysbench /usr/share/sysbench/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.11.1.160 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /usr/share/sysbench/tests/include/oltp_legacy/select.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.11.1.160 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /usr/share/sysbench/tests/include/oltp_legacy/delete.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.11.1.160 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /usr/share/sysbench/oltp_read_write.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.11.1.160 --mysql-port=3306 --mysql-db=systest --threads=100 --time=100 --report-interval=5 run
sysbench /usr/share/sysbench/oltp_insert.lua --tables=10 --table_size=2000000 --mysql-user=root --mysql-password=**** --mysql-host=10.11.1.160 --mysql-port=3306 --mysql-db=systest --threads=100 --report-interval=5 --time=100 cleanup
測試結果
每秒查詢數 (QPS) | 每秒事務數(TPS) | 平均耗時(ms) | 95%以上語句響應時間(ms) | ||
---|---|---|---|---|---|
10張表,執行insert語句,分别向每張表插入資料200萬。 | 4197.49 | 23.81 | 87.56 | ||
137.64 | 724.32 | 2449.36 | |||
3609.99 | 7.69 | 90.78 | |||
14724.55 | 6.79 | 20.74 | |||
執行select語句,分别從10張表中查詢資料。 | 25552.21 | 3.91 | 1.73 | ||
22851.12 | 4.37 | 2.71 | |||
23886.23 | 4.18 | 2.35 | |||
49049.69 | 2.04 | 3.43 | |||
執行delete語句,分别從10張表中删除資料。 | 14603.18 | 6.84 | 86.00 | ||
11944.01 | 8.37 | 82.69 | |||
13275.33 | 7.53 | 81.48 | |||
45520.04 | 2.20 | ||||
讀寫混合測試 | 7807.77 | 390.39 | 255.92 | 484.44 | |
657.50 | 37.43 | 4667.79 | 8795.93 | ||
5036.15 | 251.81 | 396.89 | 831.46 | ||
24964.83 | 1248.24 | 80.09 | 173.58 | ||
** |