RequestRouter#
- class ray.serve.request_router.RequestRouter(deployment_id: DeploymentID, handle_source: DeploymentHandleSource, self_actor_id: str | None = None, self_actor_handle: ActorHandle | None = None, use_replica_queue_len_cache: bool = False, get_curr_time_s: Callable[[], float] | None = None, create_replica_wrapper_func: Callable[[RunningReplicaInfo], RunningReplica] | None = None, initial_backoff_s: float = 0.025, backoff_multiplier: float = 2, max_backoff_s: float = 0.5, *args, **kwargs)[source]#
Bases:
ABCAbstract interface for a request router (how the router calls it).
Serve constructs the router, then calls
initialize_statewith the config’srequest_router_kwargs.- Parameters:
deployment_id (DeploymentID) – ID of the deployment that the router routes to.
handle_source (DeploymentHandleSource) – Where the handle that owns the router runs, such as a proxy or a replica.
self_actor_id (str | None) – ID of the actor that the router runs in, if any. Used as a metric tag.
self_actor_handle (ActorHandle | None) – Handle to the actor that the router runs in. A router on a proxy pushes this handle to each new replica.
use_replica_queue_len_cache (bool) – Whether to track replica queue lengths in a local cache.
get_curr_time_s (Callable[[], float] | None) – Function that returns the current time in seconds. Defaults to
time.time.create_replica_wrapper_func (Callable[[RunningReplicaInfo], RunningReplica] | None) – Function that wraps a
RunningReplicaInfoin aRunningReplica.initial_backoff_s (float) – Initial backoff, in seconds, before retrying to route a request.
backoff_multiplier (float) – Multiplier applied to the backoff after each retry.
max_backoff_s (float) – Maximum backoff, in seconds, between retries.
*args – Positional arguments passed to mixins.
**kwargs – Keyword arguments passed to mixins.
PublicAPI (alpha): This API is in alpha and may change before becoming stable.
Methods
Chooses a subset of candidate replicas from available replicas.
Wrap replica information in a
RunningReplica.Decrement the queue length cache for a replica.
Initialize the state of the request router.
Update queue length cache with new info received from replica.
Drop replica from replica set so it's not considered for future requests.
Invalidate cache entry so active probing is required for the next request.
Called when a request to a replica has completed.
Called when a request is routed to a replica.
Increment queue length cache when a request is sent to a replica.
Select available replicas from the list of candidates.
Update the backoff parameters at runtime.
Update the set of available replicas to be considered for routing.
Attributes
Name of the app this router is serving.
Current number of routing tasks running.
Current replicas available to be routed.
Max number of routing tasks to run at any time.
Hard limit on the maximum number of routing tasks to run.
Maximum deadline for receiving queue length info from replicas.
Current number of requests pending assignment.
Deadline for receiving queue length info from replicas.
Get the replica queue length cache.
Whether this router supports the rejection protocol.
Target number of routing tasks to be running based on pending requests.