pub struct ArbitrageEngine { /* private fields */ }Expand description
The provider arbitrage engine.
Thread-safe; wrap in Arc to share across pipeline stages.
§Panics
No method panics.
Implementations§
Source§impl ArbitrageEngine
impl ArbitrageEngine
Sourcepub fn register(&self, profile: ProviderProfile)
pub fn register(&self, profile: ProviderProfile)
Register a provider. If a provider with the same name already exists, its profile is updated (existing runtime state is preserved).
§Panics
Does not panic.
Sourcepub fn record_latency(&self, provider: &str, latency: Duration)
pub fn record_latency(&self, provider: &str, latency: Duration)
Record an observed end-to-end latency for a provider.
Call this after every inference call completes (success or failure).
§Panics
Does not panic.
Sourcepub fn record_success(
&self,
provider: &str,
input_tokens: u64,
output_tokens: u64,
latency: Duration,
)
pub fn record_success( &self, provider: &str, input_tokens: u64, output_tokens: u64, latency: Duration, )
Sourcepub fn record_error(&self, provider: &str, latency: Duration)
pub fn record_error(&self, provider: &str, latency: Duration)
Sourcepub fn select_provider(
&self,
sla_budget: Option<Duration>,
) -> Option<ProviderProfile>
pub fn select_provider( &self, sla_budget: Option<Duration>, ) -> Option<ProviderProfile>
Select the cheapest provider whose P95 latency is at or below
sla_budget.
§Selection algorithm
- Filter providers whose P95 latency ≤
sla_budget. - Among those, pick the one with the lowest cost (input + output rate).
Ties are broken by
priority(lower = preferred), then name (alphabetical, for determinism). - If no provider meets the SLA (or
sla_budgetisNone), fall back to the provider with the lowest P95 latency. - If no providers are registered, returns
None.
§Returns
A cloned ProviderProfile for the selected provider, or None if
no providers are registered.
§Panics
Does not panic.
Sourcepub fn snapshot(&self) -> Vec<ProviderSnapshot>
pub fn snapshot(&self) -> Vec<ProviderSnapshot>
Sourcepub fn total_selections(&self) -> u64
pub fn total_selections(&self) -> u64
Total select_provider calls since engine creation.
Sourcepub fn total_sla_misses(&self) -> u64
pub fn total_sla_misses(&self) -> u64
Total selections that fell back to fastest (SLA could not be met).
Trait Implementations§
Source§impl Debug for ArbitrageEngine
impl Debug for ArbitrageEngine
Auto Trait Implementations§
impl !Freeze for ArbitrageEngine
impl RefUnwindSafe for ArbitrageEngine
impl Send for ArbitrageEngine
impl Sync for ArbitrageEngine
impl Unpin for ArbitrageEngine
impl UnsafeUnpin for ArbitrageEngine
impl UnwindSafe for ArbitrageEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request