Skip to content

Commit

Permalink
fix: set GOMAXPROCS to optimize performance (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Yusan Kurban <[email protected]>
  • Loading branch information
yusank authored Apr 4, 2023
1 parent 1eb1e4a commit f206167
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -17,6 +17,8 @@ package main

import (
"os"
"runtime"
"strconv"

"github.com/go-logr/logr"
apiserver "k8s.io/apiserver/pkg/server"
Expand All @@ -29,11 +31,22 @@ import (
)

func main() {
setMaxProcs()
if err := runWebhookCmd(); err != nil {
os.Exit(1)
}
}

func setMaxProcs() {
s := os.Getenv("CPUS")
f, err := strconv.ParseFloat(s, 64)
if err != nil || f < 1 {
f = 1
}

runtime.GOMAXPROCS(int(f))
}

func runWebhookCmd() error {
logs.InitLogs()
defer logs.FlushLogs()
Expand Down

0 comments on commit f206167

Please sign in to comment.