APC缓存碎片问题

发布于 2024-09-26 11:44:50 字数 1076 浏览 4 评论 0原文

我在 CentOS 服务器 5 上运行 APC(php 缓存)(每天 13 000 次访问),运行 php 5.3.3、APC 3.1.4 和 4Gb RAM。在过去的几周里,我在日志中遇到了许多“无法为池分配内存”错误,并且网站经常出现故障。

我认为问题出在APC上。从统计数据来看,一两个小时后缓存就满了,而且碎片总是跳到 100%。这是我的 apc.ini 配置设置:

apc.cache_by_default    1
apc.canonicalize    0
apc.coredump_unmap  0
apc.enable_cli  0
apc.enabled 1
apc.file_md5    0
apc.file_update_protection  2
apc.filters 
apc.gc_ttl  3600
apc.include_once_override   0
apc.lazy_classes    00
apc.lazy_functions  0
apc.max_file_size   1M
apc.mmap_file_mask  /dev/zero
apc.num_files_hint  0
apc.preload_path    
apc.report_autofilter   0
apc.rfc1867 0
apc.rfc1867_freq    0
apc.rfc1867_name    APC_UPLOAD_PROGRESS
apc.rfc1867_prefix  upload_
apc.rfc1867_ttl 3600
apc.shm_segments    1
apc.shm_size    512M
apc.slam_defense    1
apc.stat    1
apc.stat_ctime  0
apc.ttl 7200
apc.use_request_time    1
apc.user_entries_hint   0
apc.user_ttl    7200
apc.write_lock  1

从 APC 统计数据中我可以看到缓存文件的数量非常高(40 000),这是由于 phpbb 和 mediawiki 的缓存文件过多所致。我是否必须使用 apc.filters 阻止 APC 缓存此文件?问题有解决办法吗?

I'm running APC (php cache) on a medium website (13 000 visits a day) on a CentOS server 5 running php 5.3.3 with APC 3.1.4 with 4Gb of RAM. In the last weeks I'm experiencing many "unable to allocate memory for pool" errors in logs, and often the site goes down.

I think the problem is in APC. From the stats I see that the cache is full after an hour or two, and the fragmentation always jumps to 100%. This are my config settings of apc.ini:

apc.cache_by_default    1
apc.canonicalize    0
apc.coredump_unmap  0
apc.enable_cli  0
apc.enabled 1
apc.file_md5    0
apc.file_update_protection  2
apc.filters 
apc.gc_ttl  3600
apc.include_once_override   0
apc.lazy_classes    00
apc.lazy_functions  0
apc.max_file_size   1M
apc.mmap_file_mask  /dev/zero
apc.num_files_hint  0
apc.preload_path    
apc.report_autofilter   0
apc.rfc1867 0
apc.rfc1867_freq    0
apc.rfc1867_name    APC_UPLOAD_PROGRESS
apc.rfc1867_prefix  upload_
apc.rfc1867_ttl 3600
apc.shm_segments    1
apc.shm_size    512M
apc.slam_defense    1
apc.stat    1
apc.stat_ctime  0
apc.ttl 7200
apc.use_request_time    1
apc.user_entries_hint   0
apc.user_ttl    7200
apc.write_lock  1

From APC stats I can see that the number of cached files is very high (40 000), and this is due to the plethora of cache files of phpbb and mediawiki. Do I have to prevent APC caching this files using apc.filters? Are there solutions to the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘年祭陌 2024-10-03 11:44:50

您确实应该在生产服务器上设置 apc.stat=0 ,这将阻止 APC 实际访问 IO 检查文件是否已更改。

还要设置 apc.slam_defense=0,因为它已被弃用

查看其他选项的文档: http:// php.net/manual/en/apc.configuration.php

You really should set apc.stat=0 on your production server and it will prevent APC from actually going to the IO to check if the file has been changed.

also set apc.slam_defense=0 as it's deprecated

Check out documentation for other options: http://php.net/manual/en/apc.configuration.php

┊风居住的梦幻卍 2024-10-03 11:44:50

我认为你应该为文件支持的 mmap 设置 apc.mmap_file_mask = /tmp/apc-yourusernamehere.XXXXXX ;通过添加您的唯一字符串使文件掩码唯一; XXXXXX(正好是 6 个 X)必须保留,以允许 APC 添加随机字符串,或者如果您可以节省内存,则将匿名 mmap 设置为 /dev/zero。

我可以看到您正在使用 /dev/zero ,这不必要地占用了内存。

I think you should set apc.mmap_file_mask = /tmp/apc-yourusernamehere.XXXXXX for file-backed mmap; make file mask unique by adding your unique string; XXXXXX (exactly 6 X’s) must remain to allow APC to add random string OR set to /dev/zero for anonymous mmap if you can spare the memory.

I can see that you are using /dev/zero which takes memory unnecessarily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文