PHP Memcache 中的压缩有何作用?
在 PHP.net 上,我正在查看 Memcache::set 函数它有这个可选标志来使用压缩...
使用MEMCACHE_COMPRESSED来存储 项目压缩(使用 zlib)。
$memcache_obj->set('var_key',
'some really big variable',
MEMCACHE_COMPRESSED,
50);
我很好奇,如果只使用更少的空间,这样做有什么好处?看起来这会减慢进程?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在运行 PHP 的服务器上压缩和解压缩可能会很快 - 根据您的网络和服务器上的负载,它可能比从 memcached 传输更多(未压缩)数据更快通过网络的服务器。
压缩数据还意味着在 memcached 服务器上使用更少的内存。
通常,您必须在 CPU、网络和 RAM 之间进行选择,并且必须考虑您的服务器和网络、它们的负载和可用资源,才能做出决定。
在您的特定情况下,“最快”的解决方案是什么?只有您才能知道……唯一了解的方法可能是在“真实条件”下测试这两种解决方案。
另外,memcached 条目不能大于 1 MB;我认为,在某些方面,压缩可以帮助将大于 1 MB 的条目(尚未压缩时)放入 memcached 中。
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.
你是对的,这是占用更少的空间或占用更多CPU周期之间的权衡。
您也可以选择 RAM 或 CPU 哪种资源对您来说更宝贵。
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.