在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一、MySQL常用配置以下所有配置参数以32G内存的服务器为基 1、打开独立的表空间
2、MySQL服务所允许的同时会话数的上限,默认为151,经常出现Too Many Connections的错误提示,则需要增大此值
3、操作系统在监听队列中所能保持的连接数
4、每个客户端连接最大的错误允许数量,当超过该次数,MYSQL服务器将禁止此主机的连接请求,直到MYSQL服务器重启或通过flush hosts命令清空此主机的相关信息
5、所有线程所打开表的数量
6、每个连接传输数据大小,最大1G,须是1024的倍数,一般设为最大的BLOB的值
7、请求的最大连接时间
8、排序缓冲被用来处理类似ORDER BY以及GROUP BY队列所引起的排序
9、不带索引的全表扫描,使用的buffer的最小值
10、查询缓冲大小
11、指定单个查询能够使用的缓冲区大小,默认为1M
12、设定默认的事务隔离级别
13、 线程使用的堆大小,此值限制内存中能处理的存储过程的递归深度和SQL语句复杂性,此容量的内存在每次连接时被预留
14、开启二进制日志功能
15、二进制日志格式:基于行
16、InnoDB使用一个缓冲池来保存索引和原始数据, 可设置这个变量到服务器物理内存大小的80%
17、用来同步IO操作的IO线程的数量
18、在Innodb核心内的允许线程数量,建议的设置是CPU数量加上磁盘数量的两倍
19、用来缓冲日志数据的缓冲区的大小
20、在日志组中每个日志文件的大小
21、在日志组中的文件总数
22、SQL语句在被回滚前,InnoDB事务等待InnoDB行锁的时间
23、慢查询记录的阈值时长,默认10秒
24、将没有使用索引的查询也记录下来
my.cnf示例: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 innodb_file_per_table = 1 innodb_buffer_pool_size = 6442450944 #内存不足6G会报错 innodb_file_io_threads = 4 innodb_thread_concurrency = 16 innodb_log_buffer_size = 16M innodb_log_file_size = 512M innodb_log_files_in_group = 3 innodb_lock_wait_timeout = 120 log_bin = /var/lib/mysql/mariadb-bin binlog_format = row slow_query_log long_query_time = 2 log-queries-not-using-indexes transaction_isolation = REPEATABLE-READ query_cache_size = 128M query_cache_limit = 4M max_connections = 8000 back_log = 300 max_connect_errors = 1000 open_files_limit = 10240 max_allowed_packet = 32M wait_timeout = 10 sort_buffer_size = 16M join_buffer_size = 16M thread_stack = 512K 二、MySQL的性能压力测试常见测试工具:
mysqlslap工具介绍 mysqlslap来自于mariadb包,测试的过程默认生成一个mysqlslap的schema,生成测试表t1,查询和插入测试数据,mysqlslap库自动生成,如果已经存在则先删除。用--only-print来打印实际的测试过程,整个测试完成后不会在数据库中留下痕迹。 常用选项:
测试示例: 1)单线程测试 [root@centos7 ~]# mysqlslap -a -uroot -p Enter password: Benchmark Average number of seconds to run all queries: 0.004 seconds Minimum number of seconds to run all queries: 0.004 seconds Maximum number of seconds to run all queries: 0.004 seconds Number of clients running queries: 1 Average number of queries per client: 0 2)多线程测试,使用–concurrency来模拟并发连接 [root@centos7 ~]# mysqlslap -uroot -p -a -c 500 Enter password: Benchmark Average number of seconds to run all queries: 3.384 seconds Minimum number of seconds to run all queries: 3.384 seconds Maximum number of seconds to run all queries: 3.384 seconds Number of clients running queries: 500 Average number of queries per client: 0 3)同时测试不同的存储引擎的性能进行对比 [root@centos7 ~]# mysqlslap -uroot -p -a --concurrency=500 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-info Enter password: Benchmark Running for engine myisam Average number of seconds to run all queries: 0.192 seconds Minimum number of seconds to run all queries: 0.187 seconds Maximum number of seconds to run all queries: 0.202 seconds Number of clients running queries: 500 Average number of queries per client: 2 Benchmark Running for engine innodb Average number of seconds to run all queries: 0.355 seconds Minimum number of seconds to run all queries: 0.350 seconds Maximum number of seconds to run all queries: 0.364 seconds Number of clients running queries: 500 Average number of queries per client: 2 User time 0.33, System time 0.58 Maximum resident set size 22892, Integral resident set size 0 Non-physical pagefaults 46012, Physical pagefaults 0, Swaps 0 Blocks in 0 out 0, Messages in 0 out 0, Signals 0 Voluntary context switches 31896, Involuntary context switches 0 4)执行一次测试,分别500和1000个并发,执行5000次总查询 [root@centos7 ~]# mysqlslap -uroot -p -a --concurrency=500,1000 --number-of-queries 5000 --debug-info Enter password: Benchmark Average number of seconds to run all queries: 3.378 seconds Minimum number of seconds to run all queries: 3.378 seconds Maximum number of seconds to run all queries: 3.378 seconds Number of clients running queries: 500 Average number of queries per client: 10 Benchmark Average number of seconds to run all queries: 3.101 seconds Minimum number of seconds to run all queries: 3.101 seconds Maximum number of seconds to run all queries: 3.101 seconds Number of clients running queries: 1000 Average number of queries per client: 5 User time 0.84, System time 0.64 Maximum resident set size 83068, Integral resident set size 0 Non-physical pagefaults 139977, Physical pagefaults 0, Swaps 0 Blocks in 0 out 0, Messages in 0 out 0, Signals 0 Voluntary context switches 31524, Involuntary context switches 3 5)迭代测试 [root@centos7 ~]# mysqlslap -uroot -p -a --concurrency=500 --number-of-queries 5000 --iterations=5 --debug-info Enter password: Benchmark Average number of seconds to run all queries: 3.307 seconds Minimum number of seconds to run all queries: 3.184 seconds Maximum number of seconds to run all queries: 3.421 seconds Number of clients running queries: 500 Average number of queries per client: 10 User time 2.18, System time 1.58 Maximum resident set size 74872, Integral resident set size 0 Non-physical pagefaults 327732, Physical pagefaults 0, Swaps 0 Blocks in 0 out 0, Messages in 0 out 0, Signals 0 Voluntary context switches 73904, Involuntary context switches 3 以上就是MySQL系列之十五 MySQL常用配置和性能压力测试的详细内容,更多关于MySQL常用配置和性能压力测试的资料请关注极客世界其它相关文章! |
请发表评论