antonputra / tutorials

DevOps Tutorials
https://youtube.com/antonputra
MIT License
3.19k stars 2.5k forks source link

Lesson 210 - GOMAXPROCS and K8s CFS scheduler #289

Closed agravelot closed 1 month ago

agravelot commented 1 month ago

If your k8s node has more cpus than your deployment limit, the golang scheduler will not be aware of the kubernetes CFS scheduler, leading to many/all coroutines in a sleep state, false result. Setting GOMAXPROCS=2 as in k8s deployment can lead to better performance.

https://github.com/uber-go/automaxprocs is specially designed for this purpose.

Related discussion: https://github.com/antonputra/tutorials/pull/288

agravelot commented 1 month ago

I hadn't noticed this PR with better explaination: https://github.com/antonputra/tutorials/pull/278 May still be relevant to the current branch.

antonputra commented 1 month ago

Thank you, @agravelot! I did some more research and even ran tests. You're right—GOMAXPROCS makes a significant difference! I'll be using it in all my future benchmarks.

env:
- name: GOMAXPROCS
  valueFrom:
    resourceFieldRef:
      resource: limits.cpu
resources:
  requests:
    memory: 128Mi
    cpu: 500m
  limits:
    memory: 256Mi
    cpu: 1000m

https://www.youtube.com/watch?v=h2pCxj_Fkdc&t=984s

Screenshot 2024-10-03 at 12 41 02 AM