mysql性能測試報告


1. 測試目的

對mysql數據庫進行基准測試,各性能指標進行定量的、可復現的、可對比的測試。

基准測試可以理解為針對系統的一種壓力測試。但基准測試不關心業務邏輯,更加簡單、直接、易於測試,

數據可以由工具生成,不要求真實;而壓力測試一般考慮業務邏輯(如購物車業務),要求真實的數據。

2. 測試環境

2.1 軟件配置

2.1 硬件配置

3. 測試工具

3.1 工具介紹sysbench

       本次測試采用通用工具SysBench,是跨平台的基准測試工具,支持多線程,支持多種數據庫;

對數據庫的基准測試的作用,就是分析在當前的配置下(包括硬件配置、OS、數據庫設置等) 數據庫的性能表現,

從而找出MySQL的性能閾值,並根據實際系統的要求調整硬件配置。

3.2 測試指標

TPS:Transaction Per Second,事務數/秒

一台數據庫服務器在單位時間內處理事務的個數,每個事務包含18條SQL語句。

QPS:Query Per Second, 查詢量/秒

每秒執行的查詢次數,是對服務器在規定時間內所處理查詢量多少的衡量標准,即數據庫每秒執行的SQL數,包含insert、select、update、delete等。

響應時間:包括平均響應時間、最小響應時間、最大響應時間、時間百分比等,其中時間百分比參考意義較大,如前95%的請求的最大響應時間。

並發量:同時處理的查詢請求的數量。

4. 安裝步驟

 1 #cd /opt  2 #下載sysbench包  3 #wget -c https://github.com/akopytov/sysbench/archive/1.0.12.zip -O "sysbench-1.0.12.zip"  4 #安裝依賴項  5 #yum install autoconf libtool mysql mysql-devel vim unzip  6 #解壓文件包  7 #unzip  sysbench-1.0.12.zip  8 #編譯  9 #cd sysbench-1.0.12 10 #./autogen.sh 11 #./configure 12 #make 13 #make install

 上述命令依次執行,安裝完成。查找測試腳本所在路徑:

  #find / -name '*oltp.lua*'

 例如:/opt/sysbench-1.0.12/tests/include/oltp_legacy/oltp.lua

 然后進入 cd /opt/sysbench-1.0.12,開始測試。

5. 參數說明

sysbenh測試工具命令,根據測試需要調整參數sysbench [options]... [testname] [command]

sysbench --help 查看命令的基本參數

表5-1

選項[options]

備注

--test

腳本路徑 oltp.lua

--mysql-db

測試庫名稱

--mysql-host

數據庫IP地址

--mysql-port

端口號 默認3306

--mysql-user

數據庫用戶名,一般是root

--mysql-password

數據庫密碼

在老版本的sysbench中,可以通過--test參數指定測試的腳本;

而在新版本中,--test參數已經聲明為廢棄,可以不使用--test,而是直接指定腳本。如下兩種結果相同

  

表5-2

測試項[testname]

備注

--oltp-tables-count

建表數量

--oltp-table-size

每張表的數據量,默認[10000]

--time=N

限制的總執行時間,默認為10s

--threads=N

需要使用的線程數,默認為1

--report-interval=N

指定間隔(秒)報告統計信息,默認為0,禁用

--oltp-test-mode=complex

測試模式,默認complex

--oltp-test-mode 運行模式包括:

simple   模式下只測試簡單的查詢;

nontrx   不僅測試查詢,還測試插入更新等,但是不使用事務;

complex 模式下測試最全面,會測試增刪改查,而且會使用事務。

備注:如果需要特別測試服務器只讀性能,或不使用事務時的性能,可以

選擇simple模式或nontrx模式。

表5-3

命令[command]

備注

prepare

准備測試數據

run

執行測試

cleanup

清理數據

6. 測試方法

6.1 准備測試數據

先登陸mysql數據庫:

#mysql -uroot -p密碼 -h 主機ip

執行show global variables統計各參數配置:show global status

創建測試庫sbtest:

>create database sbtest;

查看所有庫名:

>show databases;

exit退出mysql,進入目錄 cd /opt/sysbench-1.0.12

開始測試前,首先要生成測試數據,

執行以下命令:

#sysbench --test=/opt/sysbench-1.0.12/tests/include/oltp_legacy/oltp.lua --mysql-db=sbtest --mysql-host=ip  --mysql-port=3306 --mysql-user=root --mysql-password=密碼  --oltp-test-mode=complex --oltp-tables-count=200 --oltp-table-size=100000 --report-interval=2 prepare

其中,prepare表示准備數據,在的sbtest庫生成測試數據,

創建200張表,每張表10萬條數據,每2秒顯示一次報告。

注意這里不需要設置運行時間(time),執行時間受建表數量影響。

運行過程如下圖所示:

 6.2 建表語句

數據准備階段建表結構如下:

CREATE TABLE `sbtest` (

`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,

`k` INTEGER UNSIGNED DEFAULT '0' NOT NULL,

`c` CHAR(120) DEFAULT '' NOT NULL,

`pad` CHAR(60) DEFAULT '' NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB;

說明:以上SQL無需執行建表,在下面介紹測試方法,數據准備階段,執行命令時工具自動安照上面描述格式創建表。

6.3 執行測試方法

測試命令如下:

#sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-db=sbtest --mysql-host=ip  --mysql-port=3306 --mysql-user=root --mysql-password=密碼

--oltp-test-mode=complex --time=60 --threads=1 --report-interval=2 run

其中, run表示運行測試,單線程 運行60秒。

--oltp-tables-count(表個數)

--oltp-table-size(表數據量)

這兩個參數用於准備階段創建表的大小,在運行階段不受影響,故run階段可以取消這兩個參數,結果不受影響。

輸出結果如下圖:

由上圖可知,單線程下TPS為33,QPS為660;

6.3.1 測試事務包含的SQL

Sysbench自帶測試腳本,路徑如下/opt/sysbench-1.0.12/tests/include/oltp_legacy/oltp.lua

默認提交的事務中包含18條SQL語句:

主鍵SELECT語句,10條:

SELECT c FROM ${rand_table_name} where id=${rand_id};

范圍SELECT語句,4條:

SELECT c FROM ${rand_table_name} WHERE id BETWEEN ${rand_id_start} AND ${rand_id_end};

SELECT SUM(K) FROM ${rand_table_name} WHERE id BETWEEN ${rand_id_start} AND ${rand_id_end};

SELECT c FROM ${rand_table_name} WHERE id BETWEEN ${rand_id_start} AND ${rand_id_end} ORDER BY c;

SELECT DISTINCT c FROM ${rand_table_name} WHERE id BETWEEN ${rand_id_start} AND ${rand_id_end} ORDER BY c;

UPDATE語句,2條:

UPDATE ${rand_table_name} SET k=k+1 WHERE id=${rand_id}

UPDATE ${rand_table_name} SET c=${rand_str} WHERE id=${rand_id}

DELETE語句,1條:

DELETE FROM ${rand_table_name} WHERE id=${rand_id}

INSERT語句,1條:

INSERT INTO ${rand_table_name} (id, k, c, pad) VALUES (${rand_id},${rand_k},${rand_str_c},${rand_str_pad});

6.3.2 清理測試數據

#sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-db=sbtest --mysql-host=ip

--mysql-port=3306 --mysql-user=root --mysql-password=密碼 --oltp-tables-count=600 cleanup

其中,cleanup表示清理數據,這里不需要設置運行時間(time),只需設置表的數量即可,

此時需表的數量>=准備階段表的數量,才能全部清除測試數據,以免對下次結果產生影響;

7. 測試用例

7.1 測試用例(一)

 

測試用例1:創建6張表每表預置1000萬行數據測試

測試目的

對大表進行增刪改查場景下的QPS和TPS

前置條件

7張表,每張表1000萬行數據,每次修改並發數

步驟

1.准備測試數據(8張表會提示空間不足,因為存儲只有40G)

sysbench

--test=/opt/sysbench1.0.12/tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest --mysql-host=ip  --mysql-port=3306

--mysql-user=root --mysql-password=密碼 

--oltp-test-mode=complex   --oltp-tables-count=7 

--oltp-table-size=10000000  --report-interval=2 prepare

2.運行測試

sysbench ./tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest   --mysql-host=IP --mysql-port=3306

--mysql-user=root    --mysql-password=密碼

--oltp-test-mode=complex --time=600 

--threads=32 --report-interval=2 --oltp-tables-count=64 run

3.記錄結果,並依次增加線程數threads分別記錄線程數為 1/ 16/ 32/ 64/ 128 ……情況下的指標及資源情況

4.清除測試數據

sysbench ./tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest --mysql-host=IP --mysql-port=3306

--mysql-user=root    --mysql-password=密碼

--oltp-tables-count=7 cleanup

參數化變量

--threads:線程數,增加線程數觀察瓶頸

獲取指標

1、TPS

2、QPS

3、總事務數

4、前95%延遲時間

7.2 測試用例(二)

 

測試用例2:創建6張表每表預置100萬行數據測試

測試目的

與用例1進行對比,觀察表數據量的多少,對結果是否有影響

前置條件

7張表,每張表10萬行數據,每次修改並發數

步驟

1.准備測試數據

sysbench

--test=/opt/sysbench-1.0.12/tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest --mysql-host=IP  --mysql-port=3306

--mysql-user=root  --mysql-password=密碼 

--oltp-test-mode=complex  --oltp-tables-count=7 

--oltp-table-size=100000  --report-interval=2 prepare

2.運行測試

sysbench ./tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest --mysql-host=IP --mysql-port=3306

--mysql-user=root --mysql-password=密碼

--oltp-test-mode=complex --time=600--threads=32 

--report-interval=2 --oltp-tables-count=64 run

3.記錄結果,並依次增加線程數threads分別記錄線程數為 1/ 16/ 32/ 64/ 128 ……情況下的指標及資源情況

4.清除測試數據

sysbench ./tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest  --mysql-host=IP

--mysql-port=3306  --mysql-user=root

--mysql-password=密碼  --oltp-tables-count=7  cleanup

參數化變量

--threads:線程數,增加線程數觀察瓶頸

獲取指標

1、TPS

2、QPS

3、總事務數

4、前95%延遲時間

7.3 測試用例(三)

測試用例3:創建200張表每表預置100萬行數據

測試目的

與用例2相比,單表數量一致,增加表的數量進行觀察

前置條件

200張表,每張表10萬行數據,每次修改並發數

步驟

1.准備測試數據

sysbench

--test=/opt/sysbench-1.0.12/tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest --mysql-host=IP  --mysql-port=3306

--mysql-user=root --mysql-password=密碼 

--oltp-test-mode=complex --oltp-tables-count=200 

--oltp-table-size=100000  --report-interval=2 prepare

2.運行測試

sysbench ./tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest --mysql-host=IP --mysql-port=3306

--mysql-user=root --mysql-password=密碼

--oltp-test-mode=complex --time=600 --threads=128

 --report-interval=2 --oltp-tables-count=64 run

3.記錄結果,並依次增加線程數threads分別記錄線程數為 1/ 16/ 32/ 64/ 128 ……情況下的指標及資源情況

4.清除測試數據

sysbench ./tests/include/oltp_legacy/oltp.lua

--mysql-db=sbtest --mysql-host=IP --mysql-port=3306

--mysql-user=root --mysql-password=密碼

--oltp-tables-count=200 cleanup

參數化變量

--threads 線程數,增加線程數觀察瓶頸

獲取指標

1、TPS

2、QPS

3、總事務數

4、前95%延遲時間

8. 測試結果分析

8.1   6張表每表預置1000萬行數據測試

8.1.1 測試結果

線程數

1

16

32

64

96

128

160

256

512

TPS(/s)

 

               

QPS(/s)

 

               

事務總數(萬)

 

               

前95%延遲時間(ms)

 

               

8.1.2 測試過程記錄

1)數據准備階段:

說明:准備完成后,表空間約13G;

2)執行測試階段:

①連接數1:

8.1.3 資源情況

查看雲服務自帶監控;

8.1.4 結果分析

根據測試結果進行描述;

 

。。。。

 

9. 測試結果總結

總結當前mysql測試環境,在並發線程數達到160左右時,TPS約900/s左右,QPS約1.8萬/s左右,95%事務平均延遲達到300ms,

再增加並發數據后,QPS變化不大,但延遲時間明顯加長。測試過程整體CPU利用率較高,在達到最大TPS及QPS時此時CPU利用率達到93%以上。

特別說明:此總結只適用於本次測試。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM