Skip to main content

Module balance

Module balance 

Source
Expand description

Calls spread over several endpoints of one agent, with failing ones ejected and idempotent calls optionally hedged (ADR 0050, audit H12).

A client built with ClientBuilder::new(url) sends every call to url, and over https:// all of them share one HTTP/2 connection. Behind a layer-4 balancer, which picks a replica per connection, they all reach one replica. With ClientBuilder::with_balancing a client sends each call to the endpoint of a set with the fewest calls in flight, keeps an endpoint that keeps failing out of rotation for a while, and can send a slow idempotent call to a second endpoint.

use std::time::Duration;
use a2a_protocol_client::ClientBuilder;
use a2a_protocol_client::balance::{BalancePolicy, DnsEndpoints, Hedge};

// A Kubernetes headless Service: one name, one address per pod.
let url = "https://agent.ns.svc.cluster.local:8443";
let client = ClientBuilder::new(url)
    .with_balancing(
        DnsEndpoints::new(url)?,
        BalancePolicy::new().with_hedge(Hedge::after(Duration::from_millis(200))),
    )
    .build()?;

Structs§

BalancePolicy
How a balanced client chooses and ejects endpoints.
DnsEndpoints
Every address a URL’s host resolves to, one pinned endpoint each, resolved again every 30 s: a Kubernetes headless Service, or any name with one address per replica.
Ejection
When an endpoint is taken out of rotation (ADR 0050 decision 3), and, on an HttpPool, when its circuit opens.
Endpoint
One endpoint of an agent: a URL, optionally pinned to a socket address.
Hedge
Opt-in hedging: a second copy of a slow idempotent call (ADR 0050 decision 5).
StaticEndpoints
A fixed set of endpoints.

Constants§

DEFAULT_DNS_REFRESH
How often DnsEndpoints resolves its name again, by default.

Traits§

EndpointSource
Where a balanced client’s endpoints come from.

Type Aliases§

EndpointsFuture
The boxed future an EndpointSource returns.