def _start_proxies_if_needed(self) -> None: """Start a proxy on every node if it doesn't already exist.""" for node_id, node_resource in self._get_target_nodes(): if node_id in self._proxy_actors: continue name = format_actor_name(SERVE_PROXY_NAME, self._controller_name, node_id) try: proxy = ray.get_actor( name, namespace=self._controller_namespace) except ValueError: logger.info("Starting HTTP proxy with name '{}' on node '{}' " "listening on '{}:{}'".format( name, node_id, self._config.host, self._config.port)) proxy = HTTPProxyActor.options( num_cpus=self._config.num_cpus, name=name, lifetime="detached" if self._detached else None, max_concurrency=ASYNC_CONCURRENCY, max_restarts=-1, max_task_retries=-1, resources={ node_resource: 0.01 }, ).remote( self._config.host, self._config.port, controller_name=self._controller_name, controller_namespace=self._controller_namespace, http_middlewares=self._config.middlewares) self._proxy_actors[node_id] = proxy
def _start_routers_if_needed(self): """Start a router on every node if it doesn't already exist.""" for node_id, node_resource in get_all_node_ids(): if node_id in self.routers: continue router_name = format_actor_name(SERVE_PROXY_NAME, self.instance_name, node_id) try: router = ray.get_actor(router_name) except ValueError: logger.info("Starting router with name '{}' on node '{}' " "listening on '{}:{}'".format( router_name, node_id, self.http_host, self.http_port)) router = HTTPProxyActor.options( name=router_name, max_concurrency=ASYNC_CONCURRENCY, max_restarts=-1, max_task_retries=-1, resources={ node_resource: 0.01 }, ).remote( node_id, self.http_host, self.http_port, instance_name=self.instance_name, _http_middlewares=self._http_middlewares) self.routers[node_id] = router
def _start_routers_if_needed(self, http_host: str, http_port: str, http_middlewares: List[Any]) -> None: """Start a router on every node if it doesn't already exist.""" for node_id, node_resource in get_all_node_ids(): if node_id in self.routers_cache: continue router_name = format_actor_name(SERVE_PROXY_NAME, self.controller_name, node_id) try: router = ray.get_actor(router_name) except ValueError: logger.info("Starting router with name '{}' on node '{}' " "listening on '{}:{}'".format( router_name, node_id, http_host, http_port)) router = HTTPProxyActor.options( name=router_name, lifetime="detached" if self.detached else None, max_concurrency=ASYNC_CONCURRENCY, max_restarts=-1, max_task_retries=-1, resources={ node_resource: 0.01 }, ).remote(http_host, http_port, controller_name=self.controller_name, http_middlewares=http_middlewares) self.routers_cache[node_id] = router
def _get_or_start_http_proxy(self, node_id, host, port): """Get the HTTP proxy belonging to this serve instance. If the HTTP proxy does not already exist, it will be started. """ proxy_name = format_actor_name(SERVE_PROXY_NAME, self.instance_name) try: self.http_proxy = ray.get_actor(proxy_name) except ValueError: logger.info( "Starting HTTP proxy with name '{}' on node '{}'".format( proxy_name, node_id)) self.http_proxy = HTTPProxyActor.options( name=proxy_name, max_concurrency=ASYNC_CONCURRENCY, max_restarts=-1, max_task_retries=-1, resources={ node_id: 0.01 }, ).remote(host, port, instance_name=self.instance_name) # Since router is a merged with HTTP proxy actor, the router will be # proxied via the HTTP actor. Even though the two variable names are # pointing to the same object, their semantic differences make the code # more readable. (e.g. http_proxy.set_route_table, router.add_worker) self.router = self.http_proxy
def _get_or_start_routers(self, host, port): """Get the HTTP proxy belonging to this serve instance. If the HTTP proxy does not already exist, it will be started. """ # TODO(simon): We don't handle nodes being added/removed. To do that, # we should implement some sort of control loop in master actor. for _, node_id_group in groupby(sorted(ray.state.node_ids())): for index, node_id in enumerate(node_id_group): proxy_name = format_actor_name(SERVE_PROXY_NAME, self.instance_name) proxy_name += "-{}-{}".format(node_id, index) try: router = ray.get_actor(proxy_name) except ValueError: logger.info( "Starting HTTP proxy with name '{}' on node '{}' " "listening on port {}".format(proxy_name, node_id, port)) router = HTTPProxyActor.options( name=proxy_name, max_concurrency=ASYNC_CONCURRENCY, max_restarts=-1, max_task_retries=-1, resources={ node_id: 0.01 }, ).remote(host, port, instance_name=self.instance_name) self.routers.append(router)
def start_http_proxy(self, host, port): assert self.http_proxy is None, "HTTP proxy already started." assert self.router is not None, ( "Router must be started before HTTP proxy.") self.http_proxy = HTTPProxyActor.options( max_concurrency=ASYNC_CONCURRENCY).remote() self.http_proxy.run.remote(host, port) ray.get(self.http_proxy.set_router_handle.remote(self.router))
def start_http_proxy(self, host, port): """Start the HTTP proxy on the given host:port. On startup (or restart), the HTTP proxy will fetch its config via get_http_proxy_config. """ assert self.http_proxy is None, "HTTP proxy already started." assert self.router is not None, ( "Router must be started before HTTP proxy.") self.http_proxy = HTTPProxyActor.options( max_concurrency=ASYNC_CONCURRENCY, max_reconstructions=ray.ray_constants.INFINITE_RECONSTRUCTION, ).remote(host, port)
def _get_or_start_http_proxy(self, node_id, host, port): """Get the HTTP proxy belonging to this serve instance. If the HTTP proxy does not already exist, it will be started. """ proxy_name = format_actor_name(SERVE_PROXY_NAME, self.instance_name) try: self.http_proxy = ray.get_actor(proxy_name) except ValueError: logger.info( "Starting HTTP proxy with name '{}' on node '{}'".format( proxy_name, node_id)) self.http_proxy = HTTPProxyActor.options( name=proxy_name, max_concurrency=ASYNC_CONCURRENCY, max_restarts=-1, max_task_retries=-1, resources={ node_id: 0.01 }, ).remote(host, port, instance_name=self.instance_name)
def _start_proxies_if_needed(self) -> None: """Start a proxy on every node if it doesn't already exist.""" for node_id, node_ip_address in self._get_target_nodes(): if node_id in self._proxy_actors: continue name = format_actor_name(SERVE_PROXY_NAME, self._controller_name, node_id) try: proxy = ray.get_actor(name, namespace=SERVE_NAMESPACE) except ValueError: logger.info( "Starting HTTP proxy with name '{}' on node '{}' " "listening on '{}:{}'".format( name, node_id, self._config.host, self._config.port ) ) proxy = HTTPProxyActor.options( num_cpus=self._config.num_cpus, name=name, namespace=SERVE_NAMESPACE, lifetime="detached" if self._detached else None, max_concurrency=ASYNC_CONCURRENCY, max_restarts=-1, max_task_retries=-1, scheduling_strategy=NodeAffinitySchedulingStrategy( node_id, soft=False ), ).remote( self._config.host, self._config.port, self._config.root_path, controller_name=self._controller_name, node_ip_address=node_ip_address, http_middlewares=self._config.middlewares, ) self._proxy_actors[node_id] = proxy self._proxy_actor_names[node_id] = name