简体   繁体   English

Django +芹菜+请求+事件

[英]Django + Celery + Requests + Eventlet

I have a Django + Celery project. 我有一个Django + Celery项目。 One of the Celery tasks does a lot of small HTTP requests using the requests library, while others do lots of talking to the database via the Django ORM. Celery任务之一使用请求库执行许多小型HTTP请求,而其他任务则通过Django ORM与数据库进行大量对话。 The HTTP-heavy task is already running in its own celery worker using its own Celery queue. 繁重的HTTP任务已经使用自己的Celery队列在其自己的celery worker中运行。 I'd like to make the HTTP-heavy worker use eventlet while leaving the rest of the tasks to use the prefork execution pool. 我想让HTTP繁重的工作人员使用eventlet,而其余的任务留给prefork执行池使用。 How do I do this? 我该怎么做呢?

The Celery docs seem to suggest that I gain magical concurrency powers by just running celery ... -P eventlet . Celery文档似乎建议我通过运行celery ... -P eventlet获得神奇的并发能力。 However, this SO answer says that I need to use a patched version of the requests library. 但是, 这样的答案说我需要使用请求库的修补版本。 Which is correct? 哪个是对的? Additionally, if I have to explicitly patch requests, do I have to put this task in a separate module from the rest of the regular tasks so that these other tasks can continue using the regular version of requests? 另外,如果我必须显式修补请求,是否必须将此任务与其余常规任务放在单独的模块中,以便其他任务可以继续使用常规版本的请求?

TL,DR: use patched version of requests library. TL,DR:使用请求库的修补版本。 No need to start separate module. 无需启动单独的模块。

celery -P eventlet gives you celery jobs concurrency. celery -P eventlet使您的celery作业并发。 They may or may not call eventlet.monkey_patch() to make all code compatible. 他们可能会或可能不会调用eventlet.monkey_patch()使所有代码兼容。 They may also change it in future. 他们将来也可能会更改它。 Explicitly using patched version removes ambiguity while also providing useful documentation. 明确使用修补程序版本可消除歧义,同时还提供有用的文档。

There is no point in separating concurrent requests from blocking. 将并发requests与阻塞分开是没有意义的。 Your prefork pool can also use concurrent version. 您的prefork池也可以使用并发版本。 Eventlet doesn't poison things with something bad. Eventlet不会因不良而使事物中毒。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM