mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
if a slot is available, don't launch more (#701)
since we were sending a signal before checking if a slot was available, even in the case of serial calls locally I was seeing 2 containers launch. if we only send a signal after first checking if a slot is available, this goes away. 1 usec should not be too offensive of an additional wait, all things considered here.
This commit is contained in:
committed by
Tolga Ceylan
parent
6662ed9c2a
commit
c9e995292c
@@ -378,17 +378,14 @@ func (a *agent) hotLauncher(ctx context.Context, callObj *call) {
|
|||||||
|
|
||||||
// waitHot pings and waits for a hot container from the slot queue
|
// waitHot pings and waits for a hot container from the slot queue
|
||||||
func (a *agent) waitHot(ctx context.Context, call *call) (Slot, error) {
|
func (a *agent) waitHot(ctx context.Context, call *call) (Slot, error) {
|
||||||
|
|
||||||
ch, cancel := call.slots.startDequeuer()
|
ch, cancel := call.slots.startDequeuer()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
for {
|
// 1) if we can get a slot immediately, grab it.
|
||||||
// send a notification to launcHot()
|
// 2) if we don't, send a signaller every 200ms until we do.
|
||||||
select {
|
|
||||||
case call.slots.signaller <- true:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
|
sleep := 1 * time.Microsecond // pad, so time.After doesn't send immediately
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case s := <-ch:
|
case s := <-ch:
|
||||||
if s.acquireSlot() {
|
if s.acquireSlot() {
|
||||||
@@ -401,10 +398,18 @@ func (a *agent) waitHot(ctx context.Context, call *call) (Slot, error) {
|
|||||||
// we failed to take ownership of the token (eg. container idle timeout) => try again
|
// we failed to take ownership of the token (eg. container idle timeout) => try again
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
case <-time.After(time.Duration(200) * time.Millisecond):
|
|
||||||
// ping dequeuer again
|
|
||||||
case <-a.shutdown: // server shutdown
|
case <-a.shutdown: // server shutdown
|
||||||
return nil, models.ErrCallTimeoutServerBusy
|
return nil, models.ErrCallTimeoutServerBusy
|
||||||
|
case <-time.After(sleep):
|
||||||
|
// ping dequeuer again
|
||||||
|
}
|
||||||
|
|
||||||
|
// set sleep to 200ms after first iteration
|
||||||
|
sleep = 200 * time.Millisecond
|
||||||
|
// send a notification to launchHot()
|
||||||
|
select {
|
||||||
|
case call.slots.signaller <- true:
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user