mysql服务器基准测试_MySQL基准测试

MySQL基准测试

原因

测试评估出当前系统的运行情况,建立性能基准线;

模拟更高负载,找出扩展性瓶颈;

规划未来的业务增长;

测试不同的硬件、软件和操作系统配置;

我们只能进行大概的测试,来确定系统大致的余量。

策略

集成式

测试整体性能而不只是MySQL;

可以发现各组件之间缓存带来的影响;

更能揭示应用的真是表现;

很难建立,也很难正确设置。

组件式

需要比较不同的表结构或查询的性能;

需要针对应用中的某个具体问题进行测试;

为了避免漫长的基准测试,可以通过一个短期基准测试,快速循环,检测出调整后的效果。

指标

吞吐量:单位时间内的事务处理数,TPS和TPM。

响应时间:任务所需的整体时间,百分比响应时间和平均响应时间。

并发性:任意时间内同时发生的并发数,同时工作的线程数Threads_running或者连接数。并发性测试不是为了测试应用能达到的并发度,而是为了测试应用在不同并发下的性能。

可扩展性:系统性能/资源数的函数关系,衡量系统性能是否可以随着资源的扩展而线性扩展。

方法

错误行为

使用真实数据的子集而不是全集;

使用均匀的数据分布而不是真实数据分布;

使用不真实的分布参数;

在多用户场景中,做单用户测试;

在单服务器上测试分布式应用;

与真实用户行为不匹配的测试;

反复执行同一个查询导致一直走缓存;

忽略了系统预热的过程;

测试时间太短而无法覆盖场景;

在基准测试运行过程中有资源被其它任务消耗;

基于MySQL的默认配置的测试没有意义,默认配置是基于消耗很少内存的极小应用的。

步骤

提出问题并明确目标;

决定采用标准基准测试还是设计专用测试;

如果要设计专用测试,获取生产数据集的快照,该快照要易于还原,以便后续的测试;选择一个时间段,记录生产系统上的查询(querylog),要记录查询所在的线程以进行回放;

需要为每一轮测试创建一个目录,保存测试结果、配置文件、测试指标、脚本和相关说明;

需要准备好系统状态收集的相关的脚本,可以自己编写也可以使用pt工具;

确定基准测试的时长,基准测试运行的时间至少要等到系统达到稳定状态之后,这时候的稳定状态才是可以相信的;

决定是否使用自动化测试,从而准备自动化基准测试脚本,或者使用相关工具;

进行基准测试,通过逐步修改基准测试参数来进行迭代找出正确的参数值;

使用工具将测试过程中的数据绘制成图形,可以使用gnuplot或者R或者python;

通过图形将数字转化为结论。

在整个测试过程中,要详细地写下测试规划,应该记录测试数据、系统配置步骤、如何测量和分析结果、预热方案等,将参数和结果文档化。

工具

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

See 'sysbench help' for a list of options for each test.

常用通用参数:

--threads=N:需要使用的线程总数(默认值为1)。

--events=N:请求总数的上限值(默认值为10000)。

--thread-stack-size=SIZE:每个线程的栈空间的大小(默认值为32KB)。

--tx-rate=N:目标事务速率(TPS)(默认值为0)。

--report-interval=N:指定一个间隔时间,sysbench便会定期地报告测试期间的中间统计结果,以秒为单位。若取值为0,则表示禁用中间报告功能(默认值为0)。

--report-checkpoints=[LIST,...]:在指定的时间点,转储完整的统计数据,并且复位所有的计数器。这个选项的参数是一个由逗号分隔的值,表示从测试开始到必须执行报告检查点时需要花费的时间,以秒为单位。默认禁用报告检查点。

--test=STRING:需要运行的测试项。

--percentile=N:计算查询响应时间的百分比等级(默认值为95,表示sysbench会丢弃5%的最长的请求,然后再从剩余的请求中选择一个最长的请求)。

--histogram=[on|off]:打印响应时长直方图。

fileio测试

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]

在这个测试中,你需要创建一个大于最大内存的文件,然后选择一种读写方式(seqwr\seqrewr\seqrd\rndrd\rndwr\rndrw)测试。

--file-num=N:需要创建的文件数量(默认为128个文件)。

--file-block-size=N:在所有的IO操作中使用的数据块的大小(默认值为16384)。

--file-total-size=SIZE:需要创建的文件的总大小(默认值为2G)。

--file-test-mode=STRING:测试模式,可选的值有seqwr(顺序写)、seqrewr(顺序重写)、seqrd(顺序读)、rndrd(随机读)、rndwr(随机写)、rndrw(随机读写)。

--file-io-mode=STRING:文件操作模式,可选的值有sync、async、mmap(默认值为sync)。

--file-extra-flags=STRING:在已打开文件上使用的额外标志,可选的值有sync、dsync、direct。

--file-fsync-freq=N:在发出这个参数指定数量的请求之后,执行fsync(),将内存中已修改的文件数据同步至存储设备中。若取值为0,则表示不使用fsync()(默认值为100)。

--file-fsync-all=[on|off]:每次写操作之后,执行fsync()(默认值为off)。

--file-fsync-end=[on|off]:在测试结束时,执行fsync()(默认值为on)。

--file-fsync-mode=STRING:同步数据时,使用哪种方法,可选的值有fsync、fdatasync(默认值为fsync)。

--file-merged-requests=N:如果可能,最多合并由这个参数指定数量的IO请求。若取值为0,则表示不会合并请求(默认值为0)。

--file-rw-ratio=N:进行读写综合测试时,读写操作的比率(默认值为1.5)。

CPU测试

cpu options:

--cpu-max-prime=N upper limit for primes generator [10000]

这个测试将会执行cpu_max_prime的标准整除验证算法(从2到cpu_max_prime平方根,除去10的整数倍)

--cpu-max-prime=N:素数生成器的上限值(默认值为10000)。

内存测试

memory options:

--memory-block-size=SIZE size of memory block for test [1K]

--memory-total-size=SIZE total size of data to transfer [100G]

--memory-scope=STRING memory access scope {global,local} [global]

--memory-hugetlb[=on|off] allocate memory from HugeTLB pool [off]

--memory-oper=STRING type of memory operations {read, write, none} [write]

--memory-access-mode=STRING memory access mode {seq,rnd} [seq]

这个测试将会分配一个memory-block-size大小的内存缓冲区,对其进行读写,直到达到memory-total-size数据量。

--memory-block-size=SIZE:测试使用的内存块的大小(默认值为1K)。

--memory-total-size=SIZE:需要传输的数据总大小(默认值为100G)。

--memory-scope=STRING:内存访问范围,可选的值有global、local(默认值为global)。

--memory-hugetlb=[on|off]:从HugeTLB池中分配内存(默认值为off)。

--memory-oper=STRING:内存操作的类型,可选的值有read、write、none(默认值为write)。

--memory-access-mode=STRING:内存访问模式,可选的值有seq(顺序)、rnd(随机)(默认值为seq)。

线程测试

threads options:

--thread-yields=N number of yields to do per request [1000]

--thread-locks=N number of locks per thread [8]

这个测试将会执行thread-yields次"加thread-locks个锁-让出调度器-解锁"的循环。

--thread-yields=N:线程让出次数(默认值为1000)。线程将会执行加锁-让出-解锁的循环,循环次数为thread-yields次。

--thread-locks=N:每个线程使用的锁的数量(默认值为8)。

互斥锁测试

mutex options:

--mutex-num=N total size of mutex array [4096]

--mutex-locks=N number of mutex locks to do per thread [50000]

--mutex-loops=N number of empty loops to do outside mutex lock [10000]

这个测试将会从mutex-num大小的互斥锁池中取出互斥锁,每次取出后,执行mutex-loops全局变量递增操作,mutex-locks次。

--mutex-num=N:互斥锁数组的总大小(默认值为4096)。

--mutex-locks=N:执行每个线程时使用的互斥锁的数量(默认值为50000)。

--mutex-loops=N:在互斥锁内部执行的空循环的数量(默认值为10000)。

OLTP测试

内置支持的测试类型:bulk_insert,empty_test,oltp_common,oltp_delete,oltp_insert,oltp_point_select,oltp_read_only,oltp_read_write,oltp_update_index,oltp_update_non_index,oltp_write_only,prime-test,select_random_points,select_random_ranges

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]

可以通过(sysbench oltp_read_write help)命令获取对应test的详细信息。

参考资料

案例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值