Issue
Can't seem to find an answer and benchmarks are really tale-telling.
How does Redis handle itself during peak load/usage?
The question comes from knowing CPU usage may hit 100% of its logical core, or memory may be over used.
What happens in these cases?
Solution
In general, Redis isn't CPU heavy, and will act like any other application when CPU usage is high, but this largely depends on your Redis version.
Prior to Redis 4.0, it was entirely single-threaded, and long running operations would block (like background saves, DEL's with large objects, etc.) Since 4.0, most of these types of operations are pushed to the background. With saves to disk with the bgsave
command, Redis now forks itself and does the save in the child, leaving the parent open to accept changes. 6.0 changed a few things like the del
command now acts as unlink
, and pushes the actual delete to a thread. There were some plans to add more multi-threading to Redis version 7.0, but it appears this was pushed to 7.2.
The biggest concern however is reaching max system memory, or the maxmemory
directive in Redis' config. When this happens, Redis' eviction policy comes into play (set by the maxmemory-policy
directive).
Here are the available eviction policies and what they do:
noeviction
: New values aren’t saved when memory limit is reached. When a database uses replication, this applies to the primary databaseallkeys-lru
: Keeps most recently used keys; removes least recently used (LRU) keysallkeys-lfu
: Keeps frequently used keys; removes least frequently used (LFU) keysvolatile-lru
: Removes least recently used keys with the expire field set to true.volatile-lfu
: Removes least frequently used keys with the expire field set to true.allkeys-random
: Randomly removes keys to make space for the new data added.volatile-random
: Randomly removes keys with expire field set to true.volatile-ttl
: Removes least frequently used keys with expire field set to true and the shortest remaining time-to-live (TTL) value.
The default maxmemory-policy
is noeviction
from Redis version 3.0 up through 7.0. In version 2.8 and earlier, the default is volatile-lru
.
You can read the Key Eviction docs for more.
Answered By - Adam Marshall Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.