mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-27 10:16:34 +00:00
perf(shared-state): batch calibrator counters with the usage write
Each served request spawned a second async write for the calibrator counters. They now ride the batch accountWith already sends, and only when shared state is on and a store is configured.
This commit is contained in:
+5
-1
@@ -801,6 +801,10 @@ func (g *Gateway) runMeteredCall(sw *statusTrackingWriter, r *http.Request, scop
|
||||
extras.provenance = provenance
|
||||
extras.provenanceTokens = result.total()
|
||||
}
|
||||
calibrate := plan != nil && callErr == nil && !plan.hasImage && !result.estimated
|
||||
if calibrate {
|
||||
extras.calibration = g.tokenCalib.fleetEntries(providerName, cand.upstreamModel, plan.promptBytes, result.prompt)
|
||||
}
|
||||
extras.promptCacheSaved = unifiedPromptCacheSaved(cand.canonical, cand.upstreamModel, result, g.cfg.Pricing, g.cfg.ModelMeta)
|
||||
g.recordPromptCache(providerName, cand.upstreamModel, result)
|
||||
g.limiter.accountWith(acctScopes, result, unifiedCostMicros(cand.canonical, cand.upstreamModel, result, g.cfg.Pricing, g.cfg.ModelMeta, g.pricingWarn), extras)
|
||||
@@ -808,7 +812,7 @@ func (g *Gateway) runMeteredCall(sw *statusTrackingWriter, r *http.Request, scop
|
||||
g.logf("%s: usage for model %q logged as estimated (%d prompt tokens derived from request body size, not the provider's reported usage)", logPrefix, cand.canonical, result.prompt)
|
||||
}
|
||||
|
||||
if plan != nil && callErr == nil && !plan.hasImage && !result.estimated {
|
||||
if calibrate {
|
||||
g.tokenCalib.observe(providerName, cand.upstreamModel, plan.promptBytes, result.prompt)
|
||||
}
|
||||
if plan != nil && plan.bandit != nil {
|
||||
|
||||
Reference in New Issue
Block a user