Celery + gevent using only one CPU core

拈花ヽ惹草 提交于 2019-12-23 01:01:14

问题


I've issues with performance load running Celery with gevent, everything is running on the same core on my VPS.

Here's a screenshot of 4 Celery instance with 20 gevent concurrency each

How to fix this ? What am I doing wrong ?

Here's my first task :

def update_sender():
    items = models.Item.objects.filter(active=True).all()
    count = items.count()
    items = [i.id for i in items]
    step = count / settings.WORKERS
    for job in list(chunks(items, step)):
        update_item.apply_async(args=[job])

Calling the following sub task:

def update_item(items):
    for item in items:
        try:
            i = models.Item.objects.get(id=item)
            url = "someurl"
            rep = requests.get(url)
            jrep = rep.json()
            tracker = ItemTracker(i, jrep)
            if tracker.skip():
                continue
            if tracker.method1():
                if not tracker.method2():
                    tracker.method3()
                tracker.save()

It's all about doing a lot of HTTP requests and updating database concurrently.


回答1:


Celery with gevent still only uses a single process, its just starting multiple greenlets inside of the process, but it is still only executing one greenlet at a time. To allow using more than 1 core, you need to start multiple celery processes using something like celery-multi



来源:https://stackoverflow.com/questions/31106595/celery-gevent-using-only-one-cpu-core

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