问题描述
在这里,需要比我现在在pymongo上需要更多领域专业知识的Quickie:
Quickie here that needs more domain expertise on pymongo than I have right now:
是否用python编写的pymongo驱动程序的正确"部分为我调用gevent monkey_patch()并成功更改了gevent异步" greenlets中pymongo在r/w上的阻塞行为?
Are the "right" parts of the pymongo driver written in python for me to call gevent monkey_patch() and successfully alter pymongo's blocking behavior on r/w within gevent "asynchronous" greenlets?
如果这需要在gevent和pymongo上做更多的工作-但是这是可行的-只要我能对irc有所了解,我将非常愿意花时间.
If this will require a little more leg work on gevent and pymongo -- but it is feasible -- I would be more than willing to put in the time as long as i can get a little guidance over irc.
谢谢!
注意:在小规模的mongo上写并不是一个大问题,因为我们只是在取消阻塞之前对写请求"进行排队.但是与fiorix谈论他扭曲的异步mongo驱动程序(https://github.com/fiorix/mongo-async-python-driver),即使mongo的快速写入(请求)也可能在大规模异步应用程序中引起问题. (当然,非阻塞读取可能从一开始就引起问题!)
Note: At small scale mongo writes are not a big problem because we are just queuing a write "request" before unblocking. BUT talking to fiorix about his twisted async mongo driver (https://github.com/fiorix/mongo-async-python-driver), even mongo's quick write (requests) can cause problems in asyncronous applications at scale. (And of course, non-blocking reads could cause problems from the start!)
推荐答案
我在Gevent中使用了PyMongo,以下是需要注意的几件事:
I have used PyMongo with Gevent and here are a few things you need to watch out for:
- 仅实例化一个
pymongo.Connection
对象,最好将其实例化为全局或模块级变量.这很重要,因为Connection
自身内部有一个池! - 猴子打补丁所有东西,或者至少打补丁套接字和线程.由于在
Connection
中使用了线程局部变量,仅修补套接字是不够的. - 记住要调用
end_request
以将连接返回到池中.
- Instantiate only one
pymongo.Connection
object, preferrably as a global or module-level variable. This is important becauseConnection
has within itself a pool! - Monkey patch everything, or at least BOTH socket and threading. Due to the use of thread locals in
Connection
, patching socket alone is not enough. - Remember to call
end_request
to return the connection to the pool.
您的问题的答案是继续,PyMongo与Gevent配合得很好.
The answer to your question is go ahead, PyMongo works just fine with Gevent.
这篇关于pymongo + gevent:给我扔一个香蕉,然后给我monkey_patch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!