feat(cag): memory standing-context adapter, warmup semaphore, cache-aware routing
Issue #44: code-register memory adapter with standing-context resource; fix dispatcher method-level Auth.Capability override (was always using verb-derived capability, ignoring per-method Auth field). Issue #45: per-backend bounded in-memory queue (VLLM_MAX_QUEUE_DEPTH=20) + concurrency semaphore (VLLM_MAX_NUM_SEQS=4); warmup requests (X-Poimen-Warmup: true) sleep WARMUP_DELAY_MS before queue entry; /metrics endpoint wired. Issue #46: rendezvous-hash backend selection on X-Poimen-Cache-Key; round-robin fallback; MarkFailed excludes unhealthy backends 30s; ModifyResponse captures vllm-num-cached-tokens + emits structured log + increments counter. Closes #44 Closes #45 Closes #46
This commit is contained in:
@@ -36,6 +36,10 @@ type Metrics struct {
|
||||
itlMs map[string][]int64 // samples for histogram
|
||||
// Token counts
|
||||
tokenCount map[string]int64
|
||||
|
||||
// CAG metrics
|
||||
warmupRequestsDelayed int64
|
||||
prefixCacheHitTokens int64
|
||||
}
|
||||
|
||||
// NewMetrics creates a new Metrics instance.
|
||||
@@ -280,4 +284,46 @@ func (m *Metrics) Reset() {
|
||||
m.ttftMs = make(map[string][]int64)
|
||||
m.itlMs = make(map[string][]int64)
|
||||
m.tokenCount = make(map[string]int64)
|
||||
m.warmupRequestsDelayed = 0
|
||||
m.prefixCacheHitTokens = 0
|
||||
}
|
||||
|
||||
// IncrWarmupDelayed increments warmup_requests_delayed_total.
|
||||
func (m *Metrics) IncrWarmupDelayed() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.warmupRequestsDelayed++
|
||||
}
|
||||
|
||||
// GetWarmupDelayed returns warmup_requests_delayed_total.
|
||||
func (m *Metrics) GetWarmupDelayed() int64 {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.warmupRequestsDelayed
|
||||
}
|
||||
|
||||
// IncrPrefixCacheHitTokens increments vllm_prefix_cache_hit_tokens_total by n.
|
||||
func (m *Metrics) IncrPrefixCacheHitTokens(n int64) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.prefixCacheHitTokens += n
|
||||
}
|
||||
|
||||
// GetPrefixCacheHitTokens returns vllm_prefix_cache_hit_tokens_total.
|
||||
func (m *Metrics) GetPrefixCacheHitTokens() int64 {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.prefixCacheHitTokens
|
||||
}
|
||||
|
||||
// globalMetrics is the singleton Metrics instance for gateway-wide telemetry.
|
||||
var (
|
||||
globalMetrics *Metrics
|
||||
globalMetricsOnce sync.Once
|
||||
)
|
||||
|
||||
// Global returns the singleton Metrics instance, initialising on first call.
|
||||
func Global() *Metrics {
|
||||
globalMetricsOnce.Do(func() { globalMetrics = NewMetrics() })
|
||||
return globalMetrics
|
||||
}
|
||||
|
||||
@@ -36,6 +36,14 @@ func (p *PrometheusExporter) Export() string {
|
||||
lines = append(lines, "# TYPE request_duration_seconds histogram")
|
||||
p.exportRequestDuration(&lines)
|
||||
|
||||
lines = append(lines, "# HELP warmup_requests_delayed_total LLM warmup requests delayed for vLLM slot management")
|
||||
lines = append(lines, "# TYPE warmup_requests_delayed_total counter")
|
||||
lines = append(lines, fmt.Sprintf("warmup_requests_delayed_total %d", p.metrics.GetWarmupDelayed()))
|
||||
|
||||
lines = append(lines, "# HELP vllm_prefix_cache_hit_tokens_total vLLM KV prefix cache hit tokens")
|
||||
lines = append(lines, "# TYPE vllm_prefix_cache_hit_tokens_total counter")
|
||||
lines = append(lines, fmt.Sprintf("vllm_prefix_cache_hit_tokens_total %d", p.metrics.GetPrefixCacheHitTokens()))
|
||||
|
||||
return strings.Join(lines, "\n") + "\n"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user