电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術(shù)文章
文章詳情頁

MySQL壓力測試工具M(jìn)ysqlslap的使用

瀏覽:7日期:2023-10-08 12:17:35

一、MySQL自帶的壓力測試工具 Mysqlslap

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

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

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

[root@mysql ~]# vim /etc/my.cnf................[mysqld]max_connections=1024[root@mysql ~]# systemctl restart mysqld`查看最大連接數(shù)`mysql> show variables like ’max_connections’;+-----------------+-------+| Variable_name | Value |+-----------------+-------+| max_connections | 1024 |+-----------------+--------+1 row in set (0.00 sec)

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

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

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

測試結(jié)果說明:

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)行壓力測試。

MySQL壓力測試工具M(jìn)ysqlslap的使用

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

1、安裝sysbench工具

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

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

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

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

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

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

[root@mysql ~]# sysbench --helpUsage:sysbench [options]... [testname] [command]Commands implemented by most tests: prepare run cleanup help # 可用的命令,四個(gè)General options: # 通用選項(xiàng)--threads=N 要使用的線程數(shù),默認(rèn) 1 個(gè) [1]--events=N 最大允許的事件個(gè)數(shù) [0]--time=N 最大的總執(zhí)行時(shí)間,以秒為單位 [10]--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]--thread-stack-size=SIZE 每個(gè)線程的堆棧大小 [64K]--rate=N 平均傳輸速率。0 則無限制 [0]--report-interval=N 以秒為單位定期報(bào)告具有指定間隔的中間統(tǒng)計(jì)信息 0 禁用中間報(bào)告 [0]--report-checkpoints=[LIST,...] 轉(zhuǎn)儲(chǔ)完整的統(tǒng)計(jì)信息并在指定的時(shí)間點(diǎn)重置所有計(jì)數(shù)器。參數(shù)是一個(gè)逗號(hào)分隔的值列表,表示從測試開始經(jīng)過這個(gè)時(shí)間量時(shí)必須執(zhí)行報(bào)告檢查點(diǎn)(以秒為單位)。報(bào)告檢查點(diǎn)默認(rèn)關(guān)閉。 []--debug[=on|off] 打印更多 debug 信息 [off]--validate[=on|off] 盡可能執(zhí)行驗(yàn)證檢查 [off]--help[=on|off] 顯示幫助信息并退出 [off]--version[=on|off] 顯示版本信息并退出 [off]--config-file=FILENAME 包含命令行選項(xiàng)的文件--tx-rate=N 廢棄,改用 --rate [0]--max-requests=N 廢棄,改用 --events [0]--max-time=N 廢棄,改用 --time [0]--num-threads=N 廢棄,改用 --threads [1]Pseudo-Random Numbers Generator options: # 偽隨機(jī)數(shù)發(fā)生器選項(xiàng)--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: # 日志選項(xiàng)--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: # 通用的數(shù)據(jù)庫選項(xiàng)--db-driver=STRING 指定要使用的數(shù)據(jù)庫驅(qū)動(dòng)程序 (’help’ to get list of available drivers)--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: # ?冉ǖ氖?菘馇??絳潁??現(xiàn)С?nbsp;MySQL 和 PostgreSQLmysql - MySQL driverpgsql - PostgreSQL drivermysql options: # MySQL 數(shù)據(jù)庫專用選項(xiàng)--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: # PostgreSQL 數(shù)據(jù)庫專用選項(xiàng)--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 testcpu - CPU performance testmemory - Memory functions speed testthreads - Threads subsystem performance testmutex - Mutex performance testSee ’sysbench <testname> help’ for a list of options for each test.

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

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

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

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

[root@mysql ~]# mysql -uroot -p123 sbtest; #登錄到sbtest庫mysql> show tables; #查看相應(yīng)的表+------------------+| Tables_in_sbtest |+------------------+| sbtest1 || sbtest10 || sbtest2 || sbtest3 || sbtest4 || sbtest5 || sbtest6 || sbtest7 || sbtest8 || sbtest9 |+------------------+10 rows in set (0.00 sec)

mysql> select count(*) from sbtest1; #隨機(jī)選擇一個(gè)表,確認(rèn)其有100000條數(shù)據(jù)+----------+| count(*) |+----------+| 100000 |+----------+1 row in set (0.01 sec)

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

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

所以,我這里用oltp_read_write.lua腳本來做讀、寫測試。還有很多其它類型的測試,比如只讀測試、只寫測試、刪除測試、大批量插入測試等等。可找到對應(yīng)的lua腳本進(jìn)行調(diào)用即可。

#執(zhí)行測試命令如下:[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

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

[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 runsysbench 1.0.17 (using system LuaJIT 2.0.4)Running the test with following options:Number of threads: 4Report intermediate results every 5 second(s)Initializing random number generator from current timeInitializing worker threads...Threads started!#以下是每5秒返回一次的結(jié)果,統(tǒng)計(jì)的指標(biāo)包括:# 線程數(shù)、tps(每秒事務(wù)數(shù))、qps(每秒查詢數(shù))、# 每秒的讀/寫/其它次數(shù)、延遲、每秒錯(cuò)誤數(shù)、每秒重連次數(shù)[ 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[ 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[ 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[ 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.00SQL statistics:queries performed:read: 307146 # 執(zhí)行的讀操作數(shù)量write: 87756 # 執(zhí)行的寫操作數(shù)量other: 43878 # 執(zhí)行的其它操作數(shù)量total: 438780transactions: 21939 (1096.57 per sec.) # 執(zhí)行事務(wù)的平均速率queries: 438780 (21931.37 per sec.) # 平均每秒能執(zhí)行多少次查詢ignored errors: 0 (0.00 per sec.)reconnects: 0 (0.00 per sec.)General statistics:total time: 20.0055s # 總消耗時(shí)間total number of events: 21939 # 總請求數(shù)量(讀、寫、其它)Latency (ms):min: 1.39avg: 3.64max: 192.0595th percentile: 6.67 # 采樣計(jì)算的平均延遲sum: 79964.26Threads fairness:events (avg/stddev): 5484.7500/15.12execution time (avg/stddev): 19.9911/0.00

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

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

[root@mysql ~]# sysbench --help.......... # 省略部分內(nèi)容Compiled-in tests:fileio - File I/O testcpu - CPU performance testmemory - Memory functions speed testthreads - Threads subsystem performance testmutex - Mutex performance test

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

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

1)測試io性能

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

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

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

[root@mysql ~]# sysbench --events=5000 --threads=16 fileio --file-num=5 --file-total-size=2G --file-test-mode=rndrw --file-fsync-freq=0 --file-block-size=16384 run

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

Running the test with following options:Number of threads: 16Initializing random number generator from current timeExtra file open flags: (none)5 files, 409.6MiB each2GiB total file sizeBlock size 16KiBNumber of IO requests: 5000Read/Write ratio for combined random IO test: 1.50Calling fsync() at the end of test, Enabled.Using synchronous I/O modeDoing random r/w testInitializing worker threads...Threads started!File operations:reads/s: 9899.03writes/s: 6621.38fsyncs/s: 264.33Throughput: # 吞吐量read, MiB/s: 154.66 #表示讀帶寬written, MiB/s: 103.46 #表示寫的帶寬General statistics:total time: 0.3014stotal number of events: 5000Latency (ms):min: 0.00avg: 0.81max: 53.5695th percentile: 4.10sum: 4030.48Threads fairness:events (avg/stddev): 312.5000/27.64execution time (avg/stddev): 0.2519/0.02

2)測試cpu性能

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

壓測時(shí),還請小心謹(jǐn)慎!!!!

以上就是MySQL壓力測試工具M(jìn)ysqlslap的使用的詳細(xì)內(nèi)容,更多關(guān)于Mysqlslap的使用的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: MySQL 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 解放卡车|出口|济南重汽|报价大全|山东三维商贸有限公司 | 电磁流量计厂家_涡街流量计厂家_热式气体流量计-青天伟业仪器仪表有限公司 | UV固化机_UVLED光固化机_UV干燥机生产厂家-上海冠顶公司专业生产UV固化机设备 | 打造全球沸石生态圈 - 国投盛世| 塑胶跑道_学校塑胶跑道_塑胶球场_运动场材料厂家_中国塑胶跑道十大生产厂家_混合型塑胶跑道_透气型塑胶跑道-广东绿晨体育设施有限公司 | 阜阳成人高考_阜阳成考报名时间_安徽省成人高考网 | 泉州陶瓷pc砖_园林景观砖厂家_石英砖地铺石价格 _福建暴风石英砖 | 北京租车牌|京牌指标租赁|小客车指标出租 | 密集架-密集柜厂家-智能档案密集架-自动选层柜订做-河北风顺金属制品有限公司 | 热工多功能信号校验仪-热电阻热电偶校验仿真仪-金湖虹润仪表 | 标策网-专注公司商业知识服务、助力企业发展 | 不锈钢管件(不锈钢弯头,不锈钢三通,不锈钢大小头),不锈钢法兰「厂家」-浙江志通管阀 | DWS物流设备_扫码称重量方一体机_快递包裹分拣机_广东高臻智能装备有限公司 | 岸电电源-60HZ变频电源-大功率变频电源-济南诚雅电子科技有限公司 | 水质监测站_水质在线分析仪_水质自动监测系统_多参数水质在线监测仪_水质传感器-山东万象环境科技有限公司 | 线粒体膜电位荧光探针-细胞膜-标记二抗-上海复申生物科技有限公司 | 舞台木地板厂家_体育运动木地板_室内篮球馆木地板_实木运动地板厂家_欧氏篮球地板推荐 | 砂尘试验箱_淋雨试验房_冰水冲击试验箱_IPX9K淋雨试验箱_广州岳信试验设备有限公司 | 水成膜泡沫灭火剂_氟蛋白泡沫液_河南新乡骏华消防科技厂家 | 板材品牌-中国胶合板行业十大品牌-环保板材-上海声达板材 | 档案密集架_电动密集架_移动密集架_辽宁档案密集架-盛隆柜业厂家现货批发销售价格公道 | 自动焊锡机_点胶机_螺丝机-锐驰机器人 | 艺术漆十大品牌_艺术涂料加盟代理_蒙太奇艺术涂料厂家品牌|艺术漆|微水泥|硅藻泥|乳胶漆 | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | IHDW_TOSOKU_NEMICON_EHDW系列电子手轮,HC1系列电子手轮-上海莆林电子设备有限公司 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | 仿古建筑设计-仿古建筑施工-仿古建筑公司-汉匠古建筑设计院 | 丹佛斯压力传感器,WISE温度传感器,WISE压力开关,丹佛斯温度开关-上海力笙工业设备有限公司 | 东亚液氮罐-液氮生物容器-乐山市东亚机电工贸有限公司 | 磁力抛光研磨机_超声波清洗机厂家_去毛刺设备-中锐达数控 | 粘度计NDJ-5S,粘度计NDJ-8S,越平水分测定仪-上海右一仪器有限公司 | 嘉兴恒升声级计-湖南衡仪声级计-杭州爱华多功能声级计-上海邦沃仪器设备有限公司 | 垃圾清运公司_环卫保洁公司_市政道路保洁公司-华富环境 | 干洗加盟网-洗衣店品牌排行-干洗设备价格-干洗连锁加盟指南 | 慈溪麦田广告公司,提供慈溪广告设计。 | 自动焊锡机_点胶机_螺丝机-锐驰机器人 | 宝元数控系统|对刀仪厂家|东莞机器人控制系统|东莞安川伺服-【鑫天驰智能科技】 | 选矿设备-新型重选设备-金属矿尾矿重选-青州冠诚重工机械有限公司 | 刺绳_刀片刺网_刺丝滚笼_不锈钢刺绳生产厂家_安平县浩荣金属丝网制品有限公司-安平县浩荣金属丝网制品有限公司 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | 液氮罐_液氮容器_自增压液氮罐_杜瓦瓶_班德液氮罐厂家 |