fn: remove eviction timer to simplify eviction logic (#1223)

We tie container pausing with evictions, where if a container
is paused, then it is also eligible for eviction.
This commit is contained in:
Tolga Ceylan
2018-09-18 15:20:39 -07:00
committed by GitHub
parent b043e619d3
commit a9bba2c3a8
2 changed files with 11 additions and 18 deletions

View File

@@ -1058,11 +1058,9 @@ func (a *agent) runHotReq(ctx context.Context, call *call, state ContainerState,
freezeTimer := time.NewTimer(a.cfg.FreezeIdle)
idleTimer := time.NewTimer(time.Duration(call.IdleTimeout) * time.Second)
ejectTimer := time.NewTimer(a.cfg.EjectIdle)
defer freezeTimer.Stop()
defer idleTimer.Stop()
defer ejectTimer.Stop()
// log if any error is encountered
defer func() {
@@ -1071,6 +1069,8 @@ func (a *agent) runHotReq(ctx context.Context, call *call, state ContainerState,
}
}()
evictor := a.evictor.GetEvictor(call.ID, call.slotHashId, call.Memory+uint64(call.TmpFsSize), uint64(call.CPUs))
// if an immediate freeze is requested, freeze first before enqueuing at all.
if a.cfg.FreezeIdle == time.Duration(0) && !isFrozen {
err = cookie.Freeze(ctx)
@@ -1079,10 +1079,12 @@ func (a *agent) runHotReq(ctx context.Context, call *call, state ContainerState,
}
isFrozen = true
state.UpdateState(ctx, ContainerStatePaused, call.slots)
if !isEvictable {
isEvictable = true
a.evictor.RegisterEvictor(evictor)
}
}
evictor := a.evictor.GetEvictor(call.ID, call.slotHashId, call.Memory+uint64(call.TmpFsSize), uint64(call.CPUs))
if !isFrozen {
state.UpdateState(ctx, ContainerStateIdle, call.slots)
}
@@ -1104,16 +1106,15 @@ func (a *agent) runHotReq(ctx context.Context, call *call, state ContainerState,
}
isFrozen = true
state.UpdateState(ctx, ContainerStatePaused, call.slots)
if !isEvictable {
isEvictable = true
a.evictor.RegisterEvictor(evictor)
}
}
continue
case <-evictor.C:
logger.Debug("attempting hot function eject")
logger.Debug("attempting hot function eviction")
isEvictEvent = true
case <-ejectTimer.C:
// we've been idle too long, now we are ejectable
a.evictor.RegisterEvictor(evictor)
isEvictable = true
continue
}
break
}