feat(scheduler): replace clone concurrency limit with cost-based admission#242
Draft
feat(scheduler): replace clone concurrency limit with cost-based admission#242
Conversation
…ssion Replace the binary isCloneJob/MaxCloneConcurrency mechanism with a generic cost model. Strategies now declare the cost of each job at submit time, and the scheduler tracks total active cost against a configurable budget (max-cost). Cost constants defined in the git strategy: clone=4, snapshot=3, repack=2, fetch=1 Default max-cost is Concurrency * 4. A job is always admitted when nothing else is running, even if its cost exceeds max-cost, to prevent permanent starvation from misconfiguration. This removes isCloneJob and the scheduler's knowledge of git-specific job types. The scheduler now sees only costs and the strategy decides what each job is worth. Amp-Thread-ID: https://ampcode.com/threads/T-019d404e-21ec-723a-b211-c619925dd12e Co-authored-by: Amp <amp@ampcode.com>
alecthomas
reviewed
Mar 31, 2026
| MaxCloneConcurrency int `hcl:"max-clone-concurrency" help:"Maximum number of concurrent clone jobs. Remaining worker slots are reserved for fetch/repack/snapshot jobs. 0 means no limit." default:"0"` | ||
| SchedulerDB string `hcl:"scheduler-db" help:"Path to the scheduler state database." default:"${CACHEW_STATE}/scheduler.db"` | ||
| Concurrency int `hcl:"concurrency" help:"The maximum number of concurrent jobs to run (0 means number of cores)." default:"4"` | ||
| MaxCost int `hcl:"max-cost" help:"Maximum total cost of concurrently running jobs. Each job declares its own cost at submission. 0 means Concurrency * 4." default:"0"` |
Collaborator
There was a problem hiding this comment.
I like this as a general scheduling improvement, but is this going to work as a replacement for the existing MaxCloneConcurrency? I feel like they're solving slightly different problems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the binary
isCloneJob/MaxCloneConcurrencymechanism with a generic cost model. Strategies declare the cost of each job at submit time, and the scheduler tracks total active cost against a configurable budget (max-cost).Design
The
SubmitandSubmitPeriodicJobinterface methods now accept acost intparameter. The scheduler admits a job only whenactiveCost + job.cost <= maxCost(with a safety valve: any job is admitted when nothing else is running, preventing permanent starvation from misconfiguration).This removes
isCloneJob— the scheduler no longer has knowledge of git-specific job types.Cost constants (git strategy)
Configuration
With the defaults (concurrency=4, max-cost=16), you can run up to 4 clones, or 1 clone + 3 snapshots + 1 fetch, etc. The worker count remains the hard parallelism cap.
Breaking changes
max-clone-concurrencyconfig replaced bymax-costScheduler.SubmitandSubmitPeriodicJobsignatures changed (addedcost int)