简体   繁体   English

为什么我在mongodb中获得了读写性能?

[英]why I get the wield read / write performance in mongodb?

I use python to test the performance of tornado async performance asending. 我使用python测试龙卷风异步性能提升的性能。 my code as below. 我的代码如下。 then I use ab tool (apache benchmark) to test the performance. 然后我使用ab工具(Apache基准测试)来测试性能。 I get the performance of insert op is better than the read one. 我得到的插入操作的性能优于读取的。 why ? 为什么呢?

insert operation: Requests per second: 1323.44 [#/sec] (mean) 插入操作: Requests per second: 1323.44 [#/sec] (mean)

Read operation: Requests per second: 352.08 [#/sec] (mean) 读取操作: Requests per second: 352.08 [#/sec] (mean)

=======code========== =======代码==========

import asyncmongo

client = asyncmongo.Client("pool1",host = '127.0.0.1', port = 27017, dbname='testdb')

import tornado.web
import tornado.httpserver
import tornado.ioloop

class InsertHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    def get(self):
    friends = client.connection('friends')
    friends.insert( {"AsyncInsert":1},callback=self.on_writen)

    def on_writen(self,response,error):
    self.write("Async insert ~ !")
    self.finish()


class ReadHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    def get(self):
    friends = client.connection('friends')
    friends.find_one( {'AsyncInsert':1}, callback=self.on_read)

    def on_read(self,response,error):
    self.write("Async read ~ !")
    self.finish()




if __name__ == "__main__":
    app = tornado.web.Application([(r'/insert/',InsertHandler),(r'/',ReadHandler)])
    server = tornado.httpserver.HTTPServer(app)
    server.listen(9005)
    tornado.ioloop.IOLoop.instance().start()

MongoDB write operation performance depends on many factors such as the amount of indexes used or document growth on updates. MongoDB写入操作的性能取决于许多因素,例如使用的索引数量或更新时文档的增长。

It is important to note that the duration of the insert call of your MongoDB driver significantly depends on the write concern ( Errors Ignored, Unacknowledged, Acknowledged, Journaled, Replica Acknowledged ) chosen. 重要的是要注意,MongoDB驱动程序的插入调用的持续时间在很大程度上取决于所选的写入关注点忽略的错误,未确认的错误,已确认的错误,已记录的日志,已确认的副本 If you use Errors Ignored or Unacknowledged the driver sends the write operation without any acknowledgment. 如果您使用“忽略的错误”或“ 未确认错误” ,驱动程序将发送写入操作,而不会进行任何确认。 Those writes are significantly faster than acknowledged writes, at least in terms of method duration of your driver. 至少在驱动程序的方法持续时间方面,这些写入要比确认的写入快得多。 Note that there was a default write concern change in all official drivers. 请注意,所有正式驱动程序都有默认的写关注更改。

In your particular case I would guess that you are using Unacknowledged write concerns. 在您的特定情况下,我猜您正在使用未确认的写入问题。 Running similar code i get the following results: 运行类似的代码,我得到以下结果:

Insert with unacknowledged writes: Requests per second: 1373.51 [#/sec] (mean) 以未确认的写入插入: Requests per second: 1373.51 [#/sec] (mean)
Insert with acknowledged writes: Requests per second: 619.33 [#/sec] (mean) 插入已确认的写入: Requests per second: 619.33 [#/sec] (mean)
Reads: Requests per second: 740.99 [#/sec] (mean) 读取: Requests per second: 740.99 [#/sec] (mean)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 Python 中为每个人创建具有完全读/写权限的文件夹时,不允许出现 Errno 1 操作? - Why do I get a Errno 1 Operation not permitted when the folder is created with full read/write permissions for everyone in Python? 为什么即使关闭临时文件也能写入和读取临时文件? - Why am I able to write to and read a tempfile even after closing it? 从大型MongoDB读取,写入JSON - Read from large MongoDB, write to JSON 当我向textfile写一个变量时,为什么我会得到'none' - why do i get 'none' when i write a variable to textfile 当我打开要首先写入的文件时,为什么在File.open中无法读取任何内容? - Why I can't read anything with File.open in python when I open the file to write first? 为什么我用f.write得到空行? - Why do I get empty lines wtih f.write? Opencv:为什么在不做任何更改的情况下读写图像时文件大小会更改? - Opencv: Why does the file size change when I read and write an image without making any changes? 为什么我可以在 class 之外写入和读取双下划线变量,它们没有被破坏吗? - Why can I write and read double-underscore variables outside a class, are they not mangled? 为什么我不能让 python 读取 RegisteredOwner 注册表项? - Why can't I get python to read RegisteredOwner registry key? 为什么读写模式不起作用? - Why doesn't the read and write mode work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM