20888: Applies suggested improvements.
[arvados.git] / lib / dispatchcloud / scheduler / scheduler.go
index 0a5a94c96cb9b4dc59b64a26255c065b5b8a8fc2..ee7ab508839622af6f108cf6b98e6b48f6def603 100644 (file)
@@ -46,10 +46,11 @@ type Scheduler struct {
        stop    chan struct{}
        stopped chan struct{}
 
-       last503time        time.Time // last time API responded 503
-       maxConcurrency     int       // dynamic container limit (0 = unlimited), see runQueue()
-       supervisorFraction float64   // maximum fraction of "supervisor" containers (these are containers who's main job is to launch other containers, e.g. workflow runners)
-       maxInstances       int       // maximum number of instances the pool will bring up (0 = unlimited)
+       last503time          time.Time // last time API responded 503
+       maxConcurrency       int       // dynamic container limit (0 = unlimited), see runQueue()
+       supervisorFraction   float64   // maximum fraction of "supervisor" containers (these are containers who's main job is to launch other containers, e.g. workflow runners)
+       maxInstances         int       // maximum number of instances the pool will bring up (0 = unlimited)
+       instancesWithinQuota int       // max concurrency achieved since last quota error (0 = no quota error yet)
 
        mContainersAllocatedNotStarted   prometheus.Gauge
        mContainersNotAllocatedOverQuota prometheus.Gauge
@@ -62,7 +63,7 @@ type Scheduler struct {
 //
 // Any given queue and pool should not be used by more than one
 // scheduler at a time.
-func New(ctx context.Context, client *arvados.Client, queue ContainerQueue, pool WorkerPool, reg *prometheus.Registry, staleLockTimeout, queueUpdateInterval time.Duration, maxInstances int, supervisorFraction float64) *Scheduler {
+func New(ctx context.Context, client *arvados.Client, queue ContainerQueue, pool WorkerPool, reg *prometheus.Registry, staleLockTimeout, queueUpdateInterval time.Duration, minQuota, maxInstances int, supervisorFraction float64) *Scheduler {
        sch := &Scheduler{
                logger:              ctxlog.FromContext(ctx),
                client:              client,
@@ -75,10 +76,14 @@ func New(ctx context.Context, client *arvados.Client, queue ContainerQueue, pool
                stop:                make(chan struct{}),
                stopped:             make(chan struct{}),
                uuidOp:              map[string]string{},
-               maxConcurrency:      maxInstances, // initial value -- will be dynamically adjusted
                supervisorFraction:  supervisorFraction,
                maxInstances:        maxInstances,
        }
+       if minQuota > 0 {
+               sch.maxConcurrency = minQuota
+       } else {
+               sch.maxConcurrency = maxInstances
+       }
        sch.registerMetrics(reg)
        return sch
 }