# Redis memory usage

**URL:** <https://forums.docker.com/t/redis-memory-usage/33228>\
**Category:** General\
**Tags:** docker, amazonwebservices\
**Created:** [June 6, 2017, 8:10pm UTC](https://forums.docker.com/t/redis-memory-usage/33228 "2017-06-06T20:10:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roberto](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@roberto](https://forums.docker.com/u/roberto)\
**Post date:** [June 6, 2017, 8:10pm UTC](https://forums.docker.com/t/redis-memory-usage/33228/1 "2017-06-06T20:10:48Z")

</div>

I’m running Redis as a docker service and when I login to the machine it was assigned to and run `docker stats` I get the following:

```auto
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
redis.1.wsqexigxdtraidyyphpmuunbm 0.08% 250.3MiB / 7.797GiB 3.13% 441MB / 190MB 0B / 175MB 0

```

Specifically, note the mem usage of `250.3MiB`.

When running `top`, however, I see it’s using less than 200M:

```auto
6662 999 20 0 197144 171788 1508 S 0.0 2.1 1:19.12 redis-server 

```

The only process running in the container is Redis itself:

```auto
ubuntu@prod-docker-4:~$ docker exec -t -i redis.1.wsqexigxdtraidyyphpmuunbm /bin/bash -c 'ps -efww'
UID PID PPID C STIME TTY TIME CMD
redis 1 0 3 19:23 ? 00:01:19 redis-server *:6379
root 21 0 0 20:06 ? 00:00:00 ps -efww

```

This doesn’t appear to be a fixed amount of “container overhead”, but rather ~1.5X ratio. 😕

Here are some more stats on Docker’s memory stats and the process memory usage:

```auto
ps aux --sort -rss, docker stats, ratio
171788, 250.3MiB, 1.46
343828, 514.2MiB, 1.49
433940, 656.1MiB, 1.51
519956, 788.7MiB, 1.52

```

Any ideas on where the additional memory is going?

System info:

```auto
ubuntu@prod-docker-4:~$ uname -a
Linux prod-docker-4 3.13.0-119-generic #166-Ubuntu SMP Wed May 3 12:18:55 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@prod-docker-4:~$ cat /etc/issue.net
Ubuntu 14.04.5 LTS
ubuntu@prod-docker-4:~$ docker version
Client:
 Version: 17.04.0-ce
 API version: 1.28
 Go version: go1.7.5
 Git commit: 4845c56
 Built: Mon Apr 3 17:54:19 2017
 OS/Arch: linux/amd64

Server:
 Version: 17.04.0-ce
 API version: 1.28 (minimum version 1.12)
 Go version: go1.7.5
 Git commit: 4845c56
 Built: Mon Apr 3 17:54:19 2017
 OS/Arch: linux/amd64
 Experimental: false

```

Thanks!

---

<div class="post-metadata">

**Author:** ![junius](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@junius](https://forums.docker.com/u/junius)\
**Post date:** [October 14, 2017, 5:15am UTC](https://forums.docker.com/t/redis-memory-usage/33228/2 "2017-10-14T05:15:44Z")

</div>

could connect to redis and run `info`. it would show the memory usage like below:

```auto
# Memory
used_memory:409964064
used_memory_human:390.97M
used_memory_rss:422481920
used_memory_rss_human:402.91M
used_memory_peak:409995904
used_memory_peak_human:391.00M
used_memory_peak_perc:99.99%
used_memory_overhead:126958696
used_memory_startup:487168
used_memory_dataset:283005368
used_memory_dataset_perc:69.11%
total_system_memory:1044770816
total_system_memory_human:996.37M
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-4.0.3
lazyfree_pending_objects:0

```

---

<div class="post-metadata">

**Author:** ![fulcrum](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/fulcrum/32/14034_2.png) [@fulcrum](https://forums.docker.com/u/fulcrum)\
**Post date:** [February 6, 2018, 5:06pm UTC](https://forums.docker.com/t/redis-memory-usage/33228/3 "2018-02-06T17:06:24Z")

</div>

@roberto : Did you ever find out the problem with this? Currently I am expericing the same issue. I have a docker container memory limit of 500MB, and a redis max-memory of 150 with a maxmemory-policy of allkeys-lru so I would expect to stay well below that 500MB limit. We have however had a few containers reach that and crash.

Redis info memory shows redis not going above the threshold, however a top in the container shows a much larger redis process (I know there is overhead but 3x the size of max-memory) and ctop/docker stats shows something that doesn’t match that either.

I have upgraded to the latest redis, 4.0.7 after trying this on 3.2. My docker version is older at 1.12.1, but I see you got this with 17.04

---

<div class="post-metadata">

**Author:** ![junius](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@junius](https://forums.docker.com/u/junius)\
**Post date:** [February 7, 2018, 2:01am UTC](https://forums.docker.com/t/redis-memory-usage/33228/4 "2018-02-07T02:01:27Z")

</div>

If you are using Redis replication, the replication buffer could take like 512MB memory, and it is not included in Redis memory usage calculation. 2 refs: [redis replication buffer](https://redislabs.com/blog/top-redis-headaches-for-devops-replication-buffer), [Amazon ElasticCache Node size selection](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheNodes.SelectSize.html#CacheNodes.SelectSize.Redis).

If not using Redis replication, not sure if there are some other Redis internal data structure that consumes memory. Probably Redis github issue is a better place to ask.

---

<div class="post-metadata">

**Author:** ![roberto](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@roberto](https://forums.docker.com/u/roberto)\
**Post date:** [February 7, 2018, 3:26pm UTC](https://forums.docker.com/t/redis-memory-usage/33228/5 "2018-02-07T15:26:56Z")

</div>

Hey all,

It’s been a while since I’m thinking about this. I’m looking at a service right now and see this with the command `docker stats stack_redis.1.xxxxxxxxxxxxxxxxxxxxxxxxx`:

```auto
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
stack_redis.1.xxxxxxxxxxxxxxxxxxxxxxxxx 0.08% 23.83MiB / 64MiB 37.23% 145MB / 34.9MB 6.18MB / 6.02GB 3

```

in `top` I’m now seeing this:

```auto
  PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
 5183 docker 20 0 49696 25796 2972 S 0.0 0.3 48:54.01 redis-server

```

The discrepancy between `top` and `docker stats` is within 10% (comparing RES); then again this is a much, much smaller redis instance than the previous one.

Docker info:

```auto
aguilarr@prod-docker-5:~$ docker version
Client:
 Version: 17.09.0-ce
 API version: 1.32
 Go version: go1.8.3
 Git commit: afdb6d4
 Built: Tue Sep 26 22:42:18 2017
 OS/Arch: linux/amd64

Server:
 Version: 17.09.0-ce
 API version: 1.32 (minimum version 1.12)
 Go version: go1.8.3
 Git commit: afdb6d4
 Built: Tue Sep 26 22:40:56 2017
 OS/Arch: linux/amd64
 Experimental: false

```
