因為有個專案的場景是,大量寫操作,非常少量的讀操作
因此這裡測試下mysql資料的寫效能
建表
create table `data` (
`id` int(11) not null auto_increment,
`value` double default null,
`time` datetime default null,
`monitor_id` int(11) default null,
primary key (`id`)
) engine=myisam auto_increment=200002 default charset=latin1
測試1 每插入一條記錄,建立關閉一次連線
import time
import mysqldb
import random
def solve():
conn=mysqldb.connect(host="localhost",user="root",passwd="",db="test",charset="utf8")
cursor = conn.cursor()
sql = "insert into data(monitor_id, time, value) values(%s, %s, %s)"
mid = random.randint(0,2000)
time_str = time.strftime('%y-%m-%d %h:%m:%s', time.localtime())
value = random.uniform(10000, 2000000)
param = (mid, time_str, value)
n = cursor.execute(sql,param)
cursor.close()
conn.close()
t1 = time.time()
num = 100000
for i in range(num):
solve()
t2 = time.time()
print (t2 - t1)
測試2 在乙個連線中提交所有記錄
import time
import mysqldb
import random
conn=mysqldb.connect(host="localhost",user="root",passwd="",db="test",charset="utf8")
cursor = conn.cursor()
def solve():
global conn
global cursor
sql = "insert into data(monitor_id, time, value) values(%s, %s, %s)"
mid = random.randint(0,2000)
time_str = time.strftime('%y-%m-%d %h:%m:%s', time.localtime())
value = random.uniform(10000, 2000000)
param = (mid, time_str, value)
n = cursor.execute(sql,param)
t1 = time.time()
num = 100000
for i in range(num):
solve()
t2 = time.time()
print (t2 - t1)
cursor.close()
conn.close()
實驗結果:
型別record/second
實驗1100000/63=1587
實驗2100000/16=6250
看來單個mysql 的寫入速度已經足夠快了,沒有必要在搞什麼集群什麼的了。
MySql效能測試
mysql版本 mysql引擎 表結構 資料量 3000萬條左右 1 使用primary key進行查詢 2 使用索引進行查詢 注意資料型別,如果查詢條件為account no 26850則不會走索引查詢 在1 2中如果有order by欄位,其生效於where刪選資料之後,所以如果where篩選後...
mysql效能測試
伺服器 cpu 2ghz,記憶體 4g,物理機 系統 centos 5 32位 網路 100mbps 區域網 客戶端 cpu 2ghz,記憶體 4g 系統 centos 5 32位 資料量 1000萬條記錄 mysql版本 5.1.51 log 測試方法 把mysql掛到dns軟體後面,用bind的...
mysql效能測試
伺服器 cpu 2ghz,記憶體 4g,物理機 系統 centos 5 32位 網路 100mbps 區域網 客戶端 cpu 2ghz,記憶體 4g 系統 centos 5 32位 資料量 1000萬條記錄 mysql版本 5.1.51 log 測試方法 把mysql掛到dns軟體後面,用bind的...