登录  /  注册
Python 写的一个MongoDB压力测试
php中文网
发布: 2016-06-07 15:53:21
原创
1341人浏览过

Python 写的一个MongoDB压力测试 $ pip install pymongo #!/usr/bin/env python#coding=utf-8#Author: Ca0Gu0 from pymongo impo

Python 写的一个MongoDB压力测试

$ pip install pymongo

#!/usr/bin/env python
#coding=utf-8
#Author: Ca0Gu0

from pymongo import MongoClient
import datetime,time

class MongCli(object):

def __init__(self, host="127.0.0.1", port=27017, user='pytest', passwd ='pytest123', database="pytest"):

self.host = host
self.port = port
self.user = user
self.passwd = passwd

self.database = database

client = MongoClient(self.host, self.port)
client.the_database.authenticate(self.user, self.passwd, source=self.database)

self.db=client[self.database]
self.posts = self.db.posts

def t(self, args1=None, args2=None):

c=datetime.datetime.now()
print "%s|%s... |%s|Row:%s| %s" %(self.host, args1, args2, self.posts.count(), c.strftime("%Y-%m-%d %H:%M:%S"))
return c



def write(self,number=100):
start = self.t(args1="start", args2="write")
for i in range(number):
post = {"author": "Mike"+str(i),
"text": "My first blog post!"+str(i),
"tags": ["mongodb", "python", "pymongo"],
"date": datetime.datetime.utcnow()}


post_id = self.posts.insert_one(post).inserted_id
end = self.t(args1="end", args2="write")
print "Total write runtime: %ss" %str((end-start).seconds)

def read(self):
start = self.t(args1="start", args2="read")
output = open("output.txt", 'w')
for post in self.posts.find():
try:
output.write(str(post)+"\n")
except Exception,e:
print e
output.close()
end = self.t(args1="end", args2="read")
print "Total read runtime: %ss" %str((end-start).seconds)
print "----------Split--------"


if __name__ == "__main__":
f = MongCli(host="127.0.0.1", port=27017, user='admin', passwd ='admin', database="admin")
f.write(20000)
f.read()

Python 写的一个MongoDB压力测试

MongoDB 3.0 正式版发布下载

CentOS编译安装MongoDB

CentOS 编译安装 MongoDB与mongoDB的php扩展

CentOS 6 使用 yum 安装MongoDB及服务器端配置

Ubuntu 13.04下安装MongoDB2.4.3

MongoDB入门必读(概念与实战并重)

Ubunu 14.04下MongoDB的安装指南

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

Nagios监控MongoDB分片集群服务实战

基于CentOS 6.5操作系统搭建MongoDB服务

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

本文永久更新链接地址

来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学