一直想做这个测试,原因很简单,很多人一直比较怀疑Azure的虚拟机性能,说相同的配置凭啥比阿里的虚拟机贵那么多,其实,我自己以前也怀疑过,但是接触Azure的几个月,确实发现Azure的虚拟机性能真的很强悍,在这里笔者举个例子说明,有个客户(这里就不透露名字了)在本地数据中心cpu使用率一直在60%以上,因为我们上云都是先平移,如果不够用我们再auto sacle,但是客户却很不放心,非要高配的机器,在我们的百般劝说之下好不容易才答应先平移(客户表示很委屈,为什么我要高配的机器你不给,哈哈,开个玩笑),最后测试下来的结果发现cpu平时使用率在百分之二十多,周末最繁忙的时刻也没超过百分之五十,客户当场就说没想到Azure虚拟机性能这么优越,同时也很感谢我们没有坑他,在本次场景中,其实性能的瓶颈并不在vm,而是在于数据库,因为mysql是轻量级数据库不同于Oracle!!!

在本次测试环境中,我们在中国东部建立一台vm,考虑到数据库对虚拟机性能要求较高,这里我们以A6为例(要记得先建立高配的机型,然后再降为A6虚拟机!!!),并挂载1T的硬盘。

第一步建立虚拟机,过程略,结果如下

在这里,笔者想说一句,由于本次poc环境中,我们需要直观地看到cpu使用率,考虑到linux的ps命令的局限性,而且ARM里面很难看到cpu使用率,所以笔者选用ASM环境来建立虚拟机。

接下来我们先记录一下cpu与内存的使用情况

接下来第一步,添加附加磁盘

第二步,挂载附加磁盘

ssh远程登陆到该虚拟机

1.切换到root用户

[yangyang@mysqlvm1 ~]$ sudo su - root
[root@mysqlvm1 ~]#

切换成功

2.查看

[root@mysqlvm1 ~]# fdisk -cul /dev/sdc

Disk /dev/sdc: 1098.4 GB,  bytes
heads, sectors/track, cylinders, total sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000

3.分区

[root@mysqlvm1 ~]# fdisk -cu /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9694814d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table will be corrected by w(rite) Command (m for help): p Disk /dev/sdc: 1098.4 GB, bytes
heads, sectors/track, cylinders, total sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x9694814d Device Boot Start End Blocks Id System Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value Command (m for help): p Disk /dev/sdc: 1098.4 GB, bytes
heads, sectors/track, cylinders, total sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x9694814d Device Boot Start End Blocks Id System
/dev/sdc1 Linux Command (m for help): w

4.格式化

查看帮助文件

[root@mysqlvm1 ~]# man mkfs.ext4

找到lazy

  lazy_itable_init[= <0 to disable, 1 to enable>]
If enabled and the uninit_bg feature is enabled, the
inode table will not be fully initialized by mke2fs.
This speeds up filesystem initialization noticeably,
but it requires the kernel to finish initializing
the filesystem in the background when the filesystem
is first mounted. If the option value is omitted,
it defaults to 1 to enable lazy inode table initial-
ization.

快速格式化

[root@mysqlvm1 ~]# mkfs.ext4 -E lazy_itable_init /dev/sdc1
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , , ,
, , , , , , ,
, Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.

5.创建挂载点并挂载

[root@mysqlvm1 ~]#mkdir /1T
[root@mysqlvm1 ~]#mount /dev/sdc1 /1T

第三步,安装mysql,这里选择yum安装

[root@mysqlvm1 dev]# cd /1T/
[root@mysqlvm1 1T]# yum -y install mysql-server

看到如下结果

Installed:
mysql-server.x86_64 :5.1.-.el6 Dependency Installed:
mysql.x86_64 :5.1.-.el6 perl-DBD-MySQL.x86_64 :4.013-.el6 Dependency Updated:
mysql-libs.x86_64 :5.1.-.el6 Complete!

设置开机启动

[root@mysqlvm1 ~]# chkconfig mysqld on

启动mysql服务

[root@mysqlvm1 ~]# service mysqld start

设置mysql root用户以及密码

[root@mysqlvm1 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.1. Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select user,host,password from mysql.user;
+------+-----------+----------+
| user | host | password |
+------+-----------+----------+
| root | localhost | |
| root | mysqlvm1 | |
| root | 127.0.0.1 | |
| | localhost | |
| | mysqlvm1 | |
+------+-----------+----------+
rows in set (0.00 sec) mysql> set password for root@localhost=password('root');
Query OK, rows affected (0.00 sec) mysql> exit

用户root,密码root

用root来登陆

[root@mysqlvm1 ~]# mysql -u root -p

以下是mysql的一些常见命令

show databases; //查看系统已存在的数据库
use databasesname; //选择需要使用的数据库
drop database databasename; //删除选定的数据库
exit //退出数据库的连接
create database test01; //建立名为test的数据库
show tables; // 列出当前数据库下的表
其他基本的增删改查使用标准SQL即可

第四步,进行压测

mysqlslap是mysql自带的基准测试工具,可以模拟多个并发连接数来向服务器发起多次查询请求,这样可以观察CPU的情况

单线程测试

[root@mysqlvm1 ~]# mysqlslap -a -uroot -proot
Benchmark
Average number of seconds to run all queries: 0.001 seconds
Minimum number of seconds to run all queries: 0.001 seconds
Maximum number of seconds to run all queries: 0.001 seconds
Number of clients running queries:
Average number of queries per client:

多线程测试(100)

[root@mysqlvm1 ~]# mysqlslap -a -c  -uroot -proot
Benchmark
Average number of seconds to run all queries: 0.193 seconds
Minimum number of seconds to run all queries: 0.193 seconds
Maximum number of seconds to run all queries: 0.193 seconds
Number of clients running queries:
Average number of queries per client:

迭代测试

[root@mysqlvm1 ~]# mysqlslap -a -i  -uroot -proot
Benchmark
Average number of seconds to run all queries: 0.001 seconds
Minimum number of seconds to run all queries: 0.001 seconds
Maximum number of seconds to run all queries: 0.001 seconds
Number of clients running queries:
Average number of queries per client:

每个客户端的并发连接数*每个客户端查询的次数=总的查询次数

一下是mysqlslap的常见语法

# mysqlslap [options]

常用参数 [options] 详细说明:

--auto-generate-sql, -a 自动生成测试表和数据,表示用mysqlslap工具自己生成的SQL脚本来测试并发压力。
--auto-generate-sql-load-type=type 测试语句的类型。代表要测试的环境是读操作还是写操作还是两者混合的。取值包括:read,key,write,update和mixed(默认)。
--auto-generate-sql-add-auto-increment 代表对生成的表自动添加auto_increment列,从5.1.18版本开始支持。
--number-char-cols=N, -x N 自动生成的测试表中包含多少个字符类型的列,默认1
--number-int-cols=N, -y N 自动生成的测试表中包含多少个数字类型的列,默认1
--number-of-queries=N 总的测试查询次数(并发客户数×每客户查询次数)
--query=name,-q 使用自定义脚本执行测试,例如可以调用自定义的一个存储过程或者sql语句来执行测试。
--create-schema 代表自定义的测试库名称,测试的schema,MySQL中schema也就是database。
--commint=N 多少条DML后提交一次。
--compress, -C 如果服务器和客户端支持都压缩,则压缩信息传递。
--concurrency=N, -c N 表示并发量,也就是模拟多少个客户端同时执行select。可指定多个值,以逗号或者--delimiter参数指定的值做为分隔符。例如:--concurrency=100,200,500。
--engine=engine_name, -e engine_name 代表要测试的引擎,可以有多个,用分隔符隔开。例如:--engines=myisam,innodb。
--iterations=N, -i N 测试执行的迭代次数,代表要在不同并发环境下,各自运行测试多少次。
--only-print 只打印测试语句而不实际执行。
--detach=N 执行N条语句后断开重连。
--debug-info, -T 打印内存和CPU的相关信息。

接下来我们来执行一条更复杂的测试语句

并发分别为50,100并发,1000次查询,并进行迭代测试

[yangyang@mysqlvm1 ~]$ mysqlslap -a --concurrency=, --number-of-queries
--iterations= --debug-info -uroot -proot
Benchmark
Average number of seconds to run all queries: 0.147 seconds
Minimum number of seconds to run all queries: 0.132 seconds
Maximum number of seconds to run all queries: 0.163 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Average number of seconds to run all queries: 0.196 seconds
Minimum number of seconds to run all queries: 0.154 seconds
Maximum number of seconds to run all queries: 0.244 seconds
Number of clients running queries:
Average number of queries per client: User time 0.62, System time 1.02
Maximum resident set size , Integral resident set size
Non-physical pagefaults , Physical pagefaults , Swaps
Blocks in out , Messages in out , Signals
Voluntary context switches , Involuntary context switches

接下来我们来测试一个更大的查询次数,极端情况下,30000次查询,并减小并发量为20,50

[yangyang@mysqlvm1 ~]$ mysqlslap -a --concurrency=, --number-of-queries  --iterations= --debug-info -uroot -proot
Benchmark
Average number of seconds to run all queries: 60.339 seconds
Minimum number of seconds to run all queries: 55.709 seconds
Maximum number of seconds to run all queries: 63.855 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Average number of seconds to run all queries: 47.620 seconds
Minimum number of seconds to run all queries: 46.899 seconds
Maximum number of seconds to run all queries: 48.904 seconds
Number of clients running queries:
Average number of queries per client: User time 406.27, System time 781.33
Maximum resident set size , Integral resident set size
Non-physical pagefaults , Physical pagefaults , Swaps
Blocks in out , Messages in out , Signals
Voluntary context switches , Involuntary context switches

我们到portal中去观察结果

我们看到cpu的峰值使用情况达到了95.97%,这个时候我们再升到D12V2,执行相同的操作,看看结果如何

[yangyang@mysqlvm1 ~]$  mysqlslap -a --concurrency=, --number-of-queries  --iterations= --debug-info -uroot -proot
Benchmark
Average number of seconds to run all queries: 18.069 seconds
Minimum number of seconds to run all queries: 17.928 seconds
Maximum number of seconds to run all queries: 18.223 seconds
Number of clients running queries:
Average number of queries per client: Benchmark
Average number of seconds to run all queries: 16.130 seconds
Minimum number of seconds to run all queries: 15.414 seconds
Maximum number of seconds to run all queries: 18.134 seconds
Number of clients running queries:
Average number of queries per client: User time 174.35, System time 100.30
Maximum resident set size , Integral resident set size
Non-physical pagefaults , Physical pagefaults , Swaps
Blocks in out , Messages in out , Signals
Voluntary context switches , Involuntary context switches

我们回到portal里面来观察结果,我们去新portal去看,这里为了结果更准确,我执行了两次,所以第二幅图有两个峰值,这样结果更直观。

从上图可以看出,cpu最高也就在百分之五十左右,对于一般系统而言,前端不可能对后端有如此大的压力,即使在这种极端情况下,我们的虚拟机依然能承受,即使A6虚拟机也能承受,但是在这种极端情况我们不建议使用A系列虚拟机,D系列虚拟机性能比A系列高了百分之三十以上,再次证明,Azure的虚拟机性能是不容置疑的,本来笔者打算在linux系统中使用ps和top命令来查看cpu进程的,但是发现效果不是很良好,所以还是portal观察,但是portal的数据是有滞后性的,所以大家在观察的时候需要等待一会儿,一般十五分钟左右,本来我是想再测试一下DS系列虚拟机,但是由于普通存储盘的虚拟机无法升级到ssd的,所以就没有再去测试,如果有读者有兴趣可以去测试一下!!!

  

使用mysqlslap对mysql进行压测,观察Azure虚拟机cpu使用率的更多相关文章

  1. mysql常用压测工具

    关键字:mysql压测工具 mysqlslap.sysbench  基准测试sysbench 压力测试 tpcc  具体怎么使用百度

  2. sysbench对MySQL的压测,使用sysbench压测磁盘io

    QPS - query per secondTPS - transaction per second 不是特别关注,每个业务场景中事务标准是不一样的 Ⅰ.sysbench测试框架 Ⅱ.常用测试脚本 [ ...

  3. 关于mysql性能压测之tpcc

    软件下载: wget http://imysql.com/wp-content/uploads/2014/09/tpcc-mysql-src.tgz安装依赖:yum install -y mysql- ...

  4. 压力测试(四)-Mysql数据库压测实操

    1.Jmeter压测实战之JDBC request压测Mysql讲解 简介:讲解jdbc压测mysql相关准备工作,jar包添加,配置讲解 1.Thread Group -> add -> ...

  5. 压测过程中,CPU和内存占用率很高,案例简单分析

    Q:  最近公司测试一个接口,数据库采用Mongo    并发策略:并发400个用户,每3秒加载5个用户,持续运行30分钟    数据量:8000条左右 压测结果发现:    TPS始终在5左右   ...

  6. 关于mysql的压测sysbench

    测试表格:CREATE TABLE `sbtest` ( `id` int(10) unsigned NOT NULL auto_increment, `k` int(10) unsigned NOT ...

  7. sysbench对MySQL的压测

    QPS - query per second TPS - transaction per second 不是特别关注,每个业务场景中事务标准是不一样的 Ⅰ.sysbench测试框架 Ⅱ.常用测试脚本 ...

  8. MySQL Hardware--FIO压测

    FIO参数 .txt 支持文件系统或者裸设备,-filename=/dev/sda2或-filename=/dev/sdb direct= 测试过程绕过机器自带的buffer,使测试结果更真实 rw= ...

  9. cpu压测测试--------自己设定cpu需要跑到的压力

    下载压力测试包 https://pan.baidu.com/s/1DJYAzBHHDxMViy5dMel2Lw 提取码:a5j3 使用方法: 方法一:前端启动,按Ctrl+c结束 java -Dbus ...

随机推荐

  1. Jmeter实现登录bugfree、新建bug、解决bug脚本(抓包工具实现)

    环境 Chrome jmeter3.1 fiddler4 win7 32位 Linux CentOs6.4 bugfree3.0.1 链接:http://pan.baidu.com/s/1gfHpbp ...

  2. NGUI裁剪模型和粒子

    效果预览 注:Cube上附着的绿色是我添加的粒子效果. 软件环境 NGUI 3.9.x Unity 5.1 x64 相关知识 RenderTexture RenderTexture是一种特殊的纹理,它 ...

  3. 初识redis数据类型

    初识redis数据类型 1.String(字符串) string是redis最基本的类型,一个key对应一个value. string类型是二进制安全的.意思是redis的string可以包含任何数据 ...

  4. CSS3 基于关系的选择器

    常见的基于关系的选择器 选择器 选择的元素 A E 元素A的任一后代元素E (后代节点指A的子节点,子节点的子节点,以此类推) A > E 元素A的任一子元素E(也就是直系后代) E:first ...

  5. Linux多线程编程

    线程和进程的区别是: 进程是拷贝主进程的数据段和代码段的. 线程是和主进程公用一份数据段和代码段的. 线程一旦创建,就从指定的入口函数开始执行. 相关头文件: #include <pthread ...

  6. Weekly Traning Farm 16

    先安利一下这套比赛,大概是doreamon搞的,每周五晚上有一场,虽然没人做题目质量挺高的 http://codeforces.com/group/gRkn7bDfsN/contests(报名前要先报 ...

  7. .NET WebAPI 实现图片上传(包括附带参数上传图片)

    博主的项目,客户端是APP,考虑到以后也可能会应用到微信端.网站等,图片上传方法就需要兼容多端,并且以目前的设计,不允许非登录用户上传图片,就得在上传时解决附带参数上传图片的问题. 先来看看后台方法( ...

  8. caffe中卷积层和pooling层计算下一层的特征map的大小

    pool层,其中ceil是向上取整函数 卷积层:

  9. freemarker种种

    #include要使用绝对路径的话,在路径最前面加个"/"就行--<#include "/includes/v2/headerMacro.ftl"> ...

  10. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法

    原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 ...