Recommended Services
Amazon Web Services
LeanCloud
New Relic
ClearDB
yueyoum
V2EX  ›  云计算

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

  •  
  •   yueyoum · Nov 2, 2015 · 6256 views
    This topic created in 3888 days ago, the information mentioned may be changed or developed.

    这三家我都有使用

    先说 使用感受

    • 青云最专业,后台控制面板也好用。关机只收部分费用也非常适合做测试机器
    • 阿里云没什么要说的,很均衡。不折腾就上阿里云。 就是有几次无故重启不通知
    • 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 replies    2015-11-18 00:33:40 +08:00
    huobazi
        1
    huobazi  
       Nov 3, 2015
    谢谢
    zhangv
        2
    zhangv  
       Nov 3, 2015
    青云+1
    bingwenshi
        3
    bingwenshi  
       Nov 18, 2015
    只有真正的用户才会认证的做这样的性能测试, 不像很多人在没有深度使用之前,就在网络上主观的乱喷
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   931 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 20:09 · PVG 04:09 · LAX 13:09 · JFK 16:09
    ♥ Do have faith in what you're doing.