mysqlslap是mysql自帶的工具,不須要單獨安裝:mysql
-concurrency 表明併發數量,多個能夠用逗號隔開,concurrency=10,50,100, 併發鏈接線程數分別是十、50、100個併發。sql
--engines 表明要測試的引擎,能夠有多個,用分隔符隔開。數據庫
--iterations 表明要運行這些測試多少次。api
--auto-generate-sql 表明用系統本身生成的SQL腳原本測試。bash
--auto-generate-sql-load-type 表明要測試的是讀仍是寫仍是二者混合的(read,write,update,mixed)併發
--number-of-queries 表明總共要運行多少次查詢。每一個客戶運行的查詢數量能夠用查詢總數/併發數來計算。ide
--debug-info 表明要額外輸出CPU以及內存的相關信息。wordpress
--number-int-cols :建立測試表的 int 型字段數量工具
--auto-generate-sql-add-autoincrement : 表明對生成的表自動添加auto_increment列,從5.1.18版本開始post
--number-char-cols 建立測試表的 char 型字段數量。
--create-schema 測試的schema,MySQL中schema也就是database。
--query 使用自定義腳本執行測試,例如能夠調用自定義的一個存儲過程或者sql語句來執行測試。
--only-print 若是隻想打印看看SQL語句是什麼,能夠用這個選項。
[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
結果中各項含義:
Average number of ... 運行全部語句的平均秒數
Minimum number of ... 運行全部語句的最小秒數
Maximum number of ... 運行全部語句的最大秒數
Number of clients ... 客戶端數量
Average number of queries per client 每一個客戶端運行查詢的平均數
[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
數據庫Mariadb 10.0.14
首先給數據庫安裝審計插件,並啓用
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)
發現已經安裝了,沒有安裝的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