做网站也是一门技术外贸网站英文版
web/
2025/9/26 23:00:59/
文章来源:
做网站也是一门技术,外贸网站英文版,三亚久爱传媒招聘信息,eclipse网站开发教程一、MySQL自带的压力测试工具——Mysqlslapmysqlslap是mysql自带的基准测试工具,该工具查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测试数据而且提供了多种引擎的性能比较。mysqlslap为mysql性能优化前后提供了直观的验…一、MySQL自带的压力测试工具——Mysqlslapmysqlslap是mysql自带的基准测试工具,该工具查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测试数据而且提供了多种引擎的性能比较。mysqlslap为mysql性能优化前后提供了直观的验证依据,系统运维和DBA人员应该掌握一些常见的压力测试工具,才能准确的掌握线上数据库支撑的用户流量上限及其抗压性等问题。1、更改其默认的最大连接数在对MySQL进行压力测试之前需要更改其默认的最大连接数如下[rootmysql data]# vim /etc/my.cnf #编辑主配置文件[mysqld]............#省略部分内容max_connections1024如下mysql show variables like max_connections; #查看最大连接数------------------------| Variable_name | Value |------------------------| max_connections | 1024 |------------------------1 row in set (0.00 sec)进行压力测试[rootmysql ~]# mysqlslap --defaults-file/etc/my.cnf --concurrency100,200 --iterations1 --number-int-cols20 --number-char-cols30 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-typemixed --enginemyisam,innodb --number-of-queries2000 -uroot -p123.com --verbose上述命令测试说明模拟测试两次读写并发第一次100第二次200自动生成SQL脚本测试表包含20个init字段30个char字段每次执行2000查询请求。测试引擎分别是myisaminnodb。(上述选项中有很多都是默认值可以省略如果想要了解各个选项的解释可以使用mysqlslap --help进行查询)上述命令返回结果如下测试结果说明 Myisam第一次100客户端同时发起增查用0.557/s,第二次200客户端同时发起增查用0.522/s Innodb第一次100客户端同时发起增查用0.256/s,第二次200客户端同时发起增查用0.303/s 。可以根据实际需求一点点的加大并发数量进行压力测试。二、使用第三方sysbench工具进行压力测试1、安装sysbench工具[rootmysql ~]# yum -y install epel-release #安装第三方epel源[rootmysql ~]# yum -y install sysbench #安装sysbench工具[rootmysql ~]# sysbench --version #确定工具已安装sysbench 1.0.17sysbench 可以进行以下测试CPU 运算性能测试磁盘 IO 性能测试调度程序性能测试内存分配及传输速度测试POSIX 线程性能测试数据库性能测试(OLTP 基准测试需要通过 /usr/share/sysbench/ 目录中的 Lua 脚本执行例如 oltp_read_only.lua 脚本执行只读测试)sysbench 还可以通过运行命令时指定自己的 Lua 脚本来自定义测试。2、查看sysbench工具的帮助选项[rootmysql ~]# sysbench --helpUsage:sysbench [options]... [testname] [command]Commands implemented by most tests: prepare run cleanup help # 可用的命令四个General options: # 通用选项--threadsN 要使用的线程数默认 1 个 [1]--eventsN 最大允许的事件个数 [0]--timeN 最大的总执行时间以秒为单位 [10]--forced-shutdownSTRING 在 --time 时间限制到达后强制关闭之前等待的秒数默认“off”禁用(number of seconds to wait after the --time limit before forcing shutdown, or off to disable) [off]--thread-stack-sizeSIZE 每个线程的堆栈大小 [64K]--rateN 平均传输速率。0 则无限制 [0]--report-intervalN 以秒为单位定期报告具有指定间隔的中间统计信息 0 禁用中间报告 [0]--report-checkpoints[LIST,...] 转储完整的统计信息并在指定的时间点重置所有计数器。参数是一个逗号分隔的值列表表示从测试开始经过这个时间量时必须执行报告检查点(以秒为单位)。报告检查点默认关闭。 []--debug[on|off] 打印更多 debug 信息 [off]--validate[on|off] 尽可能执行验证检查 [off]--help[on|off] 显示帮助信息并退出 [off]--version[on|off] 显示版本信息并退出 [off]--config-fileFILENAME 包含命令行选项的文件--tx-rateN 废弃改用 --rate [0]--max-requestsN 废弃改用 --events [0]--max-timeN 废弃改用 --time [0]--num-threadsN 废弃改用 --threads [1]Pseudo-Random Numbers Generator options: # 伪随机数发生器选项--rand-typeSTRING random numbers distribution {uniform,gaussian,special,pareto} [special]--rand-spec-iterN number of iterations used for numbers generation [12]--rand-spec-pctN percentage of values to be treated as special (for special distribution) [1]--rand-spec-resN percentage of special values to use (for special distribution) [75]--rand-seedN seed for random number generator. When 0, the current time is used as a RNG seed. [0]--rand-pareto-hN parameter h for pareto distribution [0.2]Log options: # 日志选项--verbosityN verbosity level {5 - debug, 0 - only critical messages} [3]--percentileN 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-driverSTRING 指定要使用的数据库驱动程序 (help to get list of available drivers)--db-ps-modeSTRING prepared statements usage mode {auto, disable} [auto]--db-debug[on|off] print database-specific debug information [off]Compiled-in database drivers: # 內建的数据库驱动程序默认支持 MySQL 和 PostgreSQLmysql - MySQL driverpgsql - PostgreSQL drivermysql options: # MySQL 数据库专用选项--mysql-host[LIST,...] MySQL server host [localhost]--mysql-port[LIST,...] MySQL server port [3306]--mysql-socket[LIST,...] MySQL socket--mysql-userSTRING MySQL user [sbtest]--mysql-passwordSTRING MySQL password []--mysql-dbSTRING MySQL database name [sbtest]--mysql-ssl[on|off] use SSL connections, if available in the client library [off]--mysql-ssl-cipherSTRING 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 数据库专用选项--pgsql-hostSTRING PostgreSQL server host [localhost]--pgsql-portN PostgreSQL server port [5432]--pgsql-userSTRING PostgreSQL user [sbtest]--pgsql-passwordSTRING PostgreSQL password []--pgsql-dbSTRING 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 help for a list of options for each test.3、sysbench测试MySQL数据库性能1)准备测试数据#查看sysbench自带的lua脚本使用方法[rootmysql ~]# sysbench /usr/share/sysbench/oltp_common.lua help#必须创建sbtest库sbtest事sysbench默认使用的库名[rootmysql ~]# mysqladmin -uroot -p123.com create sbtest;#然后准备测试所用的表这些测试表放在测试库sbtest中。这里使用的lua脚本为/usr/share/sysbench/oltp_common.lua。[rootmysql ~]# sysbench --mysql-host127.0.0.1 \ --mysql-port3306 \ --mysql-userroot \ --mysql-password123.com \ /usr/share/sysbench/oltp_common.lua \ --tables10 \ --table_size100000 \ prepare#其中--tables10表示创建10个测试表#--table_size100000表示每个表中插入10W行数据#prepare表示这是准备数的过程。2)确认测试数据以存在[rootmysql ~]# mysql -uroot -p123.com sbtest; #登录到sbtest库mysql show tables; #查看相应的表------------------| 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; #随机选择一个表确认其有100000条数据----------| count(*) |----------| 100000 |----------1 row in set (0.01 sec)3)数据库测试和结果分析稍微修改下之前准备数据的语句就可以拿来测试了。需要注意的是之前使用的lua脚本为oltp_common.lua它是一个通用脚本是被其它lua脚本调用的它不能直接拿来测试。所以我这里用oltp_read_write.lua脚本来做读、写测试。还有很多其它类型的测试比如只读测试、只写测试、删除测试、大批量插入测试等等。可找到对应的lua脚本进行调用即可。#执行测试命令如下[rootmysql ~]# sysbench --threads4 \ --time20 \ --report-interval5 \ --mysql-host127.0.0.1 \ --mysql-port3306 \ --mysql-userroot \ --mysql-password123.com \ /usr/share/sysbench/oltp_read_write.lua \ --tables10 \ --table_size100000 \ run上述命令返回的结果如下[rootmysql ~]# sysbench --threads4 --time20 --report-interval5 --mysql-host127.0.0.1 --mysql-port3306 --mysql-userroot --mysql-password123.com /usr/share/sysbench/oltp_read_write.lua --tables10 --table_size100000 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秒返回一次的结果统计的指标包括# 线程数、tps(每秒事务数)、qps(每秒查询数)、# 每秒的读/写/其它次数、延迟、每秒错误数、每秒重连次数[ 5s ] thds: 4 tps: 675.29 qps: 13513.94 (r/w/o: 9460.62/2701.95/1351.37) lat (ms,95%): 8.58 err/s: 0.00 reconn/s: 0.00[ 10s ] thds: 4 tps: 679.05 qps: 13586.79 (r/w/o: 9511.29/2717.40/1358.10) lat (ms,95%): 8.58 err/s: 0.00 reconn/s: 0.00[ 15s ] thds: 4 tps: 676.82 qps: 13538.23 (r/w/o: 9476.70/2707.69/1353.84) lat (ms,95%): 8.74 err/s: 0.20 reconn/s: 0.00[ 20s ] thds: 4 tps: 684.62 qps: 13692.11 (r/w/o: 9585.02/2737.86/1369.23) lat (ms,95%): 8.43 err/s: 0.00 reconn/s: 0.00SQL statistics:queries performed:read: 190190 # 执行的读操作数量write: 54337 # 执行的写操作数量other: 27169 # 执行的其它操作数量total: 271696transactions: 13584 (678.88 per sec.) # 执行事务的平均速率queries: 271696 (13578.35 per sec.) # 平均每秒能执行多少次查询ignored errors: 1 (0.05 per sec.)reconnects: 0 (0.00 per sec.)General statistics:total time: 20.0084s # 总消耗时间total number of events: 13584 # 总请求数量(读、写、其它)Latency (ms):min: 2.68avg: 5.89max: 38.2195th percentile: 8.58 # 采样计算的平均延迟sum: 79985.65Threads fairness:events (avg/stddev): 3396.0000/60.84execution time (avg/stddev): 19.9964/0.004、cpu/io/内存等测试sysbench内置的几个测试指标如下[rootmysql ~]# sysbench --help.......... # 省略部分内容Compiled-in tests:fileio - File I/O testcpu - CPU performance testmemory - Memory functions speed testthreads - Threads subsystem performance testmutex - Mutex performance test可以直接help输出测试方法例如fileio测试[rootmysql ~]# sysbench fileio helpsysbench 1.0.17 (using system LuaJIT 2.0.4)fileio options:--file-numN number of files to create [128]--file-block-sizeN block size to use in all IO operations [16384]--file-total-sizeSIZE total size of files to create [2G]--file-test-modeSTRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}--file-io-modeSTRING file operations mode {sync,async,mmap} [sync]--file-async-backlogN 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-freqN do fsync() after this number of requests (0 - dont 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-modeSTRING which method to use for synchronization {fsync, fdatasync} [fsync]--file-merged-requestsN merge at most this number of IO requests if possible (0 - dont merge) [0]--file-rw-ratioN reads/writes ratio for combined test [1.5]1)测试io性能例如创建5个文件总共2G每个文件大概400M。[rootmysql ~]# sysbench fileio --file-num5 --file-total-size2G prepare[rootmysql ~]# ll -lh test*-rw------- 1 root root 410M 1月 2 18:47 test_file.0-rw------- 1 root root 410M 1月 2 18:47 test_file.1-rw------- 1 root root 410M 1月 2 18:48 test_file.2-rw------- 1 root root 410M 1月 2 18:48 test_file.3-rw------- 1 root root 410M 1月 2 18:48 test_file.4然后运行测试[rootmysql ~]# sysbench --events5000 \ --threads16 \ fileio \ --file-num5 \ --file-total-size2G \ --file-test-moderndrw \ --file-fsync-freq0 \ --file-block-size16384 \ run返回的结果如下Initializing worker threads...Threads started!File operations:reads/s: 6374.88writes/s: 4271.21fsyncs/s: 170.34Throughput: #吞吐量read, MiB/s: 99.61 #表示读带宽written, MiB/s: 66.74 #表示写的带宽General statistics:total time: 0.4684stotal number of events: 5000Latency (ms):min: 0.00avg: 0.99max: 50.6495th percentile: 4.74sum: 4940.23Threads fairness:events (avg/stddev): 312.5000/15.32execution time (avg/stddev): 0.3088/0.012)测试cpu性能[rootmysql ~]# sysbench cpu --threads40 --events10000 --cpu-max-prime20000 run———————— 本文至此结束感谢阅读 ————————
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/82427.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!