[[Django Celery]] Celery blocked doing IO tasks

三世轮回 提交于 2019-12-08 05:28:45

问题


I use celery to do some IO tasks, such as grab remote image, sending email to users. But celery sometimes blocked with no logs. At this time, it won't do any task i send. I have to restart it, it begin to work where it blocked.

It puzzles me for a very long time. What can i do ? And what is the best practice for distributing IO tasks with celery?


回答1:


By default, celery worker fork several processes waiting for tasks request from client. For the tasks of IO pending and your system need a larger number of concurrency that handle request concurrently. Here is the command:

    celery -A tasks worker --without-heartbeat -P threads --concurrency=10

If simutanelous income requests is a lot, your concurrency level have to set higher than the size of incoming reqeust burst. The system's performance may be limited by the hardware memeory size or OS's select API. You can use celery's thread/ gevent model when concurrency is large:

    celery -A tasks worker --without-heartbeat -P threads --concurrency=1000

or

    celery -A tasks worker --without-heartbeat -P gevent --concurrency=1000



回答2:


you can increase the celery concurrency

manage.py celeryd   --concurrency=3  

where concurrency == number of processors

run shell command

   grep -c processor /proc/cpuinfo

to get number of processors on your machine



来源:https://stackoverflow.com/questions/12950682/django-celery-celery-blocked-doing-io-tasks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!