自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

簡(jiǎn)單、易用的MySQL官方壓測(cè)工具,建議收藏

數(shù)據(jù)庫(kù) MySQL
mysqlslap是mysql自帶的基準(zhǔn)測(cè)試工具,該工具查詢數(shù)據(jù),語(yǔ)法簡(jiǎn)單,靈活容易使用.該工具可以模擬多個(gè)客戶端同時(shí)并發(fā)的向服務(wù)器發(fā)出查詢更新,給出了性能測(cè)試數(shù)據(jù)而且提供了多種引擎的性能比較

 一、MySQL自帶的壓力測(cè)試工具 Mysqlslap

mysqlslap是mysql自帶的基準(zhǔn)測(cè)試工具,該工具查詢數(shù)據(jù),語(yǔ)法簡(jiǎn)單,靈活容易使用.該工具可以模擬多個(gè)客戶端同時(shí)并發(fā)的向服務(wù)器發(fā)出查詢更新,給出了性能測(cè)試數(shù)據(jù)而且提供了多種引擎的性能比較。mysqlslap為mysql性能優(yōu)化前后提供了直觀的驗(yàn)證依據(jù),系統(tǒng)運(yùn)維和DBA人員應(yīng)該掌握一些常見(jiàn)的壓力測(cè)試工具,才能準(zhǔn)確的掌握線上數(shù)據(jù)庫(kù)支撐的用戶流量上限及其抗壓性等問(wèn)題。

1、更改其默認(rèn)的最大連接數(shù)

在對(duì)MySQL進(jìn)行壓力測(cè)試之前,需要更改其默認(rèn)的最大連接數(shù),如下: 

  1. [root@mysql ~]# vim /etc/my.cnf  
  2. ................  
  3. [mysqld]  
  4. max_connections=1024  
  5. [root@mysql ~]# systemctl restart mysqld 

查看最大連接數(shù) 

  1. mysql> show variables like 'max_connections';  
  2. +-----------------+-------+  
  3. | Variable_name   | Value |  
  4. +-----------------+-------+  
  5. | max_connections | 1024  |  
  6. +-----------------+--------+  
  7. 1 row in set (0.00 sec) 

進(jìn)行壓力測(cè)試: 

  1. [root@mysql ~]# mysqlslap --defaults-file=/etc/my.cnf --concurrency=100,200 --iterations=1 --number-int-cols=20 --number-char-cols=30 \  
  2. --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=myisam,innodb --number-of-queries=2000 -uroot -p123 --verbose 

 上述命令測(cè)試說(shuō)明:模擬測(cè)試兩次讀寫(xiě)并發(fā),第一次100,第二次200,自動(dòng)生成SQL腳本,測(cè)試表包含20個(gè)init字段,30個(gè)char字段,每次執(zhí)行2000查詢請(qǐng)求。測(cè)試引擎分別是myisam,innodb。(上述選項(xiàng)中有很多都是默認(rèn)值,可以省略,如果想要了解各個(gè)選項(xiàng)的解釋,可以使用mysqlslap --help進(jìn)行查詢)。

測(cè)試結(jié)果說(shuō)明:

  •  Myisam第一次100客戶端同時(shí)發(fā)起增查用0.557/s,第二次200客戶端同時(shí)發(fā)起增查用0.522/s
  •  Innodb第一次100客戶端同時(shí)發(fā)起增查用0.256/s,第二次200客戶端同時(shí)發(fā)起增查用0.303/s

可以根據(jù)實(shí)際需求,一點(diǎn)點(diǎn)的加大并發(fā)數(shù)量進(jìn)行壓力測(cè)試。

二、使用第三方sysbench工具進(jìn)行壓力測(cè)試

1、安裝sysbench工具 

  1. [root@mysql ~]# yum -y install epel-release #安裝第三方epel源  
  2. [root@mysql ~]# yum -y install sysbench #安裝sysbench工具  
  3. [root@mysql ~]# sysbench --version #確定工具已安裝  
  4. sysbench 1.0.17 

sysbench可以進(jìn)行以下測(cè)試:

  •  CPU 運(yùn)算性能測(cè)試
  •  磁盤(pán) IO 性能測(cè)試
  •  調(diào)度程序性能測(cè)試
  •  內(nèi)存分配及傳輸速度測(cè)試
  •  POSIX 線程性能測(cè)試

數(shù)據(jù)庫(kù)性能測(cè)試(OLTP 基準(zhǔn)測(cè)試,需要通過(guò) /usr/share/sysbench/ 目錄中的 Lua 腳本執(zhí)行,例如 oltp_read_only.lua 腳本執(zhí)行只讀測(cè)試)。

sysbench 還可以通過(guò)運(yùn)行命令時(shí)指定自己的 Lua 腳本來(lái)自定義測(cè)試。

2、查看sysbench工具的幫助選項(xiàng) 

  1. [root@mysql ~]# sysbench --help  
  2. Usage:  
  3. sysbench [options]... [testname] [command]  
  4. Commands implemented by most tests: prepare run cleanup help # 可用的命令,四個(gè)  
  5. General options: # 通用選項(xiàng)  
  6. --threads=N 要使用的線程數(shù),默認(rèn) 1 個(gè) [1]  
  7. --events=N 最大允許的事件個(gè)數(shù) [0]  
  8. --time=N 最大的總執(zhí)行時(shí)間,以秒為單位 [10]  
  9. --forced-shutdown=STRING 在 --time 時(shí)間限制到達(dá)后,強(qiáng)制關(guān)閉之前等待的秒數(shù),默認(rèn)“off”禁用(number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable) [off] 
  10. --thread-stack-size=SIZE 每個(gè)線程的堆棧大小 [64K]  
  11. --rate=N 平均傳輸速率。0 則無(wú)限制 [0]  
  12. --report-interval=N 以秒為單位定期報(bào)告具有指定間隔的中間統(tǒng)計(jì)信息 0 禁用中間報(bào)告 [0]  
  13. --report-checkpoints=[LIST,...] 轉(zhuǎn)儲(chǔ)完整的統(tǒng)計(jì)信息并在指定的時(shí)間點(diǎn)重置所有計(jì)數(shù)器。參數(shù)是一個(gè)逗號(hào)分隔的值列表,表示從測(cè)試開(kāi)始經(jīng)過(guò)這個(gè)時(shí)間量時(shí)必須執(zhí)行報(bào)告檢查點(diǎn)(以秒為單位)。報(bào)告檢查點(diǎn)默認(rèn)關(guān)閉。 [] 
  14. --debug[=on|off] 打印更多 debug 信息 [off]  
  15. --validate[=on|off] 盡可能執(zhí)行驗(yàn)證檢查 [off]  
  16. --help[=on|off] 顯示幫助信息并退出 [off]  
  17. --version[=on|off] 顯示版本信息并退出 [off]  
  18. --config-file=FILENAME 包含命令行選項(xiàng)的文件  
  19. --tx-rate=N 廢棄,改用 --rate [0]  
  20. --max-requests=N 廢棄,改用 --events [0]  
  21. --max-time=N 廢棄,改用 --time [0]  
  22. --num-threads=N 廢棄,改用 --threads [1] 
  23. Pseudo-Random Numbers Generator options: # 偽隨機(jī)數(shù)發(fā)生器選項(xiàng)  
  24. --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]  
  25. --rand-spec-iter=N number of iterations used for numbers generation [12]  
  26. --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]  
  27. --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]  
  28. --rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0]  
  29. --rand-pareto-h=N parameter h for pareto distribution [0.2]  
  30. Log options: # 日志選項(xiàng)  
  31. --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]  
  32. --percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]  
  33. --histogram[=on|off] print latency histogram in report [off]  
  34. General database options: # 通用的數(shù)據(jù)庫(kù)選項(xiàng)  
  35. --db-driver=STRING 指定要使用的數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序 ('help' to get list of available drivers)  
  36. --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]  
  37. --db-debug[=on|off] print database-specific debug information [off]  
  38. Compiled-in database drivers: # 內(nèi)建的數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序,默認(rèn)支持 MySQL 和 PostgreSQL  
  39. mysql - MySQL driver  
  40. pgsql - PostgreSQL driver  
  41. mysql options: # MySQL 數(shù)據(jù)庫(kù)專用選項(xiàng)  
  42. --mysql-host=[LIST,...] MySQL server host [localhost]  
  43. --mysql-port=[LIST,...] MySQL server port [3306]  
  44. --mysql-socket=[LIST,...] MySQL socket  
  45. --mysql-user=STRING MySQL user [sbtest]  
  46. --mysql-password=STRING MySQL password []  
  47. --mysql-db=STRING MySQL database name [sbtest]  
  48. --mysql-ssl[=on|off] use SSL connections, if available in the client library [off]  
  49. --mysql-ssl-cipher=STRING use specific cipher for SSL connections [] 
  50. --mysql-compression[=on|off] use compression, if available in the client library [off]  
  51. --mysql-debug[=on|off] trace all client library calls [off]  
  52. --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]  
  53. --mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off]  
  54. pgsql options: # PostgreSQL 數(shù)據(jù)庫(kù)專用選項(xiàng)  
  55. --pgsql-host=STRING PostgreSQL server host [localhost]  
  56. --pgsql-port=N PostgreSQL server port [5432]  
  57. --pgsql-user=STRING PostgreSQL user [sbtest]  
  58. --pgsql-password=STRING PostgreSQL password []  
  59. --pgsql-db=STRING PostgreSQL database name [sbtest]  
  60. Compiled-in tests: # 內(nèi)建測(cè)試類型  
  61. fileio - File I/O test  
  62. cpu - CPU performance test  
  63. memory - Memory functions speed test  
  64. threads - Threads subsystem performance test  
  65. mutex - Mutex performance test   
  66. See 'sysbench <testname> help' for a list of options for each test. 

3、sysbench測(cè)試MySQL數(shù)據(jù)庫(kù)性能

1)準(zhǔn)備測(cè)試數(shù)據(jù) 

  1. #查看sysbench自帶的lua腳本使用方法  
  2. [root@mysql ~]# sysbench /usr/share/sysbench/oltp_common.lua help  
  3. #必須創(chuàng)建sbtest庫(kù),sbtest是sysbench默認(rèn)使用的庫(kù)名  
  4. [root@mysql ~]# mysqladmin -uroot -p123 create sbtest;  
  5. #然后,準(zhǔn)備測(cè)試所用的表,這些測(cè)試表放在測(cè)試庫(kù)sbtest中。這里使用的lua腳本為/usr/share/sysbench/oltp_common.lua。  
  6. [root@mysql ~]# sysbench --mysql-host=127.0.0.1 \  
  7. --mysql-port=3306 \  
  8. --mysql-user=root \  
  9. --mysql-password=123 \  
  10. /usr/share/sysbench/oltp_common.lua \  
  11. --tables=10 \  
  12. --table_size=100000 \  
  13. prepare  
  14. #其中--tables=10表示創(chuàng)建10個(gè)測(cè)試表,  
  15. #--table_size=100000表示每個(gè)表中插入10W行數(shù)據(jù),
  16. #prepare表示這是準(zhǔn)備數(shù)的過(guò)程。 

2)確認(rèn)測(cè)試數(shù)據(jù)以存在 

  1. [root@mysql ~]# mysql -uroot -p123 sbtest; #登錄到sbtest庫(kù)  
  2. mysql> show tables; #查看相應(yīng)的表  
  3. +------------------+  
  4. | Tables_in_sbtest |  
  5. +------------------+  
  6. | sbtest1 |  
  7. | sbtest10 |  
  8. | sbtest2 |  
  9. | sbtest3 |  
  10. | sbtest4 |  
  11. | sbtest5 |  
  12. | sbtest6 |  
  13. | sbtest7 |  
  14. | sbtest8 |  
  15. | sbtest9 |  
  16. +------------------+  
  17. 10 rows in set (0.00 sec)  
  1. mysql> select count(*) from sbtest1; #隨機(jī)選擇一個(gè)表,確認(rèn)其有100000條數(shù)據(jù)  
  2. +----------+  
  3. | count(*) |  
  4. +----------+  
  5. | 100000 |  
  6. +----------+  
  7. 1 row in set (0.01 sec) 

3)數(shù)據(jù)庫(kù)測(cè)試和結(jié)果分析

稍微修改下之前準(zhǔn)備數(shù)據(jù)的語(yǔ)句,就可以拿來(lái)測(cè)試了。需要注意的是,之前使用的lua腳本為oltp_common.lua,它是一個(gè)通用腳本,是被其它lua腳本調(diào)用的,它不能直接拿來(lái)測(cè)試。

所以,我這里用oltp_read_write.lua腳本來(lái)做讀、寫(xiě)測(cè)試。還有很多其它類型的測(cè)試,比如只讀測(cè)試、只寫(xiě)測(cè)試、刪除測(cè)試、大批量插入測(cè)試等等??烧业綄?duì)應(yīng)的lua腳本進(jìn)行調(diào)用即可。 

  1. #執(zhí)行測(cè)試命令如下:  
  2. [root@mysql ~]# sysbench --threads=4 \  
  3. --time=20 \  
  4. --report-interval=5 \  
  5. --mysql-host=127.0.0.1 \  
  6. --mysql-port=3306 \  
  7. --mysql-user=root \  
  8. --mysql-password=123 \  
  9. /usr/share/sysbench/oltp_read_write.lua \  
  10. --tables=10 \  
  11. --table_size=100000 \  
  12. run 

上述命令返回的結(jié)果如下: 

  1. [root@mysql ~]# sysbench --threads=4 --time=20 --report-interval=5 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123 /usr/share/sysbench/oltp_read_write.lua --tables=10 --table_size=100000 run 
  2. sysbench 1.0.17 (using system LuaJIT 2.0.4) 
  3. Running the test with following options:  
  4. Number of threads: 4  
  5. Report intermediate results every 5 second(s)  
  6. Initializing random number generator from current time  
  7. Initializing worker threads...  
  8. Threads started!   
  9. #以下是每5秒返回一次的結(jié)果,統(tǒng)計(jì)的指標(biāo)包括:  
  10. # 線程數(shù)、tps(每秒事務(wù)數(shù))、qps(每秒查詢數(shù))、  
  11. # 每秒的讀/寫(xiě)/其它次數(shù)、延遲、每秒錯(cuò)誤數(shù)、每秒重連次數(shù)  
  12. [ 5s ] thds: 4 tps: 1040.21 qps: 20815.65 (r/w/o: 14573.17/4161.25/2081.22) lat (ms,95%): 7.17 err/s: 0.00 reconn/s: 0.00  
  13. [ 10s ] thds: 4 tps: 1083.34 qps: 21667.15 (r/w/o: 15165.93/4334.55/2166.68) lat (ms,95%): 6.55 err/s: 0.00 reconn/s: 0.00  
  14. [ 15s ] thds: 4 tps: 1121.57 qps: 22429.09 (r/w/o: 15700.64/4485.30/2243.15) lat (ms,95%): 6.55 err/s: 0.00 reconn/s: 0.00  
  15. [ 20s ] thds: 4 tps: 1141.69 qps: 22831.98 (r/w/o: 15982.65/4566.16/2283.18) lat (ms,95%): 6.09 err/s: 0.00 reconn/s: 0.00 
  16. SQL statistics:  
  17. queries performed:  
  18. read: 307146 # 執(zhí)行的讀操作數(shù)量  
  19. write: 87756 # 執(zhí)行的寫(xiě)操作數(shù)量  
  20. other: 43878 # 執(zhí)行的其它操作數(shù)量  
  21. total: 438780  
  22. transactions: 21939 (1096.57 per sec.) # 執(zhí)行事務(wù)的平均速率  
  23. queries: 438780 (21931.37 per sec.) # 平均每秒能執(zhí)行多少次查詢  
  24. ignored errors: 0 (0.00 per sec.)  
  25. reconnects: 0 (0.00 per sec.)  
  26. General statistics:  
  27. total time: 20.0055s # 總消耗時(shí)間  
  28. total number of events: 21939 # 總請(qǐng)求數(shù)量(讀、寫(xiě)、其它)  
  29. Latency (ms):  
  30. min: 1.39  
  31. avg: 3.64  
  32. max: 192.05  
  33. 95th percentile: 6.67 # 采樣計(jì)算的平均延遲  
  34. sum: 79964.26  
  35. Threads fairness:  
  36. events (avg/stddev): 5484.7500/15.12  
  37. execution time (avg/stddev): 19.9911/0.00 

4、cpu/io/內(nèi)存等測(cè)試

sysbench內(nèi)置的幾個(gè)測(cè)試指標(biāo)如下: 

  1. [root@mysql ~]# sysbench --help  
  2. .......... # 省略部分內(nèi)容  
  3. Compiled-in tests:  
  4. fileio - File I/O test  
  5. cpu - CPU performance test  
  6. memory - Memory functions speed test  
  7. threads - Threads subsystem performance test  
  8. mutex - Mutex performance test 

可以直接help輸出測(cè)試方法,例如,fileio測(cè)試: 

  1. [root@mysql ~]# sysbench fileio help  
  2. sysbench 1.0.17 (using system LuaJIT 2.0.4)  
  3. fileio options:  
  4. --file-num=N number of files to create [128]  
  5. --file-block-size=N block size to use in all IO operations [16384]  
  6. --file-total-size=SIZE total size of files to create [2G]  
  7. --file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}  
  8. --file-io-mode=STRING file operations mode {sync,async,mmap} [sync]  
  9. --file-async-backlog=N number of asynchronous operatons to queue per thread [128]  
  10. --file-extra-flags=[LIST,...] list of additional flags to use to open files {sync,dsync,direct} []  
  11. --file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]  
  12. --file-fsync-all[=on|off] do fsync() after each write operation [off]  
  13. --file-fsync-end[=on|off] do fsync() at the end of test [on]  
  14. --file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]  
  15. --file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]  
  16. --file-rw-ratio=N reads/writes ratio for combined test [1.5] 

1)測(cè)試io性能

例如,創(chuàng)建5個(gè)文件,總共2G,每個(gè)文件大概400M。 

  1. [root@mysql ~]# sysbench fileio --file-num=5 --file-total-size=2G prepare  
  2. [root@mysql ~]# ll -lh test*  
  3. -rw------- 1 root root 410M May 26 16:05 test_file.0  
  4. -rw------- 1 root root 410M May 26 16:05 test_file.1  
  5. -rw------- 1 root root 410M May 26 16:05 test_file.2  
  6. -rw------- 1 root root 410M May 26 16:05 test_file.3  
  7. -rw------- 1 root root 410M May 26 16:05 test_file.4 

然后運(yùn)行測(cè)試: 

  1. [root@mysql ~]# sysbench --events=5000 \  
  2. --threads=16 \  
  3. fileio \  
  4. --file-num=5 \  
  5. --file-total-size=2G \  
  6. --file-test-mode=rndrw \  
  7. --file-fsync-freq=0 \  
  8. --file-block-size=16384 \  
  9. run 

返回的結(jié)果如下: 

  1. Running the test with following options:  
  2. Number of threads: 16  
  3. Initializing random number generator from current time  
  4. Extra file open flags: (none)  
  5. 5 files, 409.6MiB each  
  6. 2GiB total file size  
  7. Block size 16KiB  
  8. Number of IO requests: 5000  
  9. Read/Write ratio for combined random IO test: 1.50  
  10. Calling fsync() at the end of test, Enabled.  
  11. Using synchronous I/O mode  
  12. Doing random r/w test  
  13. Initializing worker threads...  
  14. Threads started!  
  15. File operations:  
  16. reads/s: 9899.03  
  17. writes/s: 6621.38  
  18. fsyncs/s: 264.33  
  19. Throughput: # 吞吐量  
  20. read, MiB/s: 154.66 #表示讀帶寬  
  21. written, MiB/s: 103.46 #表示寫(xiě)的帶寬  
  22. General statistics:  
  23. total time: 0.3014s  
  24. total number of events: 5000  
  25. Latency (ms):  
  26. min: 0.00  
  27. avg: 0.81  
  28. max: 53.56  
  29. 95th percentile: 4.10  
  30. sum: 4030.48  
  31. Threads fairness:  
  32. events (avg/stddev): 312.5000/27.64  
  33. execution time (avg/stddev): 0.2519/0.02 

2)測(cè)試cpu性能 

  1. [root@mysql ~]# sysbench cpu --threads=40 --events=10000 --cpu-max-prime=20000 run 

壓測(cè)時(shí),還請(qǐng)小心謹(jǐn)慎?。。?! 

 

責(zé)任編輯:龐桂玉 來(lái)源: 運(yùn)維派
相關(guān)推薦

2020-12-03 09:57:34

MySQL壓測(cè)工具數(shù)據(jù)庫(kù)

2021-02-03 14:51:34

MySQL數(shù)據(jù)庫(kù)壓測(cè)工具

2023-10-19 08:23:50

wrkOpenResty工具

2010-07-14 10:53:20

Web應(yīng)用

2024-03-21 10:39:24

CIOAI

2020-06-17 08:55:22

mysqlslapsysbenchMySQL

2021-06-11 17:45:57

大數(shù)據(jù)可視化工具

2014-11-25 11:37:17

壓測(cè) 軟件測(cè)試

2016-01-14 13:07:20

美團(tuán)壓測(cè)工具工具

2012-05-07 09:01:02

Fio壓測(cè)工具

2016-09-18 18:27:21

KubernetesDocker

2023-10-31 18:12:03

壓測(cè)工具測(cè)試

2015-11-10 18:04:22

FileMaker

2020-06-18 15:45:54

AWS機(jī)器學(xué)習(xí)人工智能

2019-08-19 00:14:12

網(wǎng)絡(luò)測(cè)試帶寬網(wǎng)絡(luò)流量

2019-11-19 07:56:30

MySQL壓測(cè)數(shù)據(jù)表

2011-01-11 12:43:00

2015-07-29 09:15:43

Dukto開(kāi)源工具

2022-11-25 18:49:11

云原生

2020-10-13 17:50:06

MySQL數(shù)據(jù)庫(kù)代碼
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)