Hi,
there is a good chance the bad fragmentation ratio is not caused by actual fragmentation,
but rather by the fact some keys are deleted while the allocator cannot give back the
memory to the system.
used_memory:6423832
used_memory_rss:15855616
used_memory_peak:21095608
Peak memory is higher than rss , so it means keys have been deleted, and at a point, more memory
was used. Actually more than 50K del operations have been done:
# Commandstats
cmdstat_del:calls=50595,usec=5774517,usec_per_call=114.13
The fragmentation ratio is just calculated as rss/used, so when rss memory is still high
because the allocator has not given unused memory back to the system, the fragmentation
ratio appears bad.
To understand the difference between internal and external fragmentation, you can have
To evaluate the internal fragmentation of the allocator, just save, restart the Redis instance,
and have a look at the fragmentation ratio with INFO.
External fragmentation can only be evaluated if the global size of your data is stable or grows.
If the volume of data is decreasing, then the ratio given by INFO is not really meaningful IMO.
With jemalloc, there is no way to force the allocator to give memory back to the system.
If you really want to optimize this, you can try tcmalloc (Redis compile time option) with
your workload and check if you can improve this behavior by tweaking the tcmalloc configuration
(TCMALLOC_RELEASE_RATE)
Regards,
Didier.