Rethinkdb container: rethinkdb process takes less RAM than the whole container

11/7/2015

I'm running my rethinkdb container in Kubernetes cluster. Below is what I notice:

Running top in the host which is CoreOS, rethinkdb process takes about 3Gb:

$ top
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  981 root      20   0   53.9m  34.5m  20.9m S  15.6  0.4   1153:34 hyperkube
51139 root      20   0 4109.3m 3.179g  22.5m S  15.0 41.8 217:43.56 rethinkdb
  579 root      20   0  707.5m  76.1m  19.3m S   2.3  1.0 268:33.55 kubelet

But running docker stats to check the rethinkdb container, it takes about 7Gb!

$ docker ps | grep rethinkdb
eb9e6b83d6b8        rethinkdb:2.1.5                             "rethinkdb --bind al   3 days ago          Up 3 days                               k8s_rethinkdb-3.746aa_rethinkdb-rc-3-eiyt7_default_560121bb-82af-11e5-9c05-00155d070266_661dfae4

$ docker stats eb9e6b83d6b8
CONTAINER           CPU %               MEM USAGE/LIMIT     MEM %               NET I/O
eb9e6b83d6b8        4.96%               6.992 GB/8.169 GB   85.59%              0 B/0 B

$ free -m
         total       used       free     shared    buffers     cached
Mem:          7790       7709         81          0         71       3505
-/+ buffers/cache:       4132       3657
Swap:            0          0          0

Can someone explain why the container is taking a lot more memory than the rethinkdb process itself?

I'm running docker v1.7.1, CoreOS v773.1.0, kernel 4.1.5

-- Quyen Nguyen Tuan
docker
kubernetes
rethinkdb

1 Answer

11/7/2015

In top command, your are looking at physical memory amount. in stats command, this also include the disk cached ram, so it's always bigger than the physical amount of ram. When you really need more RAM, the disk cached will be released for the application to use.

In deed, the memmory usage is pulled via cgroup memory.usage_in_bytes, you can access it in /sys/fs/cgroup/memory/docker/long_container_id/memory.usage_in_bytes. And acording to linux doc https://www.kernel.org/doc/Documentation/cgroups/memory.txt section 5.5:

5.5 usage_in_bytes

For efficiency, as other kernel components, memory cgroup uses some optimization to avoid unnecessary cacheline false sharing. usage_in_bytes is affected by the method and doesn't show 'exact' value of memory (and swap) usage, it's a fuzz value for efficient access. (Of course, when necessary, it's synchronized.) If you want to know more exact memory usage, you should use RSS+CACHE(+SWAP) value in memory.stat(see 5.2).

-- kureikain
Source: StackOverflow