建立庫、表,導入數據用於測試。此過程由單線程完成。node
開始進行壓力測試。該步驟能夠使用多線程完成。mysql
清理測試數據。此過程由單線程完成。nginx
~]# mysqlslap -uroot -p --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement Enter password:Benchmark#運行全部語句的平局時間,單位秒Average number of seconds to run all queries: 0.018 seconds#運行全部語句的最小秒數Minimum number of seconds to run all queries: 0.018 seconds#運行全部語句的最大秒數Maximum number of seconds to run all queries: 0.018 seconds#客戶端數量Number of clients running queries: 1#每一個客戶端運行查詢的平均數Average number of queries per client: 0
--auto-generate-sql:自動生成測試表和數據,mysqlslap工具本身生成sql腳本進行測試。git
--auto-generate-sql-load-type:指定測試語句的類型。取值包括:read,key,write,update和mixed(默認)。github
--auto-generate-sql-add-autoincrement:生成的表中會添加自增列。sql

mysqlslap -uroot -p --auto-generate-sql --auto-generate-sql-load-type=mixed --concurrency=100 --number-of-queries=1000
--concurrency=100:指定同時有100個客戶端鏈接
--number-of-queries=1000:指定總的測試查詢次數,該值除以concurrency的值就是每一個客戶端執行的查詢次數。數據庫

mysqlslap --delimiter=";" --create="CREATE TABLE a (b int);INSERT INTO a VALUES (23)" --query="SELECT * FROM a" --concurrency=50 --iterations=200
mysqlslap -uroot -p --concurrency=5 --iterations=20 --number-int-cols=2 --number-char-cols=3 --auto-generate-sql
mysqlslap --concurrency=5 --iterations=5 --query=query.sql --create=create.sql --delimiter=";"
cd sysbench-0.5./autogen.sh./configure --prefix=/usr/local/sysbench --build=x86_64make && make installcp /usr/local/sysbench/bin/sysbench /usr/bin/驗證sysbench安裝是否成功。[root@node1 ~]# sysbench --versionsysbench 0.5
[root@node1 ~]# sysbench --test=cpu --cpu-max-prime=2000 runsysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Random number generator seed is 0 and will be ignored…………………………General statistics:total time: 1.1302s…………………………….
sysbench --test=memory --memory-block-size=8k --memory-total-size=100G run
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw prepare
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=root prepare
mysql> select count(*) from sbtest1;+----------+| count(*) |+----------+| 1000000 |+----------+
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=root --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
OLTP test statistics: queries performed: read: 407498 write: 0 other: 58214 total: 465712 transactions: 29107 (485.07 per sec.) requests: 407498 (6790.91 per sec.) other operations: 58214 (970.13 per sec.) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.)General statistics: total time: 60.0064s total number of events: 29107 total time taken by event execution: 479.9865s response time: min: 1.55ms avg: 16.49ms max: 539.30ms 95 percentile: 25.98ms Threads fairness: events (avg/stddev): 3638.3750/42.84 execution time (avg/stddev): 59.9983/0.00
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=root cleanup
本文分享自微信公衆號 - MySQL數據庫技術棧(Mysqltechnology)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。bash