2011/05/09 21:14
文章作者:Enjoy 转载请注明原文链接。
使用setCompressThreshold,设置为超过2000字节,则压缩,压缩比例为0.2。
$mem->setCompressThreshold(2000,0.2);
$mem->set('test_mem',$arrs,0,720);
发现实际存储了902个字节。
将0.2放大,一直放大到0.7,都是存902个字节。
放大到0.8后,就是存4132个字节
不设置setCompressThreshold存储,也是存4132字节。
再设一下$arrs的长度为2643,0.2压缩时为627字节,不压缩时为2703字节。
压缩和不压缩存储的字节数还是差不少的!
文档中写:
引用
bool Memcache::setCompressThreshold ( int threshold [, float min_savings] )
threshold : Controls the minimum value length before attempting to compress automatically.
min_saving : Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings.
threshold : Controls the minimum value length before attempting to compress automatically.
min_saving : Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings.
具体的压缩比例还是要看存储的实际内容。
如果是简单的数字组成的数组,压缩比例可能可以压到7%。
实际:1008900字节,写入1008963字节,压缩后,实际写入才69948字节。
如果是一百多篇文章内容组成的数组,压纹比例可能也就40%多。
实际:1040730字节,压缩后,写入420165字节。
另外,不管有没有设置setCompressThreshold,取出时都无需设置,$mem->get会自动判断取出来的数据是否有压缩过,压缩过则解压,没压缩过则直接输出。
之后,再测试了下memcached的压缩情况,和memcache的压缩不是完全一样,都需要多存1字节,但几乎可以认为压缩比是一模样的。
引用
Memcached::OPT_COMPRESSION
开启或关闭压缩功能。当开启的时候,item的值超过某个阈值(当前是100bytes)时,会首先对值进行压缩然后存储,并 在获取该值时进行解压缩然后返回,使得压缩对应用层透明。 类型: boolean, 默认: TRUE.
开启或关闭压缩功能。当开启的时候,item的值超过某个阈值(当前是100bytes)时,会首先对值进行压缩然后存储,并 在获取该值时进行解压缩然后返回,使得压缩对应用层透明。 类型: boolean, 默认: TRUE.
memcached默认就开启压缩,因此代码中无需设置。
实际字节 mc存储 mc压缩存储 mcd存储
1008900 1008963 69948 69949
1040730 1040793 420097 420098
6207 6267 1253 1254
1000000 1000063 2025 2026

ssh登录linux服务器过程中密码验证很慢的解决办法
nginx1.0.0配ngx_cache_purge实现高效的反向代理

