Reputation: 48983
On PHP.net I am looking at the Memcache::set function and it has this optional flag to use compression...
Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
$memcache_obj->set('var_key',
'some really big variable',
MEMCACHE_COMPRESSED,
50);
I am curious, what would be the benefit of this, just using less space? It seems like this would slow the process down?
Upvotes: 16
Views: 6912
Reputation: 401182
Compressing and decompressing on the servers that are running PHP can be quick -- depending on your network and the load on your servers, it can be quicker than transferring more (not compressed) data to and from the memcached servers via the network.
Compressing your data also means using less memory on the memcached servers.
As often, you have to choose between CPU, network, and RAM -- and you have to take into consideration your servers and network, their load, and available resources, to be able to decide.
What will be the "quickiest" solution in your particular situation ? Only you can tell... And the only way to know is probably by testing both solutions in "real conditions".
Also, memcached entries cannot be bigger than 1 MB ; I suppose, in some ways, that compression can help put entries a bit bigger than 1 MB (when not compressed yet) into memcached.
Upvotes: 27
Reputation: 154701
You're right, it's a trade off between taking up less space or eating up more CPU cycles.
You've too choose which resource is more precious to you, RAM or CPU.
Upvotes: 4
Reputation: 3329
Upvotes: 4