新鲜出炉,PCIE卡SQLServer和SSD Mongodb集群4千万数据insert测试
- - snoopyxdy的博客最近公司需要测试1亿条数据10分钟插入数据库,主要是为了数据推送留存用. 最终我们讨论给出了2套方案. 1、单台sqlserver 配合PCIE卡. 2、Mongodb分片集群. 因为目前数据量是4千万,所以我分别对4千万数据和1亿数据进行了写入测试. 被测试机器都是24CPU,64G内存的独立服务器.
# -*- coding: utf-8 -*-import _mssqlimport pymssqlimport datetime,timefrom multiprocessing import Processdef getTimestampFromDatetime(d=None):if d is None:d = datetime.datetime.now()return time.mktime(d.timetuple())def task(key):server = 'localhost:2433'user = 'testwzh'password = '123456'dbname = 'TCMobileNotification'str = u'来的真巧!这么好的东西只为你准备,你忍心让给别人吗?'all_data = (0,1,'d0118d2cffaf8000d0118d2cffaf8000',0,1,'2015-03-20 10:01:50.990',\str,'http://t.cn/RZsNwgG',71,\6, 9,'2015-03-27 10:01:50.990',0)listData = []for i in range(10000):listData.append(all_data)tableName = 'PushMessageSystem_{0}'.format(key)conn = pymssql.connect(server=server, user=user, password=password, database=dbname)cursor = conn.cursor()for i in range(0, 250000):cursor.executemany("INSERT INTO "+tableName+" VALUES (%d,%d,%s,%d,%d,%s,%s,%s,%d,%d,%d,%s,%d)",listData)conn.commit()conn.close()if __name__ == '__main__':proc_record = []keyList = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f',]for i in range(0,16):p = Process(target = task, args=(keyList[i],))p.start()proc_record.append(p)start = getTimestampFromDatetime()for p in proc_record:p.join()end = getTimestampFromDatetime()print('time: {0}s'.format(end-start))
# -*- coding: utf-8 -*-import pymongoimport jsonimport datetime,timeimport sysimport copyimport sys, osfrom multiprocessing import Processfrom hashlib import md5def getTimestampFromDatetime(d=None):if d is None:d = datetime.datetime.now()return time.mktime(d.timetuple())def md5Hash(str):m = md5()m.update(str)return m.hexdigest().upper()def task(key):mongoUri = 'mongodb://root:[email protected]:10000/admin'str = u'来的真巧!这么好的东西只为你准备,你忍心让给别人吗?'all_data = {'PMSID':1,'PMSPushTaskID':0,'PMSPlatform':1,'PMSDeviceID':md5Hash(key),'PMSReadCount':0,'PMSVisible':1,'PMSCreateTime':'2014-06-24 16:40:00.000','PMSContent':str,'PMSUrl':'http://t.cn/RZsNwgG','PMSTaskSN':71,'PMSPushType':6,'PMSProductType':3,'PMSExpiredTime':'2015-03-27 10:01:50.990','PMSContentType':0,}tableName = 'PushMessageSystem_{0}'.format(0)client = pymongo.MongoClient(mongoUri, max_pool_size=100)db = client.TCMobileNotificationfor i in range(0, 125):listData = []for i in range(10000):listData.append(copy.copy(all_data))db[tableName].insert(listData)if __name__ == '__main__':proc_record = []keyList = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f',0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f']for i in range(0,32):p = Process(target = task, args=(str(keyList[i]),))p.start()proc_record.append(p)start = getTimestampFromDatetime()for p in proc_record:p.join()end = getTimestampFromDatetime()print('time: {0}s'.format(end-start))