0

I have a Django REST Framework service. Once in a while, the service gets a large request and when that happens, it eats a large chunk of OS memory (a K8 pod in my case). After the request is processed and garbage collection is done (sometimes forced), the objects are released but the amount of memory occupied by Python never goes down until the OS starts running low on memory.

I have read this, this and this. And it looks like I cannot force Python to give that memory back to the OS. However, is there a way to limit the amount of memory Python has access to in the first place? This way, I can ensure that Python doesn't eat up memory on its own and other processes have plenty to play around with too. Kinda similar to how you can set the memory a JVM can use.

ritratt
  • 1,703
  • 4
  • 25
  • 45
  • Yes, with https://docs.python.org/3/library/resource.html#resource.setrlimit and https://docs.python.org/3/library/resource.html#resource.RLIMIT_VMEM – Alex Hall Apr 16 '20 at 19:24
  • 1
    Kubernetes can do that of cause: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ – Klaus D. Apr 16 '20 at 19:26
  • In k8s you want to set "resources" on the pod/deployment. https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/ – jordanm Apr 16 '20 at 19:27
  • @KlausD. they probably want it set on a pod/deployment level, not namespace level – jordanm Apr 16 '20 at 19:27
  • 1
    @jordanm fixed that. – Klaus D. Apr 16 '20 at 19:28

0 Answers0