MCPcopy Index your code
hub / github.com/InferCore/InferCore / cachedBackendHealth

Method cachedBackendHealth

internal/server/server.go:276–303  ·  view source on GitHub ↗

cachedBackendHealth probes adapter.Health per backend with TTL cache (shared by routing and /status).

(ctx context.Context)

Source from the content-addressed store, hash-verified

274
275// cachedBackendHealth probes adapter.Health per backend with TTL cache (shared by routing and /status).
276func (s *Server) cachedBackendHealth(ctx context.Context) map[string]bool {
277 ttl := time.Duration(s.cfg.Server.HealthCacheTTLMS) * time.Millisecond
278 if ttl <= 0 {
279 ttl = 2 * time.Second
280 }
281 perCheck := time.Duration(s.cfg.Server.HealthCheckPerMS) * time.Millisecond
282 if perCheck <= 0 {
283 perCheck = 1500 * time.Millisecond
284 }
285
286 if snap := s.peekFreshHealthSnapshot(ttl); snap != nil {
287 return snap
288 }
289
290 v, _, _ := s.healthFlight.Do("backend_health", func() (interface{}, error) {
291 if snap := s.peekFreshHealthSnapshot(ttl); snap != nil {
292 return snap, nil
293 }
294 out := s.probeBackendHealth(perCheck)
295 s.healthMu.Lock()
296 s.healthSnapshot = out
297 s.healthAt = time.Now()
298 s.healthMu.Unlock()
299 return out, nil
300 })
301 m, _ := v.(map[string]bool)
302 return cloneBoolMap(m)
303}
304
305func (s *Server) peekFreshHealthSnapshot(ttl time.Duration) map[string]bool {
306 s.healthMu.Lock()

Callers 1

statusMethod · 0.95

Calls 3

probeBackendHealthMethod · 0.95
cloneBoolMapFunction · 0.85

Tested by

no test coverage detected