Skip to content

Commit

Permalink
feat(go): improve cold start of 200ms by building outside of nsjail
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Nov 20, 2022
1 parent 8a71625 commit 838a92a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
28 changes: 2 additions & 26 deletions backend/windmill-worker/nsjail/run.go.config.proto
Expand Up @@ -58,38 +58,14 @@ mount {
options: "size=500000000"
}

mount {
src: "{JOB_DIR}/go.sum"
dst: "/tmp/go/go.sum"
is_bind: true
mandatory: false
}

mount {
src: "{JOB_DIR}/go.mod"
dst: "/tmp/go/go.mod"
is_bind: true
}

mount {
src: "{JOB_DIR}/main.go"
dst: "/tmp/go/main.go"
src: "{JOB_DIR}/main"
dst: "/tmp/go/main"
is_bind: true
mandatory: false
}

mount {
src: "{JOB_DIR}/inner/inner_main.go"
dst: "/tmp/go/inner/inner_main.go"
is_bind: true
}

mount {
src: "{JOB_DIR}/inner/runner.go"
dst: "/tmp/go/inner/runner.go"
is_bind: true
}

mount {
src: "{JOB_DIR}/args.json"
dst: "/tmp/go/args.json"
Expand Down
21 changes: 13 additions & 8 deletions backend/windmill-worker/src/worker.rs
Expand Up @@ -1151,21 +1151,26 @@ func Run(req Req) (interface{{}}, error){{
.replace("{SHARED_MOUNT}", shared_mount),
)
.await?;
let build_go = Command::new(go_path)
.current_dir(job_dir)
.env_clear()
.env("PATH", path_env)
.env("BASE_INTERNAL_URL", base_internal_url)
.env("GOPATH", GO_CACHE_DIR)
.env("HOME", home_env)
.args(vec!["build", "main.go"])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
handle_child(&job.id, db, logs, timeout, build_go).await?;

Command::new(nsjail_path)
.current_dir(job_dir)
.env_clear()
.envs(reserved_variables)
.env("PATH", path_env)
.env("BASE_INTERNAL_URL", base_internal_url)
.args(vec![
"--config",
"run.config.proto",
"--",
go_path,
"run",
"main.go",
])
.args(vec!["--config", "run.config.proto", "--", "/tmp/go/main"])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
Expand Down

0 comments on commit 838a92a

Please sign in to comment.