Skip to content

Commit

Permalink
Configure GOMAXPROCS and update docker-compose for CPU limits
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryKogan committed Dec 14, 2024
1 parent 45e993f commit 64fde03
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/jwt-microservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"log/slog"
"net/http"
"runtime"

"github.com/GregoryKogan/jwt-microservice/pkg/auth"
"github.com/GregoryKogan/jwt-microservice/pkg/cache"
Expand All @@ -16,6 +17,12 @@ func main() {
config.Init()
logging.Init()

maxProcs := viper.GetInt("server.max_processors")
if maxProcs > 0 {
runtime.GOMAXPROCS(maxProcs)
slog.Info("Processor configuration", slog.Int("max_procs", maxProcs), slog.Int("system_logical_procs", runtime.NumCPU()))
}

mux := http.NewServeMux()

slog.Info("Initializing cache connection")
Expand Down
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
server:
port: 8080
max_processors: 2 # sets GOMAXPROCS

logging:
# available modes: text, json
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ services:
path: ./pkg
- action: rebuild
path: ./internal
deploy:
resources:
limits:
cpus: '0.50'

cache:
container_name: jwt-cache
Expand Down

0 comments on commit 64fde03

Please sign in to comment.