mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Container memory tracking related changes (#541)
* squash# This is a combination of 10 commits2 fn: get available memory related changes *) getAvailableMemory() improvements *) early fail if requested memory too large to meet *) tracking async and sync pools individually. Sync pool is reserved for sync jobs only, while async pool can be used by all jobs. *) head room estimation for available memory in Linux.
This commit is contained in:
@@ -275,6 +275,11 @@ func (a *agent) launchOrSlot(ctx context.Context, slots chan slot, call *call) (
|
||||
default:
|
||||
}
|
||||
|
||||
// IMPORTANT: This means, if this request was submitted indirectly through fnlb or
|
||||
// other proxy, we will continue classifying it as 'async' which is good as async
|
||||
// regardless of origin should use the async resources.
|
||||
isAsync := call.Type == models.TypeAsync
|
||||
|
||||
// add context cancel here to prevent ramToken/launch race, w/o this ramToken /
|
||||
// launch won't know whether we are no longer receiving or not yet receiving.
|
||||
ctx, launchCancel := context.WithCancel(ctx)
|
||||
@@ -284,7 +289,10 @@ func (a *agent) launchOrSlot(ctx context.Context, slots chan slot, call *call) (
|
||||
select {
|
||||
case s := <-slots:
|
||||
return s, nil
|
||||
case tok := <-a.resources.GetResourceToken(ctx, call):
|
||||
case tok, isOpen := <-a.resources.GetResourceToken(ctx, call.Memory, isAsync):
|
||||
if !isOpen {
|
||||
return nil, models.ErrCallTimeoutServerBusy
|
||||
}
|
||||
errCh = a.launch(ctx, slots, call, tok) // TODO mangle
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
@@ -494,7 +502,7 @@ func (a *agent) prepCold(ctx context.Context, slots chan<- slot, call *call, tok
|
||||
// about timing out if this takes a while...
|
||||
cookie, err := a.driver.Prepare(ctx, container)
|
||||
if err != nil {
|
||||
tok.Close() // TODO make this less brittle
|
||||
tok.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user