Skip to content

Commit

Permalink
feat: crocochrome: try to use choom to lower oom_score_adj, failing g…
Browse files Browse the repository at this point in the history
…racefully
  • Loading branch information
nadiamoe committed Jan 31, 2025
1 parent 7fb2bae commit 8924469
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/crocochrome/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log/slog"
"net/http"
"os"
"os/exec"
"strconv"

"github.com/grafana/crocochrome"
crocohttp "github.com/grafana/crocochrome/http"
Expand All @@ -18,6 +20,20 @@ func main() {
Level: slog.LevelDebug,
}))

const oomScore = -500
if out, err := choom(oomScore); err != nil {
logger.Error(
"Error changing OOM score, assuming this is not a production environment and continuing anyway",
"err", err,
"choomOutput", string(out),
)
} else {
logger.Info(
"Main process OOM score adjusted successfully",
"oomScore", oomScore,
)
}

mux := http.NewServeMux()

registry := prometheus.NewRegistry()
Expand Down Expand Up @@ -56,3 +72,9 @@ func main() {
logger.Error("Setting up HTTP listener", "err", err)
}
}

// choom runs the choom helper (source included in this repo) to lower the current process OOM score.
func choom(score int) ([]byte, error) {
choom := exec.Command("choom", strconv.Itoa(os.Getpid()), strconv.Itoa(score))
return choom.CombinedOutput()
}

0 comments on commit 8924469

Please sign in to comment.