From
from ray import serve
class MyBackend:
def __call__(self, flask_request):
...
serve.init()
serve.create_backend("backend:v1", MyBackend)
serve.create_endpoint("endpoint", backend="backend:v1")
serve.set_traffic(...)Change:
- serve.init()
+ client = serve.start()
- serve.create_backend("backend:v1", MyBackend)
+ client.create_backend("backend:v1", MyBackend)
- serve.create_endpoint("endpoint", backend="backend:v1")
+ client.create_endpoint("endpoint", backend="backend:v1")
- serve.set_traffic(...)
+ client.set_traffic(...)- Case 1: If you are launching an ephemeral development Serve instance, you should just use
serve.start() - Case 2: If you are launching a long-running detached Serve instance, you should run
serve.start(detached=True). The instance will not be destroyed after the script exits. - Case 3: If you are just connecting a long-running detached Serve instance, you should run
serve.connect(). This assumes there is already a long-running instance started via `serve.start(detached=True).
Note: serve.start/connect are orthogonal to the underlying Ray cluster. The rule is simple:
- If there isn't a Ray cluster connected, then Serve will start one via
ray.init. The Ray cluster will be torn down on script exit. - If there is already a Ray cluster connected, then Serve will use the one connected.
The Servable API (protocol for your backend implementation) was simplified. Instead of:
class MyHandler:
def __call__(self, flask_request, *, arg_1=None, arg_2=None)You can it to just:
class MyHandler:
def __call__(self, request)The Python arguments and data are accessible via request object, which is a ServeRequest object that has similar API as Flask.Request. Learn more: https://docs.ray.io/en/master/serve/advanced.html#how-do-servehandle-and-serverequest-work
For batching, the input requests will now be a list of requests. If you can sending requests both from web and Python, the list can a mixed type of Flask.Request and ServeRequest:
@serve.accept_batch
def batch_func(requests):
assert isinstance(requests, list)