krakjoe / apcu

APCu - APC User Cache
Other
957 stars 193 forks source link

[Discussion] serializer vs compressor #403

Open remicollet opened 3 years ago

remicollet commented 3 years ago

APCu have a nice support for configurable serializer.

I see some extension (brotli, lz4...) start to use it for compression

IMHO serialization (struct to string) is very different from compression (string to string)

It could be nice to duplicate the mechanism for compression, and manage this properly

What do you think ?

Ping @kjdev

nikic commented 3 years ago

So the suggestion is to store compressed serialized data inside the apcu cache?

remicollet commented 3 years ago

yes (even if performance will be lower), this is what is done when you use apc.serializer = lz4

remicollet commented 3 years ago

See https://github.com/kjdev/php-ext-lz4/blob/master/lz4.c#L362

remicollet commented 3 years ago

yac have build-in copmpression by default

redis have support for configurable compressor

$ php --ri redis
...
Available serializers => php, json, igbinary, msgpack
Available compression => lzf, zstd, lz4
...

IMHO, compression make more sense for network cache than for fast local in memory cache.

TysonAndre commented 3 years ago

I see some extension (brotli, lz4...) start to use it for compression

I looked up what apcu was doing because I noticed today that zstd (by the same compression library author) created a release today that also added support for storing the equivalent of \zstd_compress(\serialize($data)) for objects/arrays in apcu - https://pecl.php.net/package-info.php?package=zstd&version=0.10.0 (I haven't used that and my own use cases for apcu don't require much memory, and I don't plan to use it for my own use cases)

But if a use case was memory intensive it would help to use both a compression algorithm (possibly just for objects/arrays to get the speedup for reusing persistent strings) and igbinary/msgpack for the cpu speed and memory reduction - --enable-mycompressor-apcu-igbinary and the module dependency is less than ideal for users or packagers of extensions.