用mysql自帶工具mysqlslap對數(shù)據(jù)庫進行壓力測試

MySQLslap是mysql自帶的工具,不需要單獨安裝:

創(chuàng)新互聯(lián)公司是網(wǎng)站建設技術企業(yè),為成都企業(yè)提供專業(yè)的成都網(wǎng)站建設、網(wǎng)站建設,網(wǎng)站設計,網(wǎng)站制作,網(wǎng)站改版等技術服務。擁有10多年豐富建站經(jīng)驗和眾多成功案例,為您定制適合企業(yè)的網(wǎng)站。10多年品質(zhì),值得信賴!

參數(shù):

-concurrency 代表并發(fā)數(shù)量,多個可以用逗號隔開,concurrency=10,50,100, 并發(fā)連接線程數(shù)分別是10、50、100個并發(fā)。

--engines 代表要測試的引擎,可以有多個,用分隔符隔開。

--iterations 代表要運行這些測試多少次。

--auto-generate-sql 代表用系統(tǒng)自己生成的SQL腳本來測試。

--auto-generate-sql-load-type 代表要測試的是讀還是寫還是兩者混合的(read,write,update,mixed)

--number-of-queries 代表總共要運行多少次查詢。每個客戶運行的查詢數(shù)量可以用查詢總數(shù)/并發(fā)數(shù)來計算。

--debug-info 代表要額外輸出CPU以及內(nèi)存的相關信息。

--number-int-cols :創(chuàng)建測試表的 int 型字段數(shù)量

--auto-generate-sql-add-autoincrement : 代表對生成的表自動添加auto_increment列,從5.1.18版本開始

--number-char-cols 創(chuàng)建測試表的 char 型字段數(shù)量。

--create-schema 測試的schema,MySQL中schema也就是database。

--query 使用自定義腳本執(zhí)行測試,例如可以調(diào)用自定義的一個存儲過程或者sql語句來執(zhí)行測試。

--only-print 如果只想打印看看SQL語句是什么,可以用這個選項。

1,簡單用法

[root@Linux_Aolens_01 /home/aolens]# mysqlslap --user=root --password=password --auto-generate-sql
 
Benchmark
 
Average number of seconds to run all queries: 0.002 seconds
 
Minimum number of seconds to run all queries: 0.002 seconds
 
Maximum number of seconds to run all queries: 0.002 seconds
 
Number of clients running queries: 1
 
Average number of queries per client: 0


結(jié)果中各項含義:

  • Average number of ... 運行所有語句的平均秒數(shù)

  • Minimum number of ... 運行所有語句的最小秒數(shù)

  • Maximum number of ... 運行所有語句的最大秒數(shù)

  • Number of clients ... 客戶端數(shù)量

  • Average number of queries per client 每個客戶端運行查詢的平均數(shù)

 

2,添加并發(fā)

[root@Linux_Aolens_01 /home/aolens]# mysqlslap --user=root --password=password --auto-generate-sql --concurrency=100 --number-of-queries=1000
Benchmark
Average number of seconds to run all queries: 0.316 seconds
Minimum number of seconds to run all queries: 0.316 seconds
Maximum number of seconds to run all queries: 0.316 seconds
Number of clients running queries: 100
Average number of queries per client: 10

3,使用自己測試庫和測試語句

[root@Linux_Aolens_01 /home/aolens]# mysqlslap --user=root --password=password --concurrency=10 --number-of-queries=100 --create-schema=wordpress --query="SELECT * FROM wordpress.wp_posts;"
Benchmark
Average number of seconds to run all queries: 4.255 seconds
Minimum number of seconds to run all queries: 4.255 seconds
Maximum number of seconds to run all queries: 4.255 seconds
Number of clients running queries: 10
Average number of queries per client: 10

4,結(jié)合實際,對網(wǎng)站首頁所請求的數(shù)據(jù)庫連接做壓力測試

數(shù)據(jù)庫Mariadb 10.0.14

首先給數(shù)據(jù)庫安裝審計插件,并啟用

MariaDB [(none)]> show variables like '%audit%'
-> ;
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| server_audit_events | |
| server_audit_excl_users | |
| server_audit_file_path | server_audit.log |
| server_audit_file_rotate_now | OFF |
| server_audit_file_rotate_size | 1000000 |
| server_audit_file_rotations | 9 |
| server_audit_incl_users | |
| server_audit_logging | OFF |
| server_audit_mode | 0 |
| server_audit_output_type | file |
| server_audit_syslog_facility | LOG_USER |
| server_audit_syslog_ident | mysql-server_auditing |
| server_audit_syslog_info | |
| server_audit_syslog_priority | LOG_INFO |
+-------------------------------+-----------------------+
14 rows in set (0.00 sec)

發(fā)現(xiàn)已經(jīng)安裝了,沒有安裝的MariaDB [(none)]> INSTALL PLUGIN server_audit SONAME 'server_audit.so';

命令行啟動審計功能:

       命令行啟用audit ,重啟后失效

MariaDB [(none)]> set global server_audit_file_rotate_size=1024*1024*1024;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> set global server_audit_events='query,table';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> set global server_audit_file_rotate_now=on;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> set global server_audit_logging='ON';
Query OK, 0 rows affected (0.00 sec)


刷新一下首頁查看審計日志里都有哪些SQL操作,對這些SQL進行壓測:

mysqlslap --user=root --password=password --concurrency=20 --number-of-queries=1000 --create-schema=wordpress --query=" \
SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'; \
SELECT option_value FROM wp_options WHERE option_name = 'a3_lz_google_api_key' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'a3_lz_google_api_key_enable' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = '_transient_timeout_a3_lz_google_api_key_status' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = '_transient_a3_lz_google_api_key_status' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'wordpress_api_key' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'onp_license_clipboard-p_w_picpaths' LIMIT 1; \
SELECT autoload FROM wp_options WHERE option_name = 'onp_license_clipboard-p_w_picpaths'; \
SELECT option_value FROM wp_options WHERE option_name = 'onp_version_check_clipboard-p_w_picpaths' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'ossdl_https' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'uninstall_plugins' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'a3_lazy_load_just_installed' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'akismet_comment_nonce' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'preload_cache_counter' LIMIT 1; \
SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules' LIMIT 1; \
......"
Benchmark
Average number of seconds to run all queries: 40.931 seconds
Minimum number of seconds to run all queries: 40.931 seconds
Maximum number of seconds to run all queries: 40.931 seconds
Number of clients running queries: 20
Average number of queries per client: 50

文章題目:用mysql自帶工具mysqlslap對數(shù)據(jù)庫進行壓力測試
轉(zhuǎn)載注明:http://bm7419.com/article42/jdidec.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站軟件開發(fā)、App開發(fā)全網(wǎng)營銷推廣、電子商務靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設