Skip to content

Subscribe too much celery-task-meta using Redis backend #3808

Open

Description

@memwey

celery:4.0.2 python:3.5.2 redis:2.10.5 celery-with-redis:3.0.0
os:CentOS release 6.7 (Final) 64bit

With redis as backend, using redis-cli monitor command, when adding a task into celery, it actually uses the SUBSCRIBE command in redis. Like "SUBSCRIBE" "celery-task-meta-cb1792d7-9e9d-43d9-b374-3a8b15c97790"

In my code, it's something like this

a.py
def main():
    while True:
        call_celery()

def call_celery():
    chord((task_a.s(), task_b.s()), task_c.s())()

However, I found a strange thing that after adding an amount of tasks, redis will sometimes block and cause time out. It's caused by the a.py process. redis-cli monitor shows that a.py process is trying to subscribe a very huge amount of celery-task-meta, like
"SUBSCRIBE" "celery-task-meta-f6347dbe-c91b-4c95-bcbd-3dfefbcb2f46" "celery-task-meta-83f7be2a-2906-4e34-965a-47cec416d6df" "celery-task-meta-3c3e8eff-711d-4d44-bbd4-d36adea85ecd" "celery-task-meta-22492fff-2b7a-4e69-83de-71191e66861c" "celery-task-meta-1ae1f78a-ad78-47eb-a422-25d42a33fd83" "celery-task-meta-ed041055-f2cf-4f60-a531-dbc764dff5c4" ......

I wander why it behaves like this, is it a bug or a normal act?

Activity

  1. gugu commented on Feb 6, 2017

    @gugu

    It is how celery 4 work – instead of get/set it subscribes on changes for tasks in chord, as fas as I know

    UPD: subscribe is not a problem. But no "UNSUBSCRIBE" is a problem. I created bug #3812

  2. memwey commented on Feb 7, 2017

    @memwey
    Author

    @gugu I am curious that why does Celery do so. For example, when we use Celery in web for sending email, which I think it's a very common sense, the process which adds the task into the Celery does not exactly care about the result. So in Redis, maybe it should use PUBLISH instead of SUBSCRIBE?
    I notice that after SUBSCRIBE performance, there will always be a LPUSH followed, I guess it's used to avoid multiple workers achieve the same task.
    Oops, I'm now very curious about how Celery works. Do you have any idea or blog or something else?

  3. shidenggui commented on Mar 24, 2017

    @shidenggui

    celery:4.0.2 python:3.5.2 redis:3.2.1
    os: CentOS release 6.7 (Final)
    I also meet this problem. When I run celery some hours,It while be subscribe ten of thousands celery-task-meta-xxx, make redis very slow.Sometimes it made task.get() raise redis.exceptions.ResponseError: unknown command 'celery-task-meta-xxxx' error.

  4. auvipy commented on Jan 17, 2018

    @auvipy
    Member

    try the new release and docs and report the issue again

  5. wsYdd commented on Jan 23, 2018

    @wsYdd

    This new release is v4.2?
    When do you plan to release this version?

  6. auvipy commented on Jan 23, 2018

    @auvipy
    Member

    I will reopen if this can be reproduced in master. check the milestone only 1 documentation blocker remain

  7. VictorLeP commented on Jan 29, 2018

    @VictorLeP

    I still notice a SUBSCRIBE command with a growing list of celery-task-meta on master (using redis-cli monitor), when using RabbitMQ as broker and Redis as backend. The command is not monotonically growing, so sometimes tasks disappear again from the list (usually from the tail), but the trend is for the command to keep growing and for the tasks at the beginning of the list to stabilize.

    The sheer size of this command seems to eventually cause the ResponseError reported in #3808 (comment). So it seems this issue is still present.

    Report:

    software -> celery:4.2.0 (latentcall) kombu:4.1.0 py:3.6.3
                billiard:3.5.0.3 py-amqp:2.2.2
    platform -> system:Linux arch:64bit, ELF imp:CPython
    loader   -> celery.loaders.app.AppLoader
    settings -> transport:amqp results:redis://:**@**:6379/0
    
  8. added this to the milestone on Feb 7, 2018
  9. reopened this on Feb 7, 2018
  10. georgepsarakis commented on Feb 10, 2018

    @georgepsarakis
    Contributor

    @VictorLeP there are some channel subscriptions opened by the worker (in case of chord or other workflows using results) and also by the client that waits for the task result. So, depending on the usage, and how many tasks you have simultaneously being executed, you may see a growing number of channels. Are you certain that this appears on master?

  11. VictorLeP commented on Feb 13, 2018

    @VictorLeP

    @georgepsarakis Yes, I tested it with the latest master version (also tested with kombu's master version now). I use 'normal' tasks (sent using app.send_task), of which there is a constant stream to the workers, but I see in the worker logs that the tasks that appear in the growing subscription list have succeeded. In any case, there are appropriate timeouts and the task ID remain in the subscription list longer than the timeout.

  12. jetz commented on Feb 26, 2018

    @jetz

    Same issue. In my case, just a few calls like r = somefunc.delay(), produces millions of channels with about 33G memory used after serveral months, my server is trembling 😢, must we wait for v5.0?

  13. uday-rayala commented on Mar 18, 2018

    @uday-rayala

    We are facing the same issue. Creating new tasks becomes really slow and when I checked the SLOWLOG, we found subscribe calls with huge number of channels are very slow. It looked like these subscribe calls are made from kombu and I get the big subscribe calls after the queue size reaches around ~300k. It might be because of Redis having a limitation on the number of subscribed channels.

    Surprisingly, this happens even for tasks with ignore_result=True and not running a celery worker. I expected no subscribe calls made in this scenario. Then I found this code. I wonder if this reason for the subscribe calls. Can someone with more context about this help confirm?

  14. 44 remaining items

  15. added this to the 5.3.x milestone on Dec 2, 2022
  16. moved this from Todo to Low Priority in v5.3on Feb 19, 2023
  17. Mr-Slow commented on Apr 25, 2023

    @Mr-Slow

    Have this fixed?

  18. WeipingGuo commented on Apr 25, 2023

    @WeipingGuo

    Same question, we are upgrading from celery 4 to 5, hope this is fixed.
    We see the same issue for redis==3.5.3 and celery==4.4.0

    9) 1) (integer) 470046
        2) (integer) 1682982915
        3) (integer) 759268
        4)  1) "SUBSCRIBE"
            2) "celery-task-meta-28ca8a3e-c4e7-4be9-95bb-362d6947ddcb"
            3) "celery-task-meta-8f698cbb-4d78-49c3-8292-5342a3484d21"
            4) "celery-task-meta-7621a230-3ccb-424d-92dc-e5cec8dc0011"
            5) "celery-task-meta-4e898b69-7602-42e3-8aa1-8008540e0830"
    
  19. gaozhidf commented on May 30, 2023

    @gaozhidf

    same question, redis==3.3.11 and celery==4.3.0

  20. gaozhidf commented on May 30, 2023

    @gaozhidf

    Same question, we are upgrading from celery 4 to 5, hope this is fixed. We see the same issue for redis==3.5.3 and celery==4.4.0

    9) 1) (integer) 470046
        2) (integer) 1682982915
        3) (integer) 759268
        4)  1) "SUBSCRIBE"
            2) "celery-task-meta-28ca8a3e-c4e7-4be9-95bb-362d6947ddcb"
            3) "celery-task-meta-8f698cbb-4d78-49c3-8292-5342a3484d21"
            4) "celery-task-meta-7621a230-3ccb-424d-92dc-e5cec8dc0011"
            5) "celery-task-meta-4e898b69-7602-42e3-8aa1-8008540e0830"
    

    @WeipingGuo do you fix this after upgrading to celery 5?

  21. WeipingGuo commented on May 30, 2023

    @WeipingGuo

    @gaozhidf We have not completed the full upgrade yet, fingers crossed

  22. modified the milestones: 5.3.x, 5.5 on Jun 25, 2024
  23. modified the milestones: 5.5.0, 5.7.0 on Jun 10, 2025
  24. removed this from v5.3on Aug 20, 2026
  25. modified the milestones: 5.7.0, Future on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions