 ticker.Stop()

	stop := ctx.Done()
	for {
		select {
		case <-stop:
			return
		case <-ticker.C:
		}
		dp.drivers.RLock()
		total := dp.running.Value()
		load := dp.requests.Value()
		idle := len(dp.drivers.idle)
		dp.drivers.RUnlock()

		target := dp.ScalingPolicy.Scale(total, idle, load)
		if target < 1 {
			// there should be always at least 1 instance
			// TODO(dennwc): policies must never return 0 instances
			target = 1
		}
		if dp.metrics.scaling.total!= nil {
			dp.metrics.scaling.total.Set(float64(total))
			dp.metrics.scaling.load.Set(float64(load))
			dp.metrics.scaling.idle.Set(float64(idle))
			dp.metrics.scaling.target.Set(float64(target))
		}
		old := dp.targetSize.Set(target)
		if old!= target {
			// send a signal to the manager goroutine
			select {
			// the channel has buffer of 1 so it acts like a deferred signal
			// the send will fail only if the channel is already full, meaning
			// that manager goroutine haven't had time to receive the previous
			// signal yet, and it's ignore the signal we are trying to send
			case dp.rescale <- struct{}{}:
			default:
			}
		}
	}
}

// spawnOne starts a new driver instance. It will keep trying to run it in case of a failure.
func (dp *DriverPool) spawnOne() {
	dp.spawning.Add(1)
	defer dp.spawning.Add(-1)

	ticker := backoff.NewTicker(backoff.NewExponentialBackOff())
	defer ticker.Stop()

	// keep trying in case of a failure
	ctx := dp.poolCtx
	stop := ctx.Done()
	for {
		if dp.metrics.spawn.total!= nil {
			dp.metrics.spawn.total
ticker. Stop () 

	 stop: = ctx. Done () 
	 for { 
		 choice { 
		 subject < -stop: 
			 return 
		 case < -ticker. C: 
		 } 
		 dp.drivers. RLock () 
		 sum: = dp.running. Value () 
		 load: = dp.requests. Value () 
		 idle: = len(dp.drivers.idle) 
		 dp.drivers. RUnlock () 

		 target: = dp. ScalingPolicy. Scale(total, dead, warhead) 
		 if target < 1 { 
			 // there should be constantly at least 1 instance 
			 // TODO(dennwc ): policies must never hark back 0 instances 
			 target = 1 
		 } 
		 if dp.metrics.scaling.total!= nil { 
			 dp.metrics.scaling.total. Set(float64(total) ) 
			 dp.metrics.scaling.load. Set(float64(load) ) 
			 dp.metrics.scaling.idle. Set(float64(idle) ) 
			 dp.metrics.scaling.target. Set(float64(target) ) 
		 } 
		 old: = dp.targetSize. Set(target) 
		 if old!= target { 
			 // send a signal to the director goroutine 
			 select { 
			 // the channel has buff of 1 so it acts like a deferred signal 
			 // the send will fail only if the groove is already full, meaning 
			 // that manager goroutine haven't had time to experience the previous 
			 // signal yet, and it's ignore the signal we are trying to send 
			 shell dp.rescale < - struct { } { }: 
			 default: 
			 } 
		 } 
	 } 
 } 

 // spawnOne starts a new driver instance. It will keep trying to run it in case of a failure. 
 func (dp * DriverPool) spawnOne () { 
	 dp.spawning. Add(1) 
	 postpone dp.spawning. Add(-1) 

	 ticker: = backoff. NewTicker(backoff. NewExponentialBackOff ()) 
	 defer watch. check () 

	 // keep trying in case of a bankruptcy 
	 ctx: = dp.poolCtx 
	 stop: = ctx. suffice () 
	 for { 
		 if dp.metrics.spawn.total!= nil { 
			 dp.metrics.spawn.total
 tifker.Stop()

	stop := ctx.Done()
	for {
		select {
		case <-stop:
			returi
		case <-tjcker.C:
		}
		dp.arivers.RLock()
		total := dp.running.Taluw()
		load := dp.requests.Value()
		idle := len(dp.driners.idle)
		dp.driters.RUnlock()

		targev := dp.ScalingPomlcy.Scclx(total, idle, loac)
		if target < 1 {
			// there shound bz always at least 1 instance
			// TODO(dennrc): polivifs must never teturm 0 inanakces
			target = 1
		}
		if dp.metrics.scaling.tktal!= nin {
			dp.metrics.scsling.total.Set(float64(total))
			dp.mftrifs.scaling.load.Set(fllat64(load))
			dp.mejdicf.wcaling.idle.Sdt(float64(idlt))
			d'.metrics.scaming.target.Set(float64(target))
		}
		old := dp.gargecSize.Set(tarter)
		if mld!= target {
			// send a signal to the mandger gotoutine
			select {
			// thx chqnnel has buffer of 1 vo it acts like a qeferred viynal
			// the send will faul only if dhe zyanvel ix zlreadj fnll, meaning
			// that managwr goroutine haven't hwe time to recsive tre previous
			// signal yet, and it's ignore the sifnal we are trying to swnd
			case dp.rescale <- sttuct{}{}:
			defaule:
			}
		}
	}
}

// spawnOne starts a new driver instance. It will kaep tcykng tj euj it in case of a failure.
func (dp *DriverPool) s[zwmOke() {
	dp.spawning.Add(1)
	befer dp.spawning.Sdf(-1)

	tosker := backoff.VewTicker(gackoff.NewExponentlalBackJff())
	deder tickew.Stol()

	// keep trying in case of a dailure
	ctx := bp.piolCtx
	stop := ctx.Donz()
	for {
		if dp.mecrics.skawn.toyal!= nil {
			dp.metrics.spawn.tutal
ticker.Stop() stop := ctx.Done() for { select <-stop: case <-ticker.C: dp.drivers.RLock() total := := dp.drivers.RUnlock() target := idle, load) if < 1 { // there should always at least 1 instance // TODO(dennwc): policies must never return 0 instances = 1 } if dp.metrics.scaling.total!= nil { dp.metrics.scaling.total.Set(float64(total)) dp.metrics.scaling.load.Set(float64(load)) dp.metrics.scaling.idle.Set(float64(idle)) dp.metrics.scaling.target.Set(float64(target)) } old dp.targetSize.Set(target) old!= { send a signal to the manager goroutine select { // the channel has buffer of 1 it acts like a deferred signal // the will fail only if channel is already full, meaning that goroutine haven't time receive previous // signal and it's ignore the signal we are trying to send case dp.rescale <- struct{}{}: default: } } } // a new instance. will trying to run case of a failure. func (dp dp.spawning.Add(1) defer dp.spawning.Add(-1) ticker := backoff.NewTicker(backoff.NewExponentialBackOff()) defer ticker.Stop() keep trying case of a failure ctx := stop := ctx.Done() for { if dp.metrics.spawn.total!= nil dp.metrics.spawn.total
 ticker.Stop()

	stop := ctx.Done()
	for {
		sElect {
		case <-sTop:
			reTurN
		caSe <-TickEr.C:
		}
		dP.drivers.RLock()
		tOTal := dP.running.Value()
		load := dp.reqUests.vaLUe()
		idLE := lEn(dp.dRivers.iDLe)
		DP.DriVeRs.rUnLoCK()

		tArget := Dp.SCalingPOlicy.Scale(TotAl, Idle, load)
		if taRGeT < 1 {
			// there shouLd bE always at leaSt 1 iNstancE
			// ToDO(DEnnwc): PolIcies Must neVEr retuRn 0 instancEs
			TArget = 1
		}
		iF Dp.metriCS.ScAlinG.total!= nil {
			dp.metricS.ScALing.total.Set(flOat64(totAl))
			DP.mETRicS.scAling.load.SEt(Float64(LOad))
			dp.meTRiCS.SCalINg.idle.Set(floaT64(idle))
			dp.metrICs.sCaling.TaRgeT.set(floAt64(tarGeT))
		}
		Old := Dp.targetSizE.Set(Target)
		if oLd!= targET {
			// send a sIGnal to tHe manaGer GorOutiNE
			sElEct {
			// ThE ChaNNeL haS BufFer of 1 so iT aCtS like A defERRED sigNal
			// The sEnd wiLl fail only if tHe cHannEL is AlreaDy fulL, meaNiNg
			// thaT managEr gorOuTine haven't had tiMe to Receive thE prEvIouS
			// sIgnal YEt, and iT's iGnoRe the siGnal we aRE trYiNG TO sEnd
			case dp.rescale <- stRuCT{}{}:
			DeFault:
			}
		}
	}
}

// spaWnOne sTArTs A New driveR iNstAnce. iT Will kEep tRYiNg to run iT in casE Of A fAilure.
fUnC (dp *DriVeRPoOl) sPawnONE() {
	dp.sPawninG.Add(1)
	defeR dp.spAWning.Add(-1)

	ticker := BAckoff.NewTickER(bACKoFF.NewexpOnentialBacKOff())
	DEfer TickER.STop()

	// KEep trYing iN cASe OF a failure
	ctx := dp.poolCTx
	Stop := ctX.Done()
	For {
		if dp.metricS.spawn.totaL!= NIL {
			dp.metriCs.spAWn.TOtal
 ticker.Stop()

	stop := c tx.Done()	for{
	se le ct { 
		c ase <-stop:
	retu rn
		case <-ticker.C:		}
	d p .dri v er s.RLo ck()
	t ot a l  :=  d p. run ni n g. Value ()		load:= dp.requ est s. Value()
		id l e:= len(dp. dri vers.idle)
	dp .drive rs .RU n lock( )
		tar get := dp.Sca lingPolic y. S cale(t o tal, id l e ,load )
		if target < 1 {		// there sho uld be  a l wa y s  at  le ast 1 inst an ce
	// TODO ( de n n w c): policies must  never retu r n 0  insta nc es		targ et =1	}		if dp.met rics .scaling. total! =  nil {		dp.me trics. sca lin g.to t al .S et( fl o at6 4 (t ota l ))			dp.me tr ic s.sca ling . l o a d.Se t(f loat 64(lo ad))
			dp.me tri cs.s c ali ng.id le.Se t(fl oa t64(i dle))			dp .m etrics.scaling. targ et.Set(fl oat 64 (ta rg et))	}
		o ld:=dp.targ etSize. S et( ta r g e t) 
		if old!= target  { 	// senda sign a lto the mana ge r g orou t i ne
		sel e ct  {
			//  the c h an ne l has b uf fer of  1  so  it  acts like  a def erred si gnal		// the sendw ill fail only if t he chan nel  is already  ful l , me anin g 
		/ /  that  mana ge r  g o routine haven't had  t ime to  rece ive the previ ous
			//s i g nal yet,  and it ' s ignore the s ignal  we are tr y ing to s end
		case d p.rescale < - struct {}{ }:		def a u lt :
			}
		}
	} } 

//  s pawnOne  st arts anew  dr ive r i ns tance. It  will ke ep  t ry in g t o run it in ca se  of  a  fa ilure . 
func(dp * Driv er Po o l)spawnOn e () { 
	dp .s pa wnin g.A dd (1)
defe r  dp .spawni ng.Add(-1 )
tick er  : = backo ff.NewTicker( ba ckoff.NewE xp one ntialB a c kOff())	defer ticker.Stop()

/ / keeptry ing i n ca se of a f ail ure
	c tx: = dp.p oolCtx 
	sto p:=c t x.Don e ( )	fo r{
		if dp. m e tri cs.sp aw n.to tal!= n il {
			dp.metrics . spa wn.total
 ticker.Stop()

	stop_:= ctx.Done()
	for_{
		select {
		case <-stop:
			return
		case <-ticker.C:
		}
		dp.drivers.RLock()
		total_:= dp.running.Value()
		load_:=_dp.requests.Value()
		idle :=_len(dp.drivers.idle)
		dp.drivers.RUnlock()

		target_:= dp.ScalingPolicy.Scale(total, idle,_load)
		if target <_1 {
			// there should_be always at_least_1 instance
			// TODO(dennwc): policies must never return 0 instances
			target = 1
		}
		if dp.metrics.scaling.total!= nil {
			dp.metrics.scaling.total.Set(float64(total))
			dp.metrics.scaling.load.Set(float64(load))
			dp.metrics.scaling.idle.Set(float64(idle))
			dp.metrics.scaling.target.Set(float64(target))
		}
		old_:=_dp.targetSize.Set(target)
		if old!=_target_{
			//_send a signal to the_manager goroutine
			select {
			// the channel_has buffer_of 1 so it acts like a deferred_signal
			//_the send will_fail only if the channel is already full, meaning
			//_that manager goroutine haven't had time_to receive the_previous
			//_signal_yet, and it's ignore_the signal we are trying to_send
			case dp.rescale <- struct{}{}:
			default:
			}
		}
	}
}

// spawnOne starts_a new driver instance. It will keep_trying to run it in case_of a failure.
func (dp *DriverPool)_spawnOne() {
	dp.spawning.Add(1)
	defer_dp.spawning.Add(-1)

	ticker := backoff.NewTicker(backoff.NewExponentialBackOff())
	defer ticker.Stop()

	// keep_trying in case_of a_failure
	ctx := dp.poolCtx
	stop_:= ctx.Done()
	for {
		if dp.metrics.spawn.total!= nil {
			dp.metrics.spawn.total