search
Homephp教程php手册启用MEMCACHE_COMPRESSED压缩,“扩容”MemCached

启用MEMCACHE_COMPRESSED压缩,“扩容”MemCached

Jun 13, 2016 am 10:34 AM
memcachememcachedcompressionCanenablestatementExpansioncopyright

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明。
http://www.chedong.com/blog/archives/001431.html

尝试:
启用了PHPmemcache_set()函数中的 MEMCACHE_COMPRESSED压缩选项,而memcache_get()可以在后续读取过程中自动对压缩的缓存对象进行解压缩。

效果:
测试了一下,对于博客大巴目前的应用来说,启用压缩后,相同的容量(2G)存储的对象数量增加了约一倍,缓存命中率从50%左右,提高到了60%左右。进一步提高命中率硬件投入还是必须的,又增加了2倍的内存后终于做到了缓存命中率提高到90%;

前提0: 内存缓存有用,且命中率值得提升;
从60%提高到90%,还是从90%提高到95%,要看hit后的性能能够提升是否值得;

前提1:MemCached已经用满
先用memcached-tool查看一下memcached的容量统计,看memcached是不是已经用满了。如果充分运行时MemCached的空间尚未用满,启用一下压缩是没有意义的; 而且:发现没有用满的MemCached,最好减少相应MemCached的容量,空余出更多内存给其他服务做缓存;

前提2: 压缩率
缓存的数据的确有大于几百字节的,如果都是小于100字节的键值对,压缩可能反而带来膨胀。由于缓存对象的大小在Memcached中都是按照固定大小分块存储的,最小也要88 B。所以对于过小数据带来的压缩膨胀并不是太大的问题;

前台应用的CPU损耗:
对数据的额外压缩CPU损耗远远低于缓存命中率提升减少后台数据库访问带来的性能提升,和http的gzip/deflate压缩类似,压缩后数据一般为原数据大小的30%左右,节省了70%的传输性能消耗所得会大于文件压缩带来的性能损耗;

以下是启用压缩后的一个MemCached的数据块分布:


# Item_Size Max_age 1MB_pages Count Full?
1 104 B 342694 s 60 604918 yes2 136 B 344213 s 39 300690 yes
3 176 B 324647 s 145 863765 yes
4 224 B 347049 s 52 243412 yes
5 280 B 332911 s 47 175968 yes
6 352 B 257080 s 114 339491 yes
7 440 B 330976 s 39 92934 yes
8 552 B 310225 s 51 96849 yes
9 696 B 305251 s 68 102407 yes
10 872 B 298607 s 74 88947 yes
11 1.1 kB 276463 s 70 66919 yes
12 1.3 kB 279819 s 79 60198 yes
13 1.7 kB 293690 s 97 59073 yes
14 2.1 kB 304436 s 116 56492 yes
15 2.6 kB 298020 s 102 39576 yes
16 3.3 kB 324546 s 100 31000 yes
17 4.1 kB 321757 s 97 24056 yes
18 5.2 kB 320132 s 91 18018 yes
19 6.4 kB 332232 s 89 14062 yes
20 8.1 kB 330696 s 81 10287 yes
21 10.1 kB 329582 s 76 7676 yes
22 12.6 kB 337278 s 72 5832 yes
23 15.8 kB 348626 s 66 4224 yes
24 19.7 kB 345881 s 56 2856 yes
25 24.6 kB 345825 s 44 1804 yes
26 30.8 kB 333460 s 31 1023 yes
27 38.5 kB 335782 s 22 572 yes
28 48.1 kB 302109 s 17 357 yes
29 60.2 kB 358674 s 18 306 yes
30 75.2 kB 396573 s 17 221 yes
31 94.0 kB 431605 s 11 110 yes
32 117.5 kB 418652 s 7 56 yes
33 146.9 kB 408422 s 3 17 no
34 183.6 kB 277529 s 2 7 no
35 229.5 kB 139156 s 1 3 no
36 286.9 kB 232221 s 1 1 no
37 358.6 kB 1059 s 3 6 yes

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.