亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2019年07月25日 16:49:01   作者:東山絮柳仔  
sysbench是一款壓力測試工具,可以測試系統(tǒng)的硬件性能,也可以用來對數(shù)據庫進行基準測試。這篇文章主要介紹了通過sysbench工具實現(xiàn)MySQL數(shù)據庫的性能測試 ,需要的朋友可以參考下

1.背景

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

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

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

2.sysbench的安裝

1)安裝命令

yum -y install sysbench

2)查看安裝的版本

sysbench --version

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

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

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

rpm -qa sysbench

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

rpm -ql sysbench

3.sysbench 語法

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ù)據,run是執(zhí)行正式的測試,cleanup是在測試完成后對數(shù)據庫進行清理

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

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

4 測試

Step 1 準備壓測數(shù)據

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  壓測

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

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

 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

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

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

5.注意事項

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

     --mysql-db 參數(shù)指定了測試的數(shù)據,默認是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ù)據庫)

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服務器運行的機器上進行測試,一方面可能無法體現(xiàn)網絡(哪怕是局域網)的影響,另一方面,sysbench的運行(尤其是設置的并發(fā)數(shù)較高時)會影響MySQL服務器的表現(xiàn).

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

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

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

總結

以上所述是小編給大家介紹的通過sysbench工具實現(xiàn)MySQL數(shù)據庫的性能測試的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!

相關文章

  • MySQL InnoDB 事務鎖源碼分析

    MySQL InnoDB 事務鎖源碼分析

    InnoDB 事務鎖,事務鎖實現(xiàn)起來的代碼卻是又臭又硬的好大一坨,各種細節(jié),今天小編在這里整理一個源碼閱讀筆記,把那一坨加鎖相關的代碼提煉出來,感興趣的小伙伴別忘記收藏奧
    2021-09-09
  • MySQL中常見的六個約束類型詳解

    MySQL中常見的六個約束類型詳解

    數(shù)據類型是為了節(jié)約內存,提高計算, 數(shù)據約束是為了完整性(存儲關系),下面這篇文章主要給大家介紹了關于MySQL中常見的六個約束類型的相關資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2021-09-09
  • MySQL中的SHOW FULL PROCESSLIST命令實現(xiàn)

    MySQL中的SHOW FULL PROCESSLIST命令實現(xiàn)

    SHOW FULL PROCESSLIST命令是MySQL中一個非常有用的工具,可以幫助我們理解和監(jiān)控MySQL服務器的狀態(tài),本文主要介紹了MySQL中的SHOW FULL PROCESSLIST命令,感興趣的可以了解一下
    2023-11-11
  • Mysql中的SQL約束Constraint有哪幾種

    Mysql中的SQL約束Constraint有哪幾種

    這篇文章主要介紹了Mysql中的SQL約束Constraint有哪幾種,約束是為了使表中的數(shù)據有效,常見的約束有非空約束、唯一性約束、主鍵約束、外鍵約束、檢查約束,需要的朋友可以參考下
    2024-01-01
  • 深入了解MySQL中分區(qū)表的原理與企業(yè)級實戰(zhàn)

    深入了解MySQL中分區(qū)表的原理與企業(yè)級實戰(zhàn)

    本文詳細講解什么是分區(qū)表,分區(qū)表增刪改查的工作原理以及分區(qū)表的實戰(zhàn),分區(qū)表的場景有哪些,哪些場景不建議用分區(qū)表,并列舉出六點使用分區(qū)表的誤區(qū),需要的可以參考一下
    2022-11-11
  • mysql如何用sql語句建立學生課程數(shù)據庫基本表

    mysql如何用sql語句建立學生課程數(shù)據庫基本表

    這篇文章主要給大家介紹了關于mysql如何用sql語句建立學生課程數(shù)據庫基本表的相關資料,學生表是一個常見的數(shù)據表,用于存儲學生的個人信息和成績等相關數(shù)據,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下
    2023-12-12
  • SQL如何獲取目標時間點或日期的方法實例

    SQL如何獲取目標時間點或日期的方法實例

    日期獲取在我們日常開發(fā)中經常會遇到,這篇文章主要給大家介紹了關于SQL如何獲取目標時間點或日期的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-10-10
  • Mysql 數(shù)據庫訪問類

    Mysql 數(shù)據庫訪問類

    Mysql數(shù)據庫訪問類 實現(xiàn)代碼,對于想學習mysql操作類的朋友值得一看
    2009-02-02
  • SQL?Optimizer?詳細解析

    SQL?Optimizer?詳細解析

    這篇文章主要介紹了SQL?Optimizer?解析,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-07-07
  • MySQL Order By用法分享

    MySQL Order By用法分享

    本文用實例一點一點告訴你,MySQL order by的用法
    2012-07-07

最新評論