Live Blog

High Memory Usage and Swap Issues When Restarting Redis

You might receive false positives from your monitor software (monit, netdata) about about redis taking up double the amount of memory it has been configured with. Or in-general you server might be dipping into swap memory.

[EST Jan  9 14:25:01] warning  : 'redis-server' total mem amount of 3.3 GB matches resource limit [total mem amount > 1.7 GB]

Looking further reveals that two redis-server processes are spawned at some point. Digging further it looks like when Redis is saving to rdb it’s spawning a second process which stays alive enough for monit to complain.

311844:M 09 Jan 2023 14:25:00.019 * 10 changes in 300 seconds. Saving...
311844:M 09 Jan 2023 14:25:00.052 * Background saving started by pid 739360
739360:C 09 Jan 2023 14:25:06.876 * DB saved on disk
739360:C 09 Jan 2023 14:25:06.903 * RDB: 7 MB of memory used by copy-on-write
311844:M 09 Jan 2023 14:25:06.968 * Background saving terminated with success

You can read more about the RDB saving as what happens Redis persistence | Redis

If redis is restarted at a specific time that aligns with monit’s check time it’s possible that an alert can be sent out. There is the option of using AOF, which wouldn’t require a restart. You would just need to update this setting in the redis.conf file

appendonly yes

Here’s what written in the default configuration file for appendonly

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check https://redis.io/topics/persistence for more information.

Changelog

  • Corrected appenedonly usage from no to yes, changed title

Enjoyed the content? Support My Work!

I love sharing WordPress tips, tricks, and research to help the community. If you found this article helpful and want to show your appreciation, consider buying me a coffee! Your support helps keep this site running and motivates me to create more quality content. 

0 Shares: