8000 adding per-lambda memory limit files by guptadevagya · Pull Request #306 · open-lambda/open-lambda · GitHub
[go: up one dir, main page]

Skip to content

adding per-lambda memory limit files #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ azure.json
boss.json
cluster.log
tasks.log
/venv
.vscode
5 changes: 3 additions & 2 deletions src/common/lambdaConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type CronTrigger struct {
// TODO: add KafkaTrigger struct

// LambdaConfig defines the overall configuration for the lambda function.
type LambdaConfig struct {
Triggers Triggers `yaml:"triggers"` // List of HTTP triggers
type LambdaConfig struct { // List of HTTP triggers
Triggers Triggers `yaml:"triggers"`
MemoryMaxMB *int `yaml:"memory_mb,omitempty"`
// Additional configurations can be added here.
}

Expand Down
22 changes: 18 additions & 4 deletions src/worker/sandbox/sockPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"path/filepath"
"strings"
"sync/atomic"
"net"
"net/http"
"time"

"github.com/open-lambda/open-lambda/ol/common"
Expand Down Expand Up @@ -101,7 +101,21 @@ 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)
// load lambda-specific config from code directory
lambdaConfig, err := common.LoadLambdaConfig(codeDir)
if err != nil {
// log error and use default settings
pool.printf("could not load lambda config from %s: %v. proceeding with defaults.", codeDir, err)
}
// start with default memory limit
memLimitMB := meta.MemLimitMB
// check if the per-lambda config was loaded AND if the memory field was set
if lambdaConfig != nil && lambdaConfig.MemoryMaxMB != nil {
memLimitMB = *lambdaConfig.MemoryMaxMB
// log memory override
pool.printf("using per-lambda memory limit of %d mb", memLimitMB)
}
cSock.cg = pool.cgPool.GetCg(memLimitMB, moveMemCharge, meta.CPUPercent)
t2.T1()
cSock.printf("use cgroup %s", cSock.cg.Name())

Expand Down Expand Up @@ -192,7 +206,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(common.Conf.Limits.Max_runtime_default),
}

// event handling
Expand Down
46 changes: 46 additions & 0 deletions template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"worker_dir": "",
"worker_url": "localhost",
"worker_port": "5000",
"log_output": true,
"sandbox": "sock",
"server_mode": "lambda",
"registry": "",
"registry_cache_ms": 5000,
"Pkgs_dir": "",
"pip_mirror": "",
"mem_pool_mb": 7337,
"import_cache_tree": "",
"sock_base_path": "",
"sandbox_config": {},
"docker": {
"runtime": "",
"base_image": "ol-min"
},
"limits": {
"procs": 10,
"mem_mb": 50,
"cpu_percent": 100,
"max_runtime_default": 30,
"swappiness": 0,
"installer_mem_mb": 500
},
"features": {
"reuse_cgroups": false,
"import_cache": "tree",
"downsize_paused_mem": true,
"enable_seccomp": true
},
"trace": {
"cgroups": false,
"memory": false,
"evictor": false,
"package": false,
"latency": false
},
"storage": {
"root": "private",
"scratch": "",
"code": ""
}
}
46 changes: 46 additions & 0 deletions worker-1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"worker_dir": "/app/worker-1/worker",
"worker_url": "localhost",
"worker_port": "5000",
"log_output": true,
"sandbox": "sock",
"server_mode": "lambda",
"registry": "/app/worker-1/registry",
"registry_cache_ms": 5000,
"Pkgs_dir": "/app/worker-1/lambda/packages",
"pip_mirror": "",
"mem_pool_mb": 7337,
"import_cache_tree": "/app/worker-1/default-zygotes-40.json",
"sock_base_path": "/app/worker-1/lambda",
"sandbox_config": {},
"docker": {
"runtime": "",
"base_image": "ol-min"
},
"limits": {
"procs": 10,
"mem_mb": 50,
"cpu_percent": 100,
"max_runtime_default": 30,
"swappiness": 0,
"installer_mem_mb": 500
},
"features": {
"reuse_cgroups": false,
"import_cache": "tree",
"downsize_paused_mem": true,
"enable_seccomp": true
},
"trace": {
"cgroups": false,
"memory": false,
"evictor": false,
"package": false,
"latency": false
},
"storage": {
"root": "private",
"scratch": "",
"code": ""
}
}
Loading
Loading
0