阿里云, ucloud, 青云 mysql 性能 简单测试

2015-11-02 18:06:24 +08:00
 yueyoum
这三家我都有使用

先说 使用感受

* 青云最专业,后台控制面板也好用。关机只收部分费用也非常适合做测试机器
* 阿里云没什么要说的,很均衡。不折腾就上阿里云。 就是有几次无故重启不通知
* ucloud 问题很多,比如 购买的 IP 无法访问 mailgun, 创建主机失败,只能删了重新创建。 网络突然故障, github 无法 clone


这几天有想法 测一下 这三家提供的 mysql 读写性能如何, 于是写了下面的脚本。
先说一下这三家 mysql 的配置:

* 青云是最低一档的 1 核 2G mysql5.5 , 配置默认
* ucloud 是最低一档 600M 内存, mysql5.6 标准版,默认配置
* 阿里云是 第二档 600M 内存, mysql5.5 ,默认配置

所以这是一个**不严谨**的测试,因为这些机器都是早就买好的。所以无法做到测试环境一模一样。


## 测试结果:
每家各测试多次,结果比较稳定,就选取其中的一次结果:

#### 青云
```
INSERT ONE 3.25666999817
INSERT MANY 0.217604875565
QUERY 3.51868581772
```
#### ucloud
```
INSERT ONE 5.17626905441
INSERT MANY 1.33850288391
QUERY 2.40842795372
```

#### 阿里云
```
INSERT ONE 5.36786603928
INSERT MANY 0.239859104156
QUERY 5.58612704277
```


## 测试脚本:

```python

# -*- coding: utf-8 -*-

import os
import time
import random
import base64
import MySQLdb


MYSQL_HOST = '127.0.0.1'
MYSQL_PORT = 3306
MYSQL_USER = 'root'
MYSQL_PASSWORD = 'root'
MYSQL_DB = 'bench_test'

max_num = 10000

conn = MySQLdb.connect(
host=MYSQL_HOST, port=MYSQL_PORT, db=MYSQL_DB,
user=MYSQL_USER, passwd=MYSQL_PASSWORD
)

# 数据库需要提前建立好,但是表不用
cursor = conn.cursor()
sql = """create table if not exists test (
id integer not null primary key,
age integer not null,
name varchar(255) not null
)"""
cursor.execute(sql)
conn.commit()
cursor.close()

# 生成测试数据
DATA = []
for i in range(max_num):
DATA.append((i+1, i+1, base64.b64encode(os.urandom(64))))


def insert_one_test():
cursor = conn.cursor()
cursor.execute("delete from test")

start = time.time()
for value in DATA:
cursor.execute('insert into test (id, age, name) values (%s, %s, %s)', value)

conn.commit()
cursor.close()

print "INSERT ONE", time.time() - start

def insert_many_test():
cursor = conn.cursor()
cursor.execute("delete from test")

start = time.time()

start_index = 0
batch_amount = 2000
while start_index < max_num:
values = DATA[start_index: start_index+batch_amount]
cursor.executemany("insert into test (id, age, name) values (%s, %s, %s)", values)

start_index += batch_amount

conn.commit()
cursor.close()

print "INSERT MANY", time.time() - start


def query_test():
cursor = conn.cursor()

start = time.time()

for i in range(10000 * 1):
_id = random.randint(1, max_num)
cursor.execute("select id, age, name from test where id = %s", (_id,))
result = cursor.fetchone()
assert result[1] == _id

print "QUERY", time.time() - start


if __name__ == '__main__':
insert_one_test()
insert_many_test()
query_test()

```
5224 次点击
所在节点    云计算
3 条回复
huobazi
2015-11-03 09:15:42 +08:00
谢谢
zhangv
2015-11-03 16:57:07 +08:00
青云+1
bingwenshi
2015-11-18 00:33:40 +08:00
只有真正的用户才会认证的做这样的性能测试, 不像很多人在没有深度使用之前,就在网络上主观的乱喷

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/233000

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX