Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go/worker/lambda/packages/packagePuller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ func (pp *PackagePuller) sandboxInstall(p *Package) (err error) {
}()

meta := &sandbox.SandboxMeta{
MemLimitMB: common.Conf.Limits.Installer_mem_mb,
Limits: common.Limits{
MemMB: common.Conf.Limits.Installer_mem_mb,
// CPUPercent and RuntimeSec left as zero to use defaults
},
}
sb, err := pp.sbPool.Create(nil, true, pp.pipLambda, scratchDir, meta, common.RT_PYTHON)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions go/worker/sandbox/api.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package sandbox

import (
"github.com/open-lambda/open-lambda/go/common"
"net/http"

"github.com/open-lambda/open-lambda/go/common"
)

type SandboxPool interface {
Expand Down Expand Up @@ -85,10 +86,9 @@ type Sandbox interface {
}

type SandboxMeta struct {
Installs []string
Imports []string
MemLimitMB int
CPUPercent int
Installs []string
Imports []string
Limits common.Limits // required; zeros = use defaults
}

type SandboxError string
Expand Down
14 changes: 8 additions & 6 deletions go/worker/sandbox/dockerPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func NewDockerPool(pidMode string, caps []string) (*DockerPool, error) {

// Create creates a docker sandbox from the handler and sandbox directory.
func (pool *DockerPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir string, meta *SandboxMeta, _ common.RuntimeType) (sb Sandbox, err error) {
meta = fillMetaDefaults(meta)
if meta == nil {
meta = &SandboxMeta{}
}
// Resolve zero-valued limits to worker defaults
meta.Limits.FillDefaults(common.Conf.Limits.ToLimits())
t := common.T0("Create()")
defer t.T1()

Expand Down Expand Up @@ -108,7 +112,6 @@ func (pool *DockerPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir
// create the container using the specified configuration
procLimit := int64(common.Conf.Limits.Procs)
swappiness := int64(common.Conf.Limits.Swappiness)
cpuPercent := int64(common.Conf.Limits.CPU_percent)
container, err := pool.client.CreateContainer(
docker.CreateContainerOptions{
Config: &docker.Config{
Expand All @@ -124,8 +127,8 @@ func (pool *DockerPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir
Runtime: pool.dockerRuntime,
PidsLimit: &procLimit,
MemorySwappiness: &swappiness,
CPUPercent: cpuPercent,
Memory: int64(meta.MemLimitMB * 1024 * 1024),
CPUPercent: int64(meta.Limits.CPUPercent),
Memory: int64(meta.Limits.MemMB * 1024 * 1024),
},
},
)
Expand Down Expand Up @@ -169,9 +172,8 @@ func (pool *DockerPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir

c.httpClient = &http.Client{
Transport: &http.Transport{Dial: dial},
Timeout: time.Second * time.Duration(common.Conf.Limits.Max_runtime_default),
Timeout: time.Second * time.Duration(meta.Limits.RuntimeSec),
}

// wrap to make thread-safe and handle container death
safe := newSafeSandbox(c)
safe.startNotifyingListeners(pool.eventHandlers)
Expand Down
17 changes: 2 additions & 15 deletions go/worker/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,9 @@ func SandboxPoolFromConfig(name string, sizeMb int) (cf SandboxPool, err error)
return nil, fmt.Errorf("invalid sandbox type: '%s'", common.Conf.Sandbox)
}

func fillMetaDefaults(meta *SandboxMeta) *SandboxMeta {
if meta == nil {
meta = &SandboxMeta{}
}
if meta.MemLimitMB == 0 {
meta.MemLimitMB = common.Conf.Limits.Mem_mb
}
if meta.CPUPercent == 0 {
meta.CPUPercent = common.Conf.Limits.CPU_percent
}
return meta
}

func (meta *SandboxMeta) String() string {
return fmt.Sprintf("<installs=[%s], imports=[%s], mem-limit-mb=%v>",
strings.Join(meta.Installs, ","), strings.Join(meta.Imports, ","), meta.MemLimitMB)
return fmt.Sprintf("<installs=[%s], imports=[%s], mem-limit-mb=%d>",
strings.Join(meta.Installs, ","), strings.Join(meta.Imports, ","), meta.Limits.MemMB)
}

func (e SandboxError) Error() string {
Expand Down
2 changes: 1 addition & 1 deletion go/worker/sandbox/sock.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (container *SOCKContainer) Unpause() (err error) {
// block until we have enough mem to upsize limit to the
// normal size before unpausing
oldLimit := container.cg.GetMemLimitMB()
newLimit := common.Conf.Limits.Mem_mb
newLimit := container.meta.Limits.MemMB
container.pool.mem.adjustAvailableMB(oldLimit - newLimit)
container.cg.SetMemLimitMB(newLimit)
}
Expand Down
11 changes: 7 additions & 4 deletions go/worker/sandbox/sockPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ func sbStr(sb Sandbox) string {
}

func (pool *SOCKPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir string, meta *SandboxMeta, rtType common.RuntimeType) (sb Sandbox, err error) {
if meta == nil {
meta = &SandboxMeta{}
}
meta.Limits.FillDefaults(common.Conf.Limits.ToLimits())
id := fmt.Sprintf("%d", atomic.AddInt64(&nextId, 1))
meta = fillMetaDefaults(meta)
pool.printf("<%v>.Create(%v, %v, %v, %v, %v)=%s...", pool.name, sbStr(parent), isLeaf, codeDir, scratchDir, meta, id)
defer func() {
pool.printf("...returns %v, %v", sbStr(sb), err)
Expand All @@ -91,7 +94,7 @@ func (pool *SOCKPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir st

// block until we have enough to cover the cgroup mem limits
t2 := t.T0("acquire-mem")
pool.mem.adjustAvailableMB(-meta.MemLimitMB)
pool.mem.adjustAvailableMB(-meta.Limits.MemMB)
t2.T1()

t2 = t.T0("acquire-cgroup")
Expand All @@ -101,7 +104,7 @@ func (pool *SOCKPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir st
// don't want to use this cgroup feature, because the child
// would take the blame for ALL of the parent's allocations
moveMemCharge := (parent == nil)
cSock.cg = pool.cgPool.GetCg(meta.MemLimitMB, moveMemCharge, meta.CPUPercent)
cSock.cg = pool.cgPool.GetCg(meta.Limits.MemMB, moveMemCharge, meta.Limits.CPUPercent)
t2.T1()
cSock.printf("use cgroup %s", cSock.cg.Name())

Expand Down Expand Up @@ -192,7 +195,7 @@ func (pool *SOCKPool) Create(parent Sandbox, isLeaf bool, codeDir, scratchDir st

cSock.client = &http.Client{
Transport: &http.Transport{Dial: dial},
Timeout: time.Second * time.Duration(common.Conf.Limits.Max_runtime_default),
Timeout: time.Second * time.Duration(meta.Limits.RuntimeSec),
}

// event handling
Expand Down