V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Recommended Services
Amazon Web Services
LeanCloud
New Relic
ClearDB
yueyoum
V2EX  ›  云计算

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

  •  
  •   yueyoum · 2015-11-02 18:06:24 +08:00 · 5194 次点击
    这是一个创建于 3069 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这三家我都有使用

    先说 使用感受

    • 青云最专业,后台控制面板也好用。关机只收部分费用也非常适合做测试机器
    • 阿里云没什么要说的,很均衡。不折腾就上阿里云。 就是有几次无故重启不通知
    • 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
    

    测试脚本:

    # -*- 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()
    
    3 条回复    2015-11-18 00:33:40 +08:00
    huobazi
        1
    huobazi  
       2015-11-03 09:15:42 +08:00
    谢谢
    zhangv
        2
    zhangv  
       2015-11-03 16:57:07 +08:00
    青云+1
    bingwenshi
        3
    bingwenshi  
       2015-11-18 00:33:40 +08:00
    只有真正的用户才会认证的做这样的性能测试, 不像很多人在没有深度使用之前,就在网络上主观的乱喷
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5409 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 08:55 · PVG 16:55 · LAX 01:55 · JFK 04:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.