[英]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.