MCPcopy Create free account
hub / github.com/InferCore/InferCore / beginInferLoad

Method beginInferLoad

internal/server/server.go:243–273  ·  view source on GitHub ↗

beginInferLoad enforces reliability.overload: "reject" returns reject=true without consuming a slot; "degrade" allows the request and sets overloadDegrade when at/above the limit. QueueLimit <= 0 disables checks. Concurrency slots are acquired with CAS so active /infer calls cannot exceed the limit

()

Source from the content-addressed store, hash-verified

241// "degrade" allows the request and sets overloadDegrade when at/above the limit. QueueLimit <= 0 disables checks.
242// Concurrency slots are acquired with CAS so active /infer calls cannot exceed the limit (reject mode).
243func (s *Server) beginInferLoad() (done func(), overloadDegrade bool, reject bool) {
244 nop := func() {}
245 limit := s.cfg.Reliability.Overload.QueueLimit
246 if limit <= 0 {
247 s.inferInflight.Add(1)
248 return func() { s.inferInflight.Add(-1) }, false, false
249 }
250 action := strings.ToLower(strings.TrimSpace(s.cfg.Reliability.Overload.Action))
251 if action == "" {
252 action = "degrade"
253 }
254 lim := int32(limit)
255 if action == "reject" {
256 for {
257 cur := s.inferInflight.Load()
258 if cur >= lim {
259 return nop, false, true
260 }
261 if s.inferInflight.CompareAndSwap(cur, cur+1) {
262 return func() { s.inferInflight.Add(-1) }, false, false
263 }
264 }
265 }
266 for {
267 cur := s.inferInflight.Load()
268 degraded := cur >= lim
269 if s.inferInflight.CompareAndSwap(cur, cur+1) {
270 return func() { s.inferInflight.Add(-1) }, degraded, false
271 }
272 }
273}
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 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected