You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(scheduler): replace clone concurrency limit with cost-based admission
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>
Copy file name to clipboardExpand all lines: internal/jobscheduler/jobs.go
+45-47Lines changed: 45 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -16,14 +16,15 @@ import (
16
16
)
17
17
18
18
typeConfigstruct {
19
-
Concurrencyint`hcl:"concurrency" help:"The maximum number of concurrent jobs to run (0 means number of cores)." default:"4"`
20
-
MaxCloneConcurrencyint`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"`
21
-
SchedulerDBstring`hcl:"scheduler-db" help:"Path to the scheduler state database." default:"${CACHEW_STATE}/scheduler.db"`
19
+
Concurrencyint`hcl:"concurrency" help:"The maximum number of concurrent jobs to run (0 means number of cores)." default:"4"`
20
+
MaxCostint`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"`
21
+
SchedulerDBstring`hcl:"scheduler-db" help:"Path to the scheduler state database." default:"${CACHEW_STATE}/scheduler.db"`
22
22
}
23
23
24
24
typequeueJobstruct {
25
25
idstring
26
26
queuestring
27
+
costint
27
28
runfunc(ctx context.Context) error
28
29
}
29
30
@@ -43,27 +44,31 @@ type Scheduler interface {
43
44
//
44
45
// This is useful to avoid collisions across strategies.
45
46
WithQueuePrefix(prefixstring) Scheduler
46
-
// Submit a job to the queue.
47
+
// Submit a job to the queue with a given cost.
47
48
//
48
49
// Jobs run concurrently across queues, but never within a queue.
0 commit comments