0

I have a Rocket web application packed into a Docker image. The application uses 4 or 5 times of more memory on start when deployed and running inside our Kubernetes environment (some Linux Docker host), than the memory usage of it running as a container on a Mac laptop Docker host.

What could cause this memory difference?

Locally (as a container running in my Mac laptop docker):

 PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
    1 root      20   0  187944  18916  12308 S   0.0  0.9   0:00.12 backend
   25 root      20   0   41024   3116   2668 R   0.0  0.2   0:00.03 top

On Linux docker host (Or on kubernetes):

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND     
    1 root      20   0  239244 108408  10840 S   0.0  0.3   0:00.67 backend     
   38 root      20   0   18144   3260   2820 S   0.0  0.0   0:00.00 bash        
   44 root      20   0   41032   3124   2660 R   0.0  0.0   0:00.00 top

You can see the RES value of the process backend is much higher as running on Kubernetes

I have double checked that the image versions are exactly the same.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Fuyang Liu
  • 1,496
  • 13
  • 26
  • Exact same binaries? I think of using a debug instead of a release version. Run `sha256sum` on both binaries and check, that they are equal. – hellow Oct 12 '18 at 11:57
  • Yes they both have `f2a112caf8163d484ca66b2542baad6b6411bba7296507d88059e981d9453646 backend` – Fuyang Liu Oct 12 '18 at 12:00
  • Is that a problem ? => No => So there is no problem ;) – Stargateur Oct 12 '18 at 12:05
  • What do you mean...? If I set memory limit on Kubernetes and keep the memory lower than 100MB, it will start killing my application again and again. And I simply believe my small app shouldn't take that much of memory when firstly loads up. – Fuyang Liu Oct 12 '18 at 12:08
  • So there is a problem, still I don't know how we could help you, you are comparing two runtime, one from mac one from linux, we don't even know what your application is doing, this is not answerable. Maybe linux need memory to do something. Maybe this question should be posted on ServerFault. – Stargateur Oct 12 '18 at 12:15
  • I will try make a small repo and have some minimal code to see if it uses different memory on different environment then. – Fuyang Liu Oct 12 '18 at 12:32

1 Answers1

0

The Rocket application by default will create multiple worker threads based on the system resources and each worker will have some memory overhead.

On Kubernetes we have large nodes which have more cores than my local laptop, resulting in the memory of the web application increasing a lot.

I tried to reduce the total number of workers of my Rocket application down to half and the memory usage seem reduced by around half as well.

I'm not sure whether there are other reasons that could cause the difference, but this could be the major reason.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Fuyang Liu
  • 1,496
  • 13
  • 26