-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: adding the ability to use Ray Serve async functionality #3769
feat: adding the ability to use Ray Serve async functionality #3769
Conversation
… async This is to fix deepset-ai#2968
Hi @vblagoje, |
Hey @zoltan-fedor this is not my area of expertise but I'll ping a colleague and he'll get back to you |
Thanks @vblagoje, much appreciated. |
Hey @zoltan-fedor! I've been on holiday, that's why the PR went on @vblagoje in the meantime 🙂 I'll review the Python side of this PR shortly, but before merging I hope we can get someone more expert with Ray from the rest of the team to look over these changes 👍 |
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.
A couple of question marks but otherwise really nice PR 😊 It's way simpler than I imagined!
Hi @ZanSara, Yes, I too thought that adding async will be more complicated and had to spent quite some time on figuring out how to make it the least invasive. |
My colleague left the following comments: There is 99% code duplication between Pipeline.run and Pipeline.run_async , not sure however whether this can be implemented in a cleaner way.
|
Responding to the comments from @vblagoje's colleague:
|
Thank you @vblagoje for getting the reviewer's comment! My two cents on code duplication: I agree that in the general case I would not like this amount of duplication, but here I believe we should tolerate it. That part of Pipeline is rock stable lately, and as we are planning to revisit how Pipeline works from the foundations, no point touching it now for a small optimization. Luckily this is a very simple change that will give us a good example how to run pipelines async and is immediately useful to @zoltan-fedor. So I'm ok for merging it as it is. If you don't agree, let's discuss 🙂 |
I am ok since all three of you agree that it is good to go. I don't know this part of the codebase well, but since three engineers who know the subject matter agree - I am approving. |
Thank you both for reviewing and approving. |
As I have explained in issue #2968 , a deployment on Ray Serve can be called
async
, which can make a lot of sense, as Ray Serve is typically used to serve large ML models - which means it takes a while for each request sent to a cluster of Ray Serve Deployment to return (from a few ms up to about a 100ms depending on the size of the model used).As such, it makes sense to build a concurrent (eg
async) application using an async web framework like FastAPI (or recently even Flask started supporting
async`) and then send the requests to Ray Serve in an async fashion (alias without blocking), which means that while the Ray Serve Deployment is working on the request, the application is not blocked, but can work on other requests.Unfortunately until now Haystack has only supported the calling of Ray Serve deployments in a sync fashion.
This PR is to add the ability to call the same Ray Serve deployments in an async fashion too.
This means that what is deployed into Ray Serve does NOT change, the only thing changes is how we are calling the deployment from the Ray client in Haystack.
Unfortunately making async calls require the methods containing the async call (typically
await [call]
) code to be marked as async and then that method to be called withawait
, so unfortunately some duplication of methods was required (seepipelines/base.py::Pipeline.run()
andpipelines/base.py::Pipeline.run_async()
) , but tried to minimize it as much as possible.Now you can call a Ray Serve deployment async the following way.
The original (sync) call:
The new, async option was made to be very similar:
Related Issues
async
functionality #2968Proposed Changes:
I have added the ability to call a Ray Pipeline Deployment from Haystack in an async fashion in addition to the old sync one.
How did you test it?
I have added a dedicated test to the new async method.
I have also tested it on a live Ray Serve cluster.
Notes for the reviewer
@ZanSara, this is what we have discussed earlier - some code repetition was unfortunately required, but managed to keep it to the minimum, see
pipelines/base.py::Pipeline.run()
andpipelines/base.py::Pipeline.run_async()
.The
run_async()
method is very much the same asrun()
, the only difference is theawait
call in it.Checklist