皮蒙戈 + gevent:扔给我一根香蕉然后只扔monkey_patch?

发布于 2024-12-01 10:36:41 字数 448 浏览 3 评论 0原文

这里快速地需要比我现在更多的 pymongo 领域专业知识:

pymongo 驱动程序的“正确”部分是用 python 编写的,以便我调用 gevent Monkey_patch() 并成功改变 pymongo 在 gevent“异步”内的读/写上的阻塞行为“小绿叶?

如果这需要在 gevent 和 pymongo 上做更多的工作——但这​​是可行的——我非常愿意投入时间,只要我能得到一些关于 irc 的指导。

谢谢!

注意:小规模的 mongo 写入并不是一个大问题,因为我们只是在解锁之前对写入“请求”进行排队。但是在与 fiorix 谈论他扭曲的异步 mongo 驱动程序 (https://github.com/fiorix/mongo-async-python-driver) 时,即使 mongo 的快速写入(请求)也会在大规模异步应用程序中导致问题。 (当然,非阻塞读取可能从一开始就会引起问题!)

Quickie here that needs more domain expertise on pymongo than I have right now:

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?

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.

Thanks!

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!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离旧人 2024-12-08 10:36:41

我已将 PyMongo 与 Gevent 一起使用,这里有一些您需要注意的事项:

  1. 仅实例化一个 pymongo.Connection 对象,最好作为全局或模块级变量。这很重要,因为Connection 本身就有一个池!
  2. 猴子修补所有内容,或者至少修补套接字和线程。由于Connection中使用了线程局部变量,仅修补套接字是不够的。
  3. 请记住调用 end_request 将连接返回到池中。

你的问题的答案是继续,PyMongo 与 Gevent 配合得很好。

I have used PyMongo with Gevent and here are a few things you need to watch out for:

  1. Instantiate only one pymongo.Connection object, preferrably as a global or module-level variable. This is important because Connection has within itself a pool!
  2. 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.
  3. Remember to call end_request to return the connection to the pool.

The answer to your question is go ahead, PyMongo works just fine with Gevent.

萌化 2024-12-08 10:36:41

初步检查时,它似乎没有在 c 代码中执行任何套接字操作,因此应该没问题(阻塞操作应该只阻塞绿色线程)。

On initial inspection it doesn't appear to do any socket operations in the c code so it should be fine (blocking ops should just block the green thread).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文