Repository navigation
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7612 +/- ##
==========================================
- Coverage 89.75% 89.75% -0.01%
==========================================
Files 138 138
Lines 17000 16998 -2
Branches 2509 2509
==========================================
- Hits 15259 15257 -2
Misses 1491 1491
Partials 250 250
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
auvipy
left a comment
There was a problem hiding this comment.
thanks for tackling this, would you please add some tests for this?
|
Will do! |
|
OK, I've updated with tests, and making it actually work 😁 (all existing tests used mock, to my surprise). |
auvipy
left a comment
There was a problem hiding this comment.
one failure
=========================== short test summary info ===========================
FAILED t/unit/concurrency/test_asynpool.py::test_AsynPool::test_subprocesses_are_spawned
= 1 failed,
forking_enable(True) is a no-op. False would set billiard's default context to spawn, but we do that explicitly in asynpool.py, which is better than global changes.
|
So... Windows appears to not support processes at the moment (https://github.com/celery/celery/blob/master/celery/worker/components.py#L140). So one of my points in original PR description above is not correct. However, Celery did used to support spawn-style process pools in the past, there's vestigial configuration for that which I removed. To deal with Windows failures I just skipped the test, and updated code to explain why. |
|
do we need to update some related documentation with versionadded 5.3 annotation? |
|
also check the integration tests failures please |
|
Will do. |
|
Oops apparently I ran integration tests in previous testing but not at the right time after I got the right code path sorted. And indeed, it does not work. And since Windows was not actually using spawn, that validation of spawn working is not available... so perhaps it degraded since it was last supported. In order for
Anything else? |
|
Interestingly the first task sent to a worker ( |
|
So I noticed billiard used to have a C extension that was supposedly required for execve mode to work. Is the extension module no longer necessary, or was it just not maintained, or something else? It's disabled on Python 3: https://github.com/celery/billiard/blob/master/setup.py#L232 |
|
(here's the reference to it being necessary for execv: https://github.com/celery/billiard/blob/master/setup.py#L33) |
|
also upgrading/syncing the billiard codes is a long overdue |
|
Here we can see some logs where the first task ( Any idea what might cause that, and any sense if it's related? |
Billiard itself needs a maintainer who knows what he's doing. The C extension, like every other component in billiard receives very little attention. |
|
@itamarst Good day, sir. We have had this same issue with celery in several different applications over the years. I last solved it with the spawn fix, but that's no longer an option since airflow needs a newer version of celery. We would be happy to help test this at scale once you're confident the PR is complete. |
|
Unfortunately I don't have time to work on this at the moment, so if someone else wants to take it up let me know. |
Is there some information - or documentation - on what Billiard actually does? What was/is the rationale for replacing multiprocessing? |
|
@itamarst I get a weird crash, and the following warning when trying to run celery with your PR: /home//miniconda3/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown Any ideas why? |
|
@sabetAI I never got this to working state, sorry... Will close to prevent confusion. Still would be nice if someone could figure out how to do this. |
|
@itamarst no worries. Do you have a dockerfile I can use to reproduce? |
|
FWIW, I would love to see this taken forward. It seems clear that this core fork-versus-spawn functionality of Celery is broken in multiple use cases and with a variety of hard-to-track down symptoms, but it also seems clear that no one person has the knowledge+willingness to drive this to conclusion. Might it be possible to draw together a small group to work on this in some collaborative fashion? |
|
@ShaheedHaque @itamarst yes! In particular, Celery multi-processing doesn't play well with CUDA. Know any fixes? |
|
I am not sure celery multiprocessing was designed to work with CUDA. you should try Dask / Ray for that I think |
|
It does work with CUDA, you just have to make 100% sure that no CUDA code is executed by the root (parent) process :) |
|
@adampl interesting, can you share a link so I can read up further on that? Do I disable CUDA on parent by running torch code only if os.getpid != os.getppid()? |
|
I just import all the CUDA-related stuff inside the task functions. The trick with PIDs may work too. That way no CUDA context is ever initialized in the parent process. I also use the Celery Max Tasks Per Child=1 setting so that the child process is deleted when the task is finished, to ensure full cleanup. |
some models are 10+ Gb, sometimes it can be very costly to do cleanup after every task |
Yes, but unfortunately many libraries don't properly manage GPU resources, causing subsequent tasks to fail. |
|
hey good peoples! we got a new approach here to fix it #9810 . please check it out |
Note: Before submitting this pull request, please review our contributing
guidelines.
Description
Fixes #6036
Rather than making the pool strategy configurable, this always uses
spawn, for the following reason:fork()withoutexecve()is fundamentally broken. See the many many complaints in Allow celery to spawn rather than fork #6036, and also https://pythonspeed.com/articles/python-multiprocessing/. I have helped multiple people fix mysterious problems caused byfork()withoutexecve()as well in non-Celery contexts; it's just not possible to work correctly.fork()withoutexecve()has no benefits! It won't save much memory: shared libraries and the Python executable will already be shared by the OS, and Python objects trigger copy-on-write anytime e.g. a refcount changes. It will speed up startup, very slightly. Neither is particularly useful.Turns out Windows always uses threads (https://github.com/celery/celery/blob/master/celery/worker/components.py#L140).spawnis already what Windows uses, so it's known to work.So instead of an extra knob to disable a broken-by-default feature, this just uses a correct-by-default and consistent-across-platforms default, with no knob to turn it off. (The blocking issue on Windows is not related to spawn AFAICT, and Windows always spawn).