LocalAI icon indicating copy to clipboard operation
LocalAI copied to clipboard

Backend operations run one at a time; one slow node blocks the whole queue

Open mudler-agent opened this issue 1 month ago • 0 comments

Problem

Backend operations (install, upgrade, delete) run one at a time. One slow operation blocks every operation behind it, and also blocks model operations.

In core/services/galleryop/service.go, one goroutine reads both BackendGalleryChannel and ModelGalleryChannel and runs each operation inline. In distributed mode, enqueueAndDrainBackendOp (core/services/nodes/managers_distributed.go) visits the nodes one after the other, and waits for each node up to the backend install or upgrade timeout (15 minutes by default).

In a cluster with mixed nodes this has a bad effect. A large backend image on one slow node holds the queue for up to 15 minutes. "Upgrade all" then shows many operations as queued with no sign of progress, even though most of them touch other nodes.

There is a setting for concurrent downloads (--artifact-download-concurrency), but it only limits the files of one model download. Nothing limits how many operations run at the same time.

Proposal

Add a setting for the number of backend operations that run at the same time:

  • Flag --max-concurrent-backend-operations, environment variable LOCALAI_MAX_CONCURRENT_BACKEND_OPERATIONS, runtime setting max_concurrent_backend_operations. Default 1, so current behaviour does not change.
  • Replace the inline call in the queue loop with a bounded worker pool.
  • Keep operations on the same backend name serialized, and operations on the same node serialized, so install, upgrade and delete of one backend never overlap on one node.
  • Give model operations their own loop, so a slow backend upgrade does not block model installs.
  • In distributed mode, send an operation to its target nodes in parallel, so one slow node does not hold the others.

Things to check

  • Races on the status and cancellation maps, the persisted gallery_operations rows and the reconciler drain.
  • Cancel and pause of queued and running operations.
  • Whether worker-side backend.install is safe to run concurrently with other operations on the same node.
  • Docs: docs/content/features/runtime-settings.md.

mudler-agent avatar Oct 24 '26 21:10 mudler-agent