개발/Kubernetes

Tensorflow in Kubernetes - CPU Memory Troubleshooting

bitofsky 2022. 9. 19. 17:34

K8s에서 텐서플로우의 CPU Training을 돌릴 때 겪은 문제

  • CPU / Memory 사용량이 치솟아 QoS Burstable / BestEffort로는 Pod Eviction이 발생함
  • CPU / Memory의 Request와 Limit을 동일하게 설정해 QoS를 Guaranteed로 주면 OOM Killed로 죽음

원인은 기본 System Malloc을 사용할 때 Python TF가 돌면서 메모리 할당을 VM Memory Limit를 보지 않고 노드 호스트를 기준으로 동작해 Pod의 Limit를 초과하는 Memory를 사용해 OOM이 발생하는 것 같다.

이것 대신 구글의 libtcmalloc으로 변경해주면 된다.

https://stackoverflow.com/a/57288305

 

TF 학습 이미지에 google-perftools 를 설치하고 실행전에 환경변수 LD_PRELOAD에 libtcmalloc 경로를 정의하면 된다.

apt-get update
apt-get install google-perftools -y
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4 python training.py

 

'개발 > Kubernetes' 카테고리의 다른 글

Kubernetes OpenLens 6.1.12 Download  (0) 2022.08.01
Hyper-V 에서 Kubernetes 설치하기  (0) 2022.05.27
kubectl tip  (0) 2022.05.25