feat(models): add max concurrency setting for background tasks

Introduce a new `max_concurrency` parameter to the model configuration, allowing control over the maximum number of concurrent background tasks (ingestion/enrichment) per model. This feature is applicable to chat, embedding, and VLM models, with a value of 0 or undefined falling back to the global default. Update UI components and localization files to support this new setting, ensuring a seamless user experience.
This commit is contained in:
wizardchen
2026-07-09 19:56:43 +08:00
committed by lyingbug
parent 200c344065
commit 20256287ec
17 changed files with 173 additions and 55 deletions
+18 -6
View File
@@ -28,16 +28,28 @@ func SetGovernor(l ModelConcurrencyLimiter, limit int) {
governorN = limit
}
// Gate acquires a per-model concurrency slot when the call is a background task
// (see types.IsBackgroundTask) and a governor is installed. It returns a
// release func that is ALWAYS safe to call: on the passthrough / fail-open
// paths it is a cheap no-op. The gate never blocks a call permanently — a
// limiter/Redis outage or a cancelled context fails open.
// Gate acquires a per-model concurrency slot using the process-wide default
// limit. Equivalent to GateN(ctx, modelID, 0).
func Gate(ctx context.Context, modelID string) func() {
return GateN(ctx, modelID, 0)
}
// GateN acquires a per-model concurrency slot when the call is a background task
// (see types.IsBackgroundTask) and a governor is installed. modelLimit is the
// model's own configured cap; a value <= 0 means "fall back to the process-wide
// default" (governorN). It returns a release func that is ALWAYS safe to call:
// on the passthrough / fail-open paths it is a cheap no-op. The gate never
// blocks a call permanently — a limiter/Redis outage or a cancelled context
// fails open.
func GateN(ctx context.Context, modelID string, modelLimit int) func() {
governorMu.RLock()
l, limit := governor, governorN
l, defaultLimit := governor, governorN
governorMu.RUnlock()
limit := modelLimit
if limit <= 0 {
limit = defaultLimit
}
if l == nil || limit <= 0 || !types.IsBackgroundTask(ctx) {
return noop
}