服務器硬件配置:172.16.16.169 CPU:2*E5620 @ 2.40GHz、內存:8Gpython
客戶端硬件配置:172.16.40.92 CPU: 4*I5-4300U@ 1.90GHz、內存:4Gmysql
數據庫:mongodb V3.0.6web
開發環境:python3.4.三、pycharm4.5.4算法
#./mongod --dbpath=/data/db --logpath=/data/log
#./mongo
> db.serverStatus()"storageEngine" : {"name" : "mmapv1"
#./mongod --dbpath=/data/wiredtiger --logpath=/data/wiredtiger/log
#./mongo 127.0.0.1:11111
> db.serverStatus()"storageEngine" : {"name" : "wiredTiger"
import time import datetime import timeit import math ISOTIMEFORMAT = '%Y-%m-%d %X' from pymongo import MongoClient mc = MongoClient("172.16.16.169",27017) db = mc.users def dateDiffInSeconds(date1,date2): timedelta = date2 - date1 return timedelta.days*24*3600 +timedelta.seconds date1 = datetime.datetime.now() db.users.drop() for i in range(0,1000000) :db.users.insert({"name":"ljai","age":i,"addr":"fuzhou"}) c = db.users.find().count() print("count is ",c) date2 = datetime.datetime.now() print(date1) print(date2) print(dateDiffInSeconds(date1,date2),"seconds") mc.close()
8. 測試結果:100萬條數據寫入花費了12分鐘28秒:sql
二、 python鏈接MongoDB WiredTiger寫入配置:mongodb
import time import datetime import timeit import math ISOTIMEFORMAT = '%Y-%m-%d %X' from pymongo import MongoClient mc = MongoClient("172.16.16.169",27017) db = mc.users def dateDiffInSeconds(date1,date2): timedelta = date2 - date1 return timedelta.days*24*3600 +timedelta.seconds date1 = datetime.datetime.now() db.users.drop() for i in range(0,1000000) :db.users.insert({"name":"ljai","age":i,"addr":"fuzhou"}) c = db.users.find().count() print("count is ",c) date2 = datetime.datetime.now() print(date1) print(date2) print(dateDiffInSeconds(date1,date2),"seconds") mc.close()
9. 測試結果:100萬條數據寫入花費了10分3秒:數據庫