Redis - memory usage monitoring

I am currently testing key insertion into a Redis database (on local). I have over 5 million keys, and I only have 4 GB of RAM, so at one point I get to the amount of RAM and swap filling (and my computer shuts down) ...

My problem: how can I make use of control memory on a computer with a Redis database, and so the warning no longer inserts some keys into the Redis database?

Thanks.

+7
source share
3 answers

Regarding memory usage, I would advise you to take a look at the redis.io FAQ and this article about using redis as an LRU cache .

You can either limit memory usage using the maxmemory configuration parameter, and in this case, as soon as the memory limit is reached, all write requests will fail with an error or you can set the maxmemory policy for allkeys-lru, for example, start overwriting the least recently used data on the server with the materials you need, etc. For most use cases, you have enough flexibility to solve such problems with a proper configuration.

My advice is to simplify the task and solve this problem using the redis server configuration, and not introduce additional complexity by monitoring the os level, etc.

+4
source

There is a good Unix utility called vmstat. This is similar to the top, but command line, so you can get memory usage and be prepared before the system stops. You can also use ps v PID to get information about a specific process. Redis PID can be found as follows: pidof redis-server

+4
source

Memory is a critical resource for Redis to work. The memory used determines the total number of bytes allocated to Redis using its allocator (standard libc, jemalloc, or an alternative allocator such as tcmalloc).

You can collect all memory usage data for a Redis instance by running "information memory".

 
 127.0.0.1:6379> info memory
 Memory
 used_memory: 1007280
 used_memory_human: 983.67K
 used_memory_rss: 2002944
 used_memory_rss_human: 1.91M
 used_memory_peak: 1008128
 used_memory_peak_human: 984.50K

Sometimes, when Redis is configured without limiting maximum memory, memory usage will eventually reach system memory and the server will start throwing out of memory errors. In other cases, Redis is configured with a maximum memory limit, but without a search policy. This will result in the server not crowding out any keys, thereby preventing any writes until the memory is freed. The solution to such problems will be to configure Redis with maximum memory and some eviction policy. In this case, the server begins to supplant the keys using the eviction policy, as memory usage reaches its maximum.

RSS feed (resident set size) is the number of bytes allocated by the Redis operating system. If the ratio "memory_rss to" memory_used is greater than ~ 1.5, then this means memory fragmentation. Fragmented memory can be restored by restarting the server.

Learn more about tracking redis server here.

+1
source

All Articles