Global Backend Admission Controller (backend/global_admission.go)

LocalAI · core/backend/global_admission.go · go · MIT
infra, security, tag:concurrency, tag:resource-management

Manages concurrent backend execution to prevent overload and ensure fair resource distribution.

// Source: https://github.com/mudler/LocalAI | License: MIT | Copyright 2023-2025 Ettore Di Giacinto (mudler@localai.io)
// Provided via justclaw.it.com; keep this notice with the code.
// SPDX-License-Identifier: MIT

package backend

import (
	"fmt"
	"sync"
	"time"

	"github.com/mudler/LocalAI/core/config"
)

// BackendAdmissionError reports that the process-wide backend execution
// ceiling is full. HTTP callers map it to 429 (Too Many Requests) with a
// Retry-After header; internal callers receive the same typed error instead
// of silently queueing and growing in-flight state.
type BackendAdmissionError struct {
	Limit      int
	RetryAfter time.Duration
}

func (e *BackendAdmissionError) Error() string {
	return fmt.Sprintf("backend inference capacity reached (max_concurrent=%d); ret

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key