Hello! Thank you for joining the Ray community Charles and sharing your use case with us
I’ve done some researched in the docs and I think I have the answers to your questions!
- As you can see we need some global vars,
workers
ortask_manager
but is it OK to have such global var in the API replica ?
Using global variables like task_manager
or workers
can work in simple setups, but as your system scales, it can become tricky. Globals can cause issues with state management, concurrency, and fault tolerance. Instead:
- Use Ray Actors: Actors allow you to manage shared state, and manage it safely across tasks. For example, you could have an actor to manage your DB pool or any shared dependencies. This keep things synced.
- You can read more about it here: Anti-pattern: Using global variables to share state between tasks and actors — Ray 2.41.0
Your FastAPI setup seems correct though so I don’t think you necessarily need to change it.
- Is it a good way of using Ray workers, are we going to have so issues down the line ?
It seems like a good use case for Ray workers! Don’t really see any issues here Just make sure to stay on top of resource management.
- Do you see things we could do better?
Try out some of the Ray debugging tools to help debug any potential issues that may arise. There’s also some nice user guides out there that might be helpful. I’ll link them here!