when maxmemory reached, the freeMemoryIfNeeded method will invoke. On condition that maxmemory_policy == "MAXMEMORY_VOLATILE_LRU" , redis will populate evictionPool from every db and select one bestkey to evit. This strategy is inefficiency because every bestkey must invoke evictionPoolPopulate().
I have a test for dbnum is 16384 & maxmemory_samples is 5, the freeMemoryIfNeeded only free 18m memory , but cost 30 minutes !
Below is my performance analysis:
Comment From: trevor211
Having such a big dbnum is not a normal thing. But maybe we could make an effort here if it is intended to support a big number of dbs in redis singleton mode. @oranagra
Comment From: oranagra
@hongliuliao can you describe your use case for such a big number of databases? or are you just trying to take it to the edge? Redis normally designed to work with just a few databases, and even that is somewhat planned to be phased out. The maxmemory_samples is what defines how many samples to get from each db, so if you have 10 DBs, it'll sample 50 keys, if you have 50 databases, you may want to set maxmemory_samples to just one, and of course sampling one key from each dictionary would be less efficient than sampling 50 keys from one dictionary. Obviously, for 16k databases to be practical, a totally different approach should be taken, we can't afford to sample each database in every eviction cycle. but this doesn't seem like something that we would like to do, so please state your use case, maybe there's a better way to achieve it.