pymongo性能测试脚本
2016/03/05 00:16 于 数据分析 0
最近开始接触mongodb,顺便用python的pymongo写了一个测试性能的脚本
[root@cloud ~]# cat /home/baishaohua/mongo_test.py
#!/usr/bin/python
import pymongo
import time,datetime
conn=pymongo.Connection('192.168.1.8',27017) #建立连接
db=conn.test #进入test库
col=db.people #进入people集合
print "Test Write==>" #开始写测试
atime=time.time() #记录开始时间戳atime
doc = { "high" : 175, "six" : "true", "phone_num" : 1222222, "name" : "str(i)" }
for i in range(1,1200000): #循环顺序写入120w次
col.insert(doc)
btime=time.time() #记录结束时间戳
print "Writeexec time:"
print btime-atime #计算执行市场
print "Test Read==>"
atime=time.time()
doc = { "name" : "str(i)" }
for i in range(1,1200000): #循环顺序读取120w次
col.find(doc)
btime=time.time()
print "Read exec time:"
print btime-atime
print "Test Delete==>"
atime=time.time()
doc = { "name" : "str(i)" }
for i in range(1,1200000): #循环顺序删除120w次
col.remove(doc)
btime=time.time()
print "Delete exec time:"
print btime-atime
微信扫描二维码了解更多 ->
[运维博客]
[运维博客](http://nginxs.blog.51cto.com/)