日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python做数据库压力测试_Python 写的一个MongoDB压力测试

發(fā)布時(shí)間:2023/12/3 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python做数据库压力测试_Python 写的一个MongoDB压力测试 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Python 寫(xiě)的一個(gè)MongoDB壓力測(cè)試

$ 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()

《MongoDB 權(quán)威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htm

MongoDB 的詳細(xì)介紹:請(qǐng)點(diǎn)這里

MongoDB 的下載地址:請(qǐng)點(diǎn)這里

總結(jié)

以上是生活随笔為你收集整理的python做数据库压力测试_Python 写的一个MongoDB压力测试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。