-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(udf): support multiprocess pool for CPU-bound Python UDFs #13838
Conversation
Signed-off-by: Runji Wang <[email protected]>
Signed-off-by: Runji Wang <[email protected]>
Signed-off-by: Runji Wang <[email protected]>
Signed-off-by: Runji Wang <[email protected]>
src/udf/python/risingwave/udf.py
Outdated
if io_threads is not None: | ||
self._executor = ThreadPoolExecutor(max_workers=io_threads) | ||
elif workers is not None: | ||
self._executor = get_reusable_executor(max_workers=workers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pondering whether io_threads
can also be replaced by this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But using threads is more efficient than processes, because multiprocess needs pickling (serializing code) and data transfer between processes. That's why it's even slower than single thread mode for not very computationally heavy functions. 🤪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit about the "Timing results"? Why the first one is slower with worker=10 🤪
BTW, might also trying compare throughputs, like #11508 (comment) does with nexmark generator
…rocess Signed-off-by: Runji Wang <[email protected]>
The overhead of data exchange between processes looks too large. I'm looking for some other ways, like spawning separate Arrow Flight servers on each process and enabling the |
Closed this PR as the overhead of multiprocessing is too large. We would like to recommend another approach to scale Python UDF server: start a server on each CPU core and use a proxy such as Nginx to do load balance. See: https://github.com/risingwavelabs/risingwave-docs/pull/1680 |
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
partially-resolve #13744
This PR adds a multiprocess pool to run CPU bound Python functions. Users can add the
workers
option in@udf
or@udtf
to enable parallel execution:Timing results:
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
Python UDFs now support multiple
workers
to run CPU-bound functions.