Gzipping data sounds like an easy to implement option with huge wins
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 2991121-17.patch | 4.32 KB | berdir |
| #12 | interdiff-11-12.txt | 1.82 KB | eiriksm |
| #12 | 2991121-12.patch | 4.91 KB | eiriksm |
| #11 | interdiff.txt | 155 bytes | slasher13 |
| #11 | redis-2991121-option-to-compress-data-11.patch | 4.66 KB | slasher13 |
Comments
Comment #2
vomiand commentedSubmitting patch.
Comment #3
vomiand commentedComment #4
vomiand commentedPosting updated patch
Comment #5
vomiand commentedOne more update to fix cache invalidation
Comment #6
driki_ commentedPatch proposal to ensure we have at least 4% gain on compression
Comment #7
driki_ commentedoups sorry wrong patch
Comment #8
andypostIf compression going to be configurable I'd prefer to have igbinary
Comment #9
anish.a commentedRedis is supposed to be high performant cache. Compression is likely to slow down things way much, right? Any specific use case for this?
Comment #10
Jackinloadup commentedAmish, the ability to gzip responses can help greatly in being able to use lower priced hardware. The process of compressing and uncompressing data can speed up the overall time to transfer the large objects being passed back. I personally ran into an issue where our caching server didn't have enough bandwidth to keep up but plenty of CPU. Enabling gzip helped us push past that bottleneck without inuring more cost. I haven't reviewed recent benchmarks but there was some good material on this on the interwebs a few years ago.
Comment #11
slasher13remove patch file from patch
Comment #12
eiriksmHere are some benchmarks:
Using this script:
The script was run with drush scr, and with cold (drupal) caches, and completely flushed and restarted redis.
Without gzip:
total time: 24.938342094421ms. Total memory: 58982400
Redis memory usage: 1128M
With gzip:
total time: 26.523010015488ms. Total memory: 58982400
Redis memory usage: 148M
So the performance hit for getting and setting 100K keys, with unnatural big is so small that for general get/set you have no way of noticing. The memory savings however is huge. Or huge wins, as the OP described it.
Here is also an updated patch that fixes some coding standard errors and edge cases.
Comment #13
berdirthis shouldn't be added to the patch.
I'm not sure I like the approach.
This makes it PhpRedis specific, I'd instead suggest to make it a separate setting setting and putting directly into \Drupal\redis\Cache\CacheBase::createEntryHash.
Not sure if the 4% check is a bit overengineered, is that really worth checking? I'd rather consider increasing the length to try compressing it in the first place.
We could for example make the the setting, so Settings::get('redis_compress_minlength', 0) and if it's > 0, we compress if the length is higher. Then people can finetune it if they want to.
this and all other changes below are then not needed anymore.
Comment #14
berdirI also looked a bit into the compression level and gzcompress vs bzcompress, but it looks like gzcompress is considerably faster and doesn't make a big difference in size: https://labs.octivi.com/how-we-cut-down-memory-usage-by-82/
And based on the comment on https://www.php.net/manual/en/function.gzcompress.php, anything above the default 6 makes little difference as well and is likely not worth it.
Comment #15
berdirWorking on this.
Comment #16
andypostBtw ratio about compress/decompress makes me think about other algo support - zstd, igbinary, msgpack (they all mature last year in pecl).
Comment #17
berdirThis implements what I suggested, two settings for the length and level. Seems to work well in my own testing. It is passing tests (https://travis-ci.org/md-systems/redis/builds/642152240), I enabled it in the web test. I plan to commit this soon, but confirmation that this works from someone else would be great.
@andypost: We do support igbinary through the injected serializer, that was added for https://www.drupal.org/project/igbinary, but that didn't make it out of the experimental stage.
Comment #18
berdirCommitted, seems to work fine for us.
Comment #21
ressaThanks everyone for adding this great feature, it is indeed a huge win! And thanks @eiriksm for sharing the script. I never heard about the
drush php:scriptcommand before. But it came in handy for me today, because I wanted to check if compression was enabled ...These are the results, and I can confirm that compression is enabled by default, via the settings.redis.example.php file, and also in Valkey, which I also tested in DDEV:
I adjusted the values for these two settings:
$settings['redis_compress_length']$settings['redis_compress_level']First column = "Compression Length / Compression Level".
Valkey 8.1.4 (October 2025)
Redis 7.4.6 (July 2024)
Interestingly, there were no almost no difference between compression level 1 and 6. It could be due to the test-nodes being very uniform?
I got the memory usage (
used_memory_human) with this:$ ddev redis-cli INFO MEMORY | grep used_memory_humanPS. Archived version of the Octivi article from 2014: https://web.archive.org/web/20140313012502/https://labs.octivi.com/how-w...