From b8a9be0378a421309acaad54b4a6f01443ccda59 Mon Sep 17 00:00:00 2001 From: Edward Oakes Date: Tue, 2 Jun 2020 16:03:18 -0500 Subject: [PATCH] [serve] Specify how to pass init args to actors (#8738) --- doc/source/serve/key-concepts.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/source/serve/key-concepts.rst b/doc/source/serve/key-concepts.rst index e8a858238..c1f5c1d86 100644 --- a/doc/source/serve/key-concepts.rst +++ b/doc/source/serve/key-concepts.rst @@ -25,7 +25,7 @@ model that you'll be serving. To create one, we'll simply specify the name, rout serve.create_endpoint("simple_endpoint", "/simple") -You can also delete an endpoint using `serve.delete_endpoint`. +You can also delete an endpoint using ``serve.delete_endpoint``. Note that this will not delete any associated backends, which can be reused for other endpoints. .. code-block:: python @@ -45,6 +45,7 @@ Use a function when your response is stateless and a class when you might need to maintain some state (like a model). For both functions and classes (that take as input Flask Requests), you'll need to define them as backends to Ray Serve. +You can specify arguments to be passed to class constructors in ``serve.create_backend``, shown below. It's important to note that Ray Serve places these backends in individual worker processes, which are replicas of the model. @@ -54,14 +55,17 @@ It's important to note that Ray Serve places these backends in individual worker return "hello world" class RequestHandler: - def __init__(self): - self.msg = "hello, world!" + # Take the message to return as an argument to the constructor. + def __init__(self, msg): + self.msg = msg def __call__(self, flask_request): return self.msg serve.create_backend("simple_backend", handle_request) - serve.create_backend("simple_backend_class", RequestHandler) + # Pass in the message that the backend will return as an argument. + # If we call this backend, it will respond with "hello, world!". + serve.create_backend("simple_backend_class", RequestHandler, "hello, world!") Setting Traffic ===============