[原] KVM 环境下MySQL性能对比
KVM 环境下MySQL性能对比
标签(空格分隔): Cloud2.0
测试目的
对比MySQL在物理机和KVM环境下性能情况
压测标准
压测遵循单一变量原则,所有的对比都是只改变一个变量的前提下完成
测试方式
以物理机MySQL为基准,分别做两次测试
- 测试IO相关参数(writethrough, innodb flush method)
- 测试CPU相关参数(NUMA Balancing)
测试环境
CPU:Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz X 24
MEM:48G
Disk:SSD 1.3T
System:Ubuntu 14.04.4 LTS
Kernel:3.16.0-30-generic
MySQL:mysql-5.5.31-linux2.6-x86_64
Sysbench:0.4.12
KVM:QEMU emulator version 2.0.0 (Debian 2.0.0+dfsg-2ubuntu1.22)
测试变量
因相关资料说明,writethrough IO模式能够保障数据一致性,所以在MySQL环境下,默认只测试writethrough环境
以打开NUMA Balancing的物理机环境为基准,测试KVM环境如下变量:
- writethrough cache模式下的 innodb io (O_DIRECT, O_SYNC)
- KVM 宿主机 NUMA Balancing 对MySQL性能影响
测试软件环境
配置模板如下(只列举关键参数)
# The MySQL server
[mysqld]
default-storage-engine = innodb
# MyISAM setup
key_buffer_size = 128M
myisam_sort_buffer_size = 64M
## gloabl config
max_allowed_packet = 16M
max_heap_table_size = 64M
tmp_table_size = 8M
max_connections = 4000
open_files_limit = 6000
table_open_cache = 512
read_buffer_size = 2M
read_rnd_buffer_size = 4M
join_buffer_size = 256K
sort_buffer_size = 2M
thread_cache_size = 8
query_cache_size = 0
thread_concurrency = 16
# Replication Master setup
log-bin = mysql-bin
relay-log = mysqld-relay-bin
max_binlog_size = 100M
binlog_format = row
binlog_cache_size=32K
thread_stack=262144
auto_increment_increment = 3
auto_increment_offset = 1
# Logging
slow_query_log = 1
long_query_time = 2
# InnoDB setup
innodb_file_format = Barracuda
innodb_file_per_table
innodb_buffer_pool_size = 4096M
innodb_log_file_size = 16M
innodb_log_buffer_size = 40M
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_log_files_in_group=2
innodb_io_capacity=2000
[mysqldump]
quick
extended-insert = false
default-character-set = utf8
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
KVM-qemu 配置如下:
<domain type='kvm'>
<name>mysql1</name>
<memory unit='MiB'>5120</memory>
<currentMemory unit='MiB'>5120</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type>hvm</type>
<boot dev='hd' />
</os>
<features>
<acpi />
<apic />
<pae />
</features>
<clock offset='utc' />
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' />
<source file='/data2/kvm/image1/mysql.qcow2' />
<target dev='vda' bus='virtio' />
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='writethrough'/>
<source file='/data2/kvm/image1/data.qcow2' />
<target dev='vdb' bus='virtio' />
</disk>
<interface type='network'>
<source network='default1' />
<model type='virtio' />
</interface>
<console type='pty'>
<target port='0' />
</console>
<graphics type='vnc' autoport='yes' sharePolicy='allow-exclusive' keymap='en-us'>
<listen type='address' address='0.0.0.0' />
</graphics>
</devices>
</domain>
测试基准
测试以物理机的MySQL实例作为参照
物理机MySQL默认情况下,使用4G+4Core,关闭NUMA Balancing
基准数据
Innodb_flush_method = O_DIRECT
OLTP test statistics:
queries performed:
read: 14000028
write: 5000010
other: 2000004
total: 21000042
transactions: 1000002 (1375.45 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 19000038 (26133.48 per sec.)
other operations: 2000004 (2750.89 per sec.)
Test execution summary:
total time: 727.0382s
total number of events: 1000002
total time taken by event execution: 17443.5464
per-request statistics:
min: 1.78ms
avg: 17.44ms
max: 1048.03ms
approx. 95 percentile: 32.64ms
Threads fairness:
events (avg/stddev): 41666.7500/646.28
execution time (avg/stddev): 726.8144/0.00
关闭 Innodb_flush_method = O_DIRECT, 使用默认值
OLTP test statistics:
queries performed:
read: 14000028
write: 5000010
other: 2000004
total: 21000042
transactions: 1000002 (1390.26 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 19000038 (26414.92 per sec.)
other operations: 2000004 (2780.52 per sec.)
Test execution summary:
total time: 719.2920s
total number of events: 1000002
total time taken by event execution: 17257.6867
per-request statistics:
min: 1.78ms
avg: 17.26ms
max: 1476.86ms
approx. 95 percentile: 32.76ms
Threads fairness:
events (avg/stddev): 41666.7500/709.66
execution time (avg/stddev): 719.0703/0.00
基准数据分析
在物理机MySQL实例情况下,innodb_flush_method对MySQL性能有一定影响关系
测试结果
第一次压测,KVM环境下 (单一变量 innodb_flush_method)
单纯虚拟机(kvm)压测, Innodb_flush_method = O_DIRECT
打开 Numa balancing
, kvm cache模式改为 writethrough
KVM 配置:
CPU = 4 core
Mem = 5 G
MySQL = 4G
Cache = writethrough
MySQL 配置:
Mem = 4G
Innodb_flush_method = O_DIRECT
Innodb_flush_method = O_DIRECT
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --max-requests=1000000 --num-threads=24 --mysql-host=192.168.100.244 --mysql-user=test run
OLTP test statistics:
queries performed:
read: 14000042
write: 5000015
other: 2000006
total: 21000063
transactions: 1000003 (1041.22 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 19000057 (19783.20 per sec.)
other operations: 2000006 (2082.44 per sec.)
Test execution summary:
total time: 960.4138s
total number of events: 1000003
total time taken by event execution: 23044.1587
per-request statistics:
min: 3.43ms
avg: 23.04ms
max: 958.60ms
approx. 95 percentile: 43.71ms
Threads fairness:
events (avg/stddev): 41666.7917/865.32
execution time (avg/stddev): 960.1733/0.01
Innodb_flush_method = DEFAULT(O_SYNC)
sysbench 0.4.12: multi-threaded system evaluation benchmark
OLTP test statistics:
queries performed:
read: 14000042
write: 5000015
other: 2000006
total: 21000063
transactions: 1000003 (1025.90 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 19000057 (19492.01 per sec.)
other operations: 2000006 (2051.79 per sec.)
Test execution summary:
total time: 974.7614s
total number of events: 1000003
total time taken by event execution: 23388.1224
per-request statistics:
min: 3.75ms
avg: 23.39ms
max: 1306.42ms
approx. 95 percentile: 44.38ms
Threads fairness:
events (avg/stddev): 41666.7917/863.10
execution time (avg/stddev): 974.5051/0.01
第一次压测总结
从压测报告显示,在kvm打开writethrough前提下,O_DIRECT方式,MySQL的效率更高
使用kvm,MySQL性能约为物理机的75%
纵坐标为总执行时间
IO模式建议优化手段
在宿主机打开writethrough前提下,配置 Innodb_flush_method = O_DIRECT有效提高MySQL性能
约为物理机O_DIRECT模式下性能的97%
第二次压测, KVM环境下 (单一变量 numa balancing)
单纯虚拟机(kvm)压测, 打开 numa balancing
关闭宿主机 Numa balancing, kvm cache模式改为 writethrough
Innodb_flush_method = O_SYNC
OLTP test statistics:
queries performed:
read: 14000014
write: 5000005
other: 2000002
total: 21000021
transactions: 1000001 (1068.76 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 19000019 (20306.35 per sec.)
other operations: 2000002 (2137.51 per sec.)
Test execution summary:
total time: 935.6690s
total number of events: 1000001
total time taken by event execution: 22450.9403
per-request statistics:
min: 3.51ms
avg: 22.45ms
max: 1170.10ms
approx. 95 percentile: 41.65ms
Threads fairness:
events (avg/stddev): 41666.7083/855.51
execution time (avg/stddev): 935.4558/0.01
Innodb_flush_method = O_DIRECT
OLTP test statistics:
queries performed:
read: 14000042
write: 5000015
other: 2000006
total: 21000063
transactions: 1000003 (1062.79 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 19000057 (20193.07 per sec.)
other operations: 2000006 (2125.59 per sec.)
Test execution summary:
total time: 940.9197s
total number of events: 1000003
total time taken by event execution: 22577.0003
per-request statistics:
min: 3.36ms
avg: 22.58ms
max: 756.58ms
approx. 95 percentile: 41.50ms
Threads fairness:
events (avg/stddev): 41666.7917/943.69
execution time (avg/stddev): 940.7083/0.01
第二次压测总结
打开NUMA绑定后,性能下降约3%
CPU优化建议
关闭NUMA绑定
Q&A
为什么不采用多个实例做高负载压测?
在测试的过程中,利用cgroup可以将实例的CPU全部跑到对应的核,在对应CPU上,负载是满的
为什么NUMA对性能影响如此之大?
猜测vCPU的多个线程可能位于不同的CPU Nodes, 导致跨node的内存访问,不太清楚vCPU是否会产生这样的调度,但是关闭NUMA是不会导致的。
有没有一张图解释不同kvm cache?
[原] KVM 环境下MySQL性能对比的更多相关文章
- tensorflow在各种环境下搭建与对比
tensorflow在各种环境下搭建与对比 由于有些训练是要长时间进行训练(几天),才能看出显著的结果,如果只是通过本地的计算机进行训练是不可能的.因此这周花了一些时间调研如何才能让神经网络长时间的进 ...
- [原]生产环境下的nginx.conf配置文件(多虚拟主机)
[原]生产环境下的nginx.conf配置文件(多虚拟主机) 2013-12-27阅读110 评论0 我的生产环境下的nginx.conf配置文件,做了虚拟主机设置的,大家可以根据需求更改,下载即可在 ...
- windows 环境下mysql 如何修改root密码
windows 环境下mysql 如何修改root密码 以windows为例: 无法开启服务,将mysql更目录下的data文件夹清空,然后调用 mysqld --initialize 开启mysql ...
- win10环境下MySql(5.7.21版本)安装过程
windows10上安装mysql(详细步骤) 2016年09月06日 08:09:34 阅读数:60405 环境:windwos 10(1511) 64bit.mysql 5.7.14 时间:201 ...
- docker环境下mysql参数修改
原文:docker环境下mysql参数修改 需要修改log_bin为on,看了好几个博客说都需要删掉容器重新生成,然而并非如此, 我们可以用docker cp 命令将docker的文件"下载 ...
- Linux环境下MySql安装和常见问题的解决
MySql安装 首先当然是要连接上linux服务器咯,然后就是下面的命令甩过去,梭哈,一通运行就是啦 梭哈 下载: sudo wget http://dev.mysql.com/get/mysql ...
- Windows环境下Mysql 5.7读写分离之使用mysql-proxy练习篇
本文使用mysql-proxy软件,结合mysql读写分离,实现实战练习. 前期准备: 三台机器: 代理机,IP:192.168.3.33 mysql Master,IP:192.168.3.32 m ...
- windowns环境下mysql 安装教程
windowns环境下mysql 安装教程 一:这里以绿色版安装为例(解压就可以使用) 下载地址: 下载页面:https://dev.mysql.com/downloads/mysql/ 2:点击 ...
- 【Data Cluster】真机环境下MySQL数据库集群搭建
真机环境下MySQL-Cluster搭建文档 摘要:本年伊始阶段,由于实验室对不同数据库性能测试需求,才出现MySQL集群搭建.购置主机,交换机,双绞线等一系列准备工作就绪,也就开始集群搭建.起初笔 ...
随机推荐
- Akka.net路径里的user
因为经常买双色球,嫌每次对彩票号麻烦,于是休息的时候做了个双色球兑奖的小程序,做完了发现业务还挺复杂的,于是改DDD重做设计,拆分服务,各种折腾...,不过这和本随笔没多大关系,等差不多了再总结一下, ...
- 两个 viewports 的故事-第二部分
原文链接:A tale of two viewports — part two 译者:nzbin 在这个迷你系列中,我将解释 viewports 和各种重要元素的宽度是如何工作的,比如说 <ht ...
- mysql进阶之存储过程
往往看别人的代码会有这样的感慨: 看不懂 理还乱 是离愁 别是一番滋味在心头 为什么要使用存储过程? 在mysql开发中使用存储过程的理由: 当希望在不同的应用程序或平台上执行相同的函数,或者封装特定 ...
- Oracle数据库该如何着手优化一个SQL
这是个终极问题,因为优化本身的复杂性实在是难以总结的,很多时候优化的方法并不是用到了什么高深莫测的技术,而只是一个思想意识层面的差异,而这些都很可能连带导致性能表现上的巨大差异. 所以有时候我们应该先 ...
- C++的内存泄漏检测【转载】
原文地址: http://www.cnblogs.com/jily/p/6239514.html
- Struts2入门(五)——OGNL和标签库
一.前言 OGNL和标签库的作用,粗暴一点说,就是减少在JSP页面中出现java代码,利于维护. 1.1.OGNL 1.1.1.什么是OGNL? OGNL(Object-Graph Navigatio ...
- JavaScript事件代理和委托(Delegation)
JavaScript事件代理 首先介绍一下JavaScript的事件代理.事件代理在JS世界中一个非常有用也很有趣的功能.当我们需要对很多元素添加事件的时候,可以通过将事件添加到它们的父节点而将事件委 ...
- Linux 利用Google Authenticator实现ssh登录双因素认证
1.介绍 双因素认证:双因素身份认证就是通过你所知道再加上你所能拥有的这二个要素组合到一起才能发挥作用的身份认证系统.双因素认证是一种采用时间同步技术的系统,采用了基于时间.事件和密钥三变量而产生的一 ...
- Linux C语言解析并显示.bmp格式图片
/************************* *bmp.h文件 *************************/ #ifndef __BMP_H__ #define __BMP_H__ # ...
- 万向节锁(Gimbal Lock)的理解
[TOC] 结论 我直接抛出结论: Gimbal Lock 产生的原因不是欧拉角也不是旋转顺序,而是我們的思维方式和程序的执行逻辑没有对应,也就是说是我们的观念导致这个情况的发生. 他人解释 首先我们 ...