0

0

Python 写的一个MongoDB压力测试

php中文网

php中文网

发布时间:2016-06-07 15:53:21

|

1899人浏览过

|

来源于php中文网

原创

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

 

立即学习Python免费学习笔记(深入)”;

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 正式版发布下载 

火山写作
火山写作

字节跳动推出的中英文AI写作、语法纠错、智能润色工具,是一款集成创作、润色、纠错、改写、翻译等能力的中英文 AI 写作助手。

下载

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 的下载地址:请点这里

本文永久更新链接地址

相关文章

python速学教程(入门到精通)
python速学教程(入门到精通)

python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

2

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

2

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

0

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

29

2025.12.24

yandex外贸入口合集
yandex外贸入口合集

本专题汇总了yandex外贸入口地址,阅读下面的文章了解更多内容。

58

2025.12.24

添加脚注通用方法
添加脚注通用方法

本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。

1

2025.12.24

重启电脑教程汇总
重启电脑教程汇总

本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。

3

2025.12.24

纸张尺寸汇总
纸张尺寸汇总

本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。

5

2025.12.24

Java Spring Boot 微服务实战
Java Spring Boot 微服务实战

本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。

1

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
RunnerGo从入门到精通
RunnerGo从入门到精通

共22课时 | 1.7万人学习

0基础快速上手自动化测试
0基础快速上手自动化测试

共8课时 | 0.4万人学习

Django 教程
Django 教程

共28课时 | 2.4万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号