Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #131 from Netflix/oom-2
Browse files Browse the repository at this point in the history
Introduce OOM settings for containers
  • Loading branch information
sargun authored May 21, 2018
2 parents 8576bf6 + cf73461 commit 75bb466
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
46 changes: 45 additions & 1 deletion executor/mock/standalone/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
}
ubuntu = testImage{
name: "titusoss/ubuntu",
tag: "20180501-1525157359",
tag: "20180518-1526605880",
}
// TODO: Determine how this got built, and add it to the auto image builders?
byDigest = testImage{
Expand Down Expand Up @@ -94,6 +94,8 @@ func TestStandalone(t *testing.T) {
testTerminateTimeout,
testMakesPTY,
testTerminateTimeoutNotTooSlow,
testOOMAdj,
testOOMKill,
}
for _, fun := range testFunctions {
fullName := runtime.FuncForPC(reflect.ValueOf(fun).Pointer()).Name()
Expand Down Expand Up @@ -531,3 +533,45 @@ func testTerminateTimeoutNotTooSlow(t *testing.T, jobID string) {
t.Fatalf("Task wasn't killed quickly enough, in %s", killTime.String())
}
}

func testOOMAdj(t *testing.T, jobID string) {
ji := &mock.JobInput{
ImageName: ubuntu.name,
Version: ubuntu.tag,
Entrypoint: `/bin/bash -c 'cat /proc/1/oom_score | grep 999'`,
JobID: jobID,
}
if !mock.RunJobExpectingSuccess(ji) {
t.Fail()
}
}

func testOOMKill(t *testing.T, jobID string) {
// Start the executor
jobRunner := mock.NewJobRunner()
defer jobRunner.StopExecutorAsync()

ji := &mock.JobInput{
ImageName: ubuntu.name,
Version: ubuntu.tag,
Entrypoint: `stress --vm 100 --vm-keep --vm-hang 100`,
JobID: jobID,
}
jobResponse := jobRunner.StartJob(ji)

// Wait until the task is running

for status := range jobResponse.UpdateChan {

if mock.IsTerminalState(status.State) {
if status.State.String() != "TASK_FAILED" {
t.Fail()
}
if !strings.Contains(status.Mesg, "OOMKilled") {
t.Fatal("Task killed due to: ", status.Mesg)
}
return
}
}
t.Fail()
}
4 changes: 4 additions & 0 deletions executor/runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,10 @@ func (r *DockerRuntime) setupPostStartLogDirTiniHandleConnection2(parentCtx cont
}
}

if err := setupOOMAdj(c, cred); err != nil {
return err
}

if err := setupContainerNesting(parentCtx, c, cred); err != nil {
log.Error("Unable to setup container nesting: ", err)
return err
Expand Down
18 changes: 18 additions & 0 deletions executor/runtime/docker/docker_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,21 @@ func setupContainerNesting(parentCtx context.Context, c *runtimeTypes.Container,

return ret
}

func setupOOMAdj(c *runtimeTypes.Container, cred ucred) error {
oomScore := 1000

if c.TitusInfo.OomScoreAdj != nil {
oomScore = int(c.TitusInfo.GetOomScoreAdj())
}

pid := strconv.FormatInt(int64(cred.pid), 10)
oomScoreAdjPath := filepath.Join("/proc", pid, "oom_score_adj")
file, err := os.OpenFile(oomScoreAdjPath, os.O_RDWR, 0000)
if err != nil {
return err
}
defer shouldClose(file)
_, err = file.WriteString(fmt.Sprintf("%d\n", oomScore))
return err
}
4 changes: 4 additions & 0 deletions executor/runtime/docker/docker_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ func cleanupCgroups(cgroupPath string) error {
func setupContainerNesting(parentCtx context.Context, c *runtimeTypes.Container, cred ucred) error {
return errUnsupported
}

func setupOOMAdj(c *runtimeTypes.Container, cred ucred) error {
return errUnsupported
}
2 changes: 1 addition & 1 deletion hack/test-images/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM ubuntu:xenial
RUN apt-get update && apt-get install -y curl libcap2-bin grep iproute2 httpie iputils-ping
RUN apt-get update && apt-get install -y curl libcap2-bin grep iproute2 httpie iputils-ping stress

0 comments on commit 75bb466

Please sign in to comment.