一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數(shù)據(jù)庫技術(shù)|

服務(wù)器之家 - 數(shù)據(jù)庫 - Mysql - 通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

2020-11-26 20:09東山絮柳仔 Mysql

sysbench是一款壓力測試工具,可以測試系統(tǒng)的硬件性能,也可以用來對數(shù)據(jù)庫進行基準測試。這篇文章主要介紹了通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試 ,需要的朋友可以參考下

1.背景

 sysbench是一款壓力測試工具,可以測試系統(tǒng)的硬件性能,也可以用來對數(shù)據(jù)庫進行基準測試。sysbench 支持的測試有cpu運算性能測試、內(nèi)存分配及傳輸速度測試、磁盤io性能測試、posix線程性能測試、互斥性測試測試、數(shù)據(jù)庫性能測試(oltp基準測試)。目前支持的數(shù)據(jù)庫主要是mysql數(shù)據(jù)庫和pg數(shù)據(jù)庫。

在新服務(wù)器上線時,建議對服務(wù)器的性能做一次測試,最好與既往的同類型的服務(wù)器的性能測試報表做一個橫線比較,發(fā)現(xiàn)潛在問題。及新機器上線前,對服務(wù)器做一次體檢。

對數(shù)據(jù)庫而言,我們可以通過sysbench工具實現(xiàn)對數(shù)據(jù)庫的基準測試。在現(xiàn)在的系統(tǒng)架構(gòu)中,前端都比較容易彈性水平拓展,數(shù)據(jù)庫相對較難,因此,基準測試對數(shù)據(jù)庫具有很重要的作用。而對數(shù)據(jù)庫的基準測試的作用,就是分析在當前的配置下(包括硬件配置、os、數(shù)據(jù)庫設(shè)置等),數(shù)據(jù)庫的性能表現(xiàn),從而找出mysql的性能閾值,并根據(jù)實際系統(tǒng)的要求調(diào)整配置。

2.sysbench的安裝

1)安裝命令

yum -y install sysbench

2)查看安裝的版本

sysbench --version

通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

3)查看已安裝軟件的信息(主要是通 rpm 命令)。

 查詢sysbench的安裝信息,主要是測試mysql時,需要使用sysbench自帶的lua腳本進行測試。如果使用快速安裝的方式,默認的腳本路徑為:/usr/share/sysbench

 如果不在這個命令,我們我們執(zhí)行以下命令查看,查找已安裝在本機linux系統(tǒng)上面的所有的sysbench軟件的程序:

rpm -qa sysbench

列出該軟件所有的文件與目錄所在完整文件名(list):

rpm -ql sysbench

通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

3.sysbench 語法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
sysbench --help
usage:
 sysbench [options]... [testname] [command]
commands implemented by most tests: prepare run cleanup help
general options:
 --threads=n           number of threads to use [1]
 --events=n           limit for total number of events [0]
 --time=n            limit for total execution time in seconds [10]
 --forced-shutdown=string    number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off]
 --thread-stack-size=size    size of stack per thread [64k]
 --rate=n            average transactions rate. 0 for unlimited rate [0]
 --report-interval=n       periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
 --report-checkpoints=[list,...] dump full statistics and reset all counters at specified points in time. the argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. report checkpoints are off by default. []
 --debug[=on|off]        print more debugging info [off]
 --validate[=on|off]       perform validation checks where possible [off]
 --help[=on|off]         print help and exit [off]
 --version[=on|off]       print version and exit [off]
 --config-file=filename     file containing command line options
 --tx-rate=n           deprecated alias for --rate [0]
 --max-requests=n        deprecated alias for --events [0]
 --max-time=n          deprecated alias for --time [0]
 --num-threads=n         deprecated alias for --threads [1]
pseudo-random numbers generator options:
 --rand-type=string random numbers distribution {uniform,gaussian,special,pareto} [special]
 --rand-spec-iter=n number of iterations used for numbers generation [12]
 --rand-spec-pct=n percentage of values to be treated as 'special' (for special distribution) [1]
 --rand-spec-res=n percentage of 'special' values to use (for special distribution) [75]
 --rand-seed=n   seed for random number generator. when 0, the current time is used as a rng seed. [0]
 --rand-pareto-h=n parameter h for pareto distribution [0.2]
log options:
 --verbosity=n verbosity level {5 - debug, 0 - only critical messages} [3]
 --percentile=n    percentile to calculate in latency statistics (1-100). use the special value of 0 to disable percentile calculations [95]
 --histogram[=on|off] print latency histogram in report [off]
general database options:
 --db-driver=string specifies database driver to use ('help' to get list of available drivers) [mysql]
 --db-ps-mode=string prepared statements usage mode {auto, disable} [auto]
 --db-debug[=on|off] print database-specific debug information [off]
compiled-in database drivers:
 mysql - mysql driver
 pgsql - postgresql driver
mysql options:
 --mysql-host=[list,...]     mysql server host [localhost]
 --mysql-port=[list,...]     mysql server port [3306]
 --mysql-socket=[list,...]    mysql socket
 --mysql-user=string       mysql user [sbtest]
 --mysql-password=string     mysql password []
 --mysql-db=string        mysql database name [sbtest]
 --mysql-ssl[=on|off]       use ssl connections, if available in the client library [off]
 --mysql-ssl-cipher=string    use specific cipher for ssl connections []
 --mysql-compression[=on|off]   use compression, if available in the client library [off]
 --mysql-debug[=on|off]      trace all client library calls [off]
 --mysql-ignore-errors=[list,...] list of errors to ignore, or "all" [1213,1020,1205]
 --mysql-dry-run[=on|off]     dry run, pretend that all mysql client api calls are successful without executing them [off]
pgsql options:
 --pgsql-host=string   postgresql server host [localhost]
 --pgsql-port=n     postgresql server port [5432]
 --pgsql-user=string   postgresql user [sbtest]
 --pgsql-password=string postgresql password []
 --pgsql-db=string    postgresql database name [sbtest]
compiled-in tests:
 fileio - file i/o test
 cpu - cpu performance test
 memory - memory functions speed test
 threads - threads subsystem performance test
 mutex - mutex performance test

基本語法如下:

sysbench [options]... [testname] [command]

command 是sysbench要執(zhí)行的命令,包括prepare、run和cleanup。prepare是為測試提前準備數(shù)據(jù),run是執(zhí)行正式的測試,cleanup是在測試完成后對數(shù)據(jù)庫進行清理

testname  指定了要進行的測試,在老版本的sysbench中,可以通過--test參數(shù)指定測試的腳本;而在新版本中,--test參數(shù)已經(jīng)聲明為廢棄,可以不使用--test,而是直接指定腳本。測試時使用的腳本為lua腳本,可以使用sysbench自帶腳本,也可以自己開發(fā)。

options 關(guān)于mysql的主要包括mysql 連接信息參數(shù) 和 mysql 執(zhí)行相關(guān)的參數(shù)。

4 測試

step 1 準備壓測數(shù)據(jù)

通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

?
1
sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=xxx.xxx.xxx.xxx --mysql-port=3306 --mysql-user=testsbuser --mysql-password='textpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 prepare

step 2  壓測

?
1
sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=xxx.xxx.xxx.xxx --mysql-port=3306 --mysql-user=testsbuser --mysql-password='textpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 run

也可以將測試結(jié)果導(dǎo)出到文件中,便于后續(xù)分析。

?
1
sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=xxx.xxx.xxx.xxx --mysql-port=3306 --mysql-user=testsbuser --mysql-password='testpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 run >> ./mysysbench.log

通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

step 3 清理壓測數(shù)據(jù)

?
1
sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=xxx.xxx.xxx.xxx --mysql-port=3306 --mysql-user=testsbuser --mysql-password='testpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 cleanup

 

通過sysbench工具實現(xiàn)MySQL數(shù)據(jù)庫的性能測試的方法

5.注意事項

(1) 測試數(shù)據(jù)庫需要提前創(chuàng)建,及時測試賬號擁有創(chuàng)建數(shù)據(jù)庫的權(quán)限。

     --mysql-db 參數(shù)指定了測試的數(shù)據(jù),默認是sbtest。

    不提前創(chuàng)建,報錯信息如下;

fatal: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:83: connection creation failed
(last message repeated 3 times)
fatal: error 1049: unknown database 'sysbench_db'
fatal: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:83: connection creation failed
fatal: unable to connect to mysql server on host 'xxx.xxx.xxx.xxx', port 3306, aborting...
(last message repeated 1 times)
fatal: error 1049: unknown database 'sysbench_db'
(last message repeated 1 times)

或是(不指定數(shù)據(jù)庫)

fatal: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:83: connection creation failed
fatal: error 1049: unknown database 'sbtest'
fatal: unable to connect to mysql server on host 'xxx.xxx.xxx.xxx', port 3306, aborting...

(2)不要在mysql服務(wù)器運行的機器上進行測試,一方面可能無法體現(xiàn)網(wǎng)絡(luò)(哪怕是局域網(wǎng))的影響,另一方面,sysbench的運行(尤其是設(shè)置的并發(fā)數(shù)較高時)會影響mysql服務(wù)器的表現(xiàn).

(3)逐步增加客戶端的并發(fā)連接數(shù)(--thread參數(shù)),觀察在連接數(shù)不同情況下,mysql服務(wù)器的表現(xiàn)。

(4)如果連續(xù)進行多次測試,注意確保之前測試的數(shù)據(jù)已經(jīng)被清理干凈。

(5)如果生成的報告,圖形化分析,可以通過gnuplot工具進行分析。

總結(jié)

以上所述是小編給大家介紹的通過sysbench工具實現(xiàn)mysql數(shù)據(jù)庫的性能測試的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對服務(wù)器之家網(wǎng)站的支持!

如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

原文鏈接:https://www.cnblogs.com/xuliuzai/p/11243376.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本一在线中文字幕天堂 | 日本一区二区精品88 | 日本在线国产 | 精品一区二区三区在线播放 | 398av影院视频在线 | 亚洲无限| 久久久无码精品亚洲A片猫咪 | 天天操丝袜 | 日本一区二区精品88 | 柔术一级毛片 | 2021国产精品露脸在线 | 日韩理论在线观看 | 色噜噜视频影院 | 亚洲色大成网站www久久九九 | 好大好猛好爽好深视频免费 | 国产精品www夜色影视 | 亚洲欧美日韩高清 | 亚洲国产婷婷俺也色综合 | 美女视频91 | 东方影库四虎 | 欧美在线视频一区在线观看 | 日本一区二区视频在线观看 | 国产二区精品视频 | 午夜福利自怕 | 婷综合| 国产一级黄色录像 | 亚洲日韩欧美一区二区在线 | 美女的让男人桶爽网站 | 亚洲久草| 国产在线激情视频 | 欧美一区二区日韩一区二区 | 车上小婕子系列辣文小说 | 初尝黑人巨大h文 | 久久视频精品3线视频在线观看 | 精品亚洲永久免费精品 | 好湿好紧太硬了我好爽 | 久久精品黄AA片一区二区三区 | 久久精品午夜一区二区福利 | 扒开双腿疯狂进出爽爽动态图 | 97爱sese| tube69中国露脸 |