简体   繁体   English

APC缓存碎片(无尽的困境)

[英]APC cache fragmentation (endless dilemma)

It's a frequently asked question , I know. 我知道这是一个 经常 被问到的 问题 But I tried every solution suggested (apc.stat=0, increasing shared memory, etc) without benefits. 但是我尝试了所有建议的解决方案(apc.stat = 0,增加共享内存等),但没有任何好处。

Here's the screen with stats (you can see nginx and php5-fpm) and the parameters set in apc.ini: 这是带有统计信息的屏幕(您可以看到nginx和php5-fpm)以及apc.ini中设置的参数:

APC统计页面

APC is used for system and user-cache entries on multiple sites (8-9 WordPress sites and one with MediaWiki and SMF). APC用于多个站点(8-9个WordPress站点以及一个带有MediaWiki和SMF的站点)上的系统和用户缓存条目。

What would you suggest? 你有什么建议?

Each wordpress site is is going to cache a healthy amount in the user cache. 每个wordpress网站都将在用户缓存中缓存正常数量。 I've looked at this myself in depth and have found the best 'guesstimate' is that if you use user cache in APC keep the fragmentation under 10%. 我本人对此进行了深入研究,发现最好的“猜测”是,如果在APC中使用用户缓存,则将碎片保持在10%以下。 This can sometimes mean you need to try and reserve upwards of 10x the amount of memory you intend to actually use for caching to avoid fragmentation. 有时这可能意味着您需要尝试将打算实际用于缓存的内存增加10倍以上,以避免碎片。 Start where you are and keep increasing memory allocated until fragmentation stays below 10% after running a while. 从您所在的位置开始,并继续增加分配的内存,直到运行一段时间后碎片保持在10%以下。

BTW: wordpress pages being cached are huge, so you'll probably need a lot of memory to avoid fragmentation. 顺便说一句:缓存的wordpress页面很大,因此您可能需要大量内存来避免碎片。

Why 10% fragmentation? 为什么会有10%的碎片化? It's a bit of a black art, but I observed this is where performance start to noticeabily decline. 这有点荒唐,但是我观察到这是性能开始明显下降的地方。 I haven't found any good benchmarks (or run my own controlled tests) however. 但是我没有找到任何好的基准(或运行自己的受控测试)。

This 10x amount to get this my seem insane, but root cause is APC has no way to defragment other than a restart (which completely dumps the cache). 这个10倍的数量让我看起来很疯狂,但是根本原因是APC除了重新启动(完全转储缓存)之外没有其他方法来进行碎片整理。 Having a slab of 1G of memory when you only plan to use 100-200m gives a lot of space to fill without having to look for 'holes' to put stuff. 当您仅打算使用100-200m时,只有1G的内存就可以提供很多空间来填充,而不必寻找“空洞”来放置东西。 Think about bad old FAT16 or FAT32 disk performance with Windows 98--constant need to manually defrag as the disk gets over 50% full. 考虑一下Windows 98上旧的FAT16或FAT32磁盘性能不好的情况-当磁盘的容量超过50%时,经常需要手动进行碎片整理。

If you can't afford the extra memory to spare, you might want to look at either memcached or plain old file caching for your user cache. 如果您无法负担额外的可用内存,则可能需要查看memcached或普通的旧文件缓存作为用户缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM