我最近在網站服務器(Centos 5.7,PHP 5.3,1.5GB內存)上安裝並激活了APC緩存,主要用於中等流量(30k獨立訪客/月)WordPress網站的運行設置爲使用APC進行數據庫和對象緩存的W3Total緩存(頁面,縮小使用磁盤)。WordPress站點上的APC緩存碎片
服務器的APC信息頁面顯示存在始終嚴重的碎片。例如,在重新啓動httpd後,11小時後碎片率高達75%,幾天後我已經看到它爲100%。在任何時候,我都沒有看到使用超過40%的高速緩存,服務器一直運行在大約400Mb的內存,1100Mb空閒( -/+緩衝區/緩存,由free -m報告)。所以它似乎沒有導致碎片的內存不足。
我開始使用默認的APC和W3TC配置,並且已經嘗試的以下變化的各種組合: -
- apc.ttl減少到1800(從7200)
- apc.user_ttl設置爲0 (使用用戶的高速緩存的唯一事情是W3TC並設置其自己的TTL)
- W3TC超時從180到7200秒增加
- apc.filters到方框timthumb
儘管到目前爲止,Google網站管理員工具所測量的主觀性能和頁面加載時間似乎沒有受到任何影響,但這些更改似乎沒有太大差別。
我應該爲此擔心嗎?雖然目前的表現不是,但我寧願在服務器負載/站點流量上升之前進行排序。如果擔心,我可以採取哪些措施來解決?
編輯: - 下面是完整的apc.ini配置文件: -
; Enable apc extension module
extension = apc.so
; Options for the APC module version >= 3.1.3
; See http://www.php.net/manual/en/apc.configuration.php
; This can be set to 0 to disable APC.
apc.enabled=1
; The number of shared memory segments to allocate for the compiler cache.
apc.shm_segments=1
; The size of each shared memory segment, with M/G suffixe
apc.shm_size=256M
; A "hint" about the number of distinct source files that will be included or
; requested on your web server. Set to zero or omit if you're not sure;
apc.num_files_hint=1024
; Just like num_files_hint, a "hint" about the number of distinct user cache
; variables to store. Set to zero or omit if you're not sure;
apc.user_entries_hint=4096
; The number of seconds a cache entry is allowed to idle in a slot in case this
; cache entry slot is needed by another entry.
apc.ttl=7200
; use the SAPI request start time for TTL
apc.use_request_time=1
; The number of seconds a user cache entry is allowed to idle in a slot in case
; this cache entry slot is needed by another entry.
apc.user_ttl=0
; The number of seconds that a cache entry may remain on the garbage-collection list.
apc.gc_ttl=3600
; On by default, but can be set to off and used in conjunction with positive
; apc.filters so that files are only cached if matched by a positive filter.
apc.cache_by_default=1
; A comma-separated list of POSIX extended regular expressions.
apc.filters="-.[omitted]/timthumb.php$"
; The mktemp-style file_mask to pass to the mmap module
apc.mmap_file_mask=/tmp/apc.XXXXXX
; This file_update_protection setting puts a delay on caching brand new files.
apc.file_update_protection=2
; Setting this enables APC for the CLI version of PHP (Mostly for testing and debugging).
apc.enable_cli=0
; Prevents large files from being cached
apc.max_file_size=1M
; Whether to stat the main script file and the fullpath includes.
apc.stat=1
; Vertification with ctime will avoid problems caused by programs such as svn or rsync by making
; sure inodes havn't changed since the last stat. APC will normally only check mtime.
apc.stat_ctime=0
; Whether to canonicalize paths in stat=0 mode or fall back to stat behaviour
apc.canonicalize=0
; With write_lock enabled, only one process at a time will try to compile an
; uncached script while the other processes will run uncached
apc.write_lock=1
; Logs any scripts that were automatically excluded from being cached due to early/late binding issues.
apc.report_autofilter=0
; RFC1867 File Upload Progress hook handler
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
; Optimize include_once and require_once calls and avoid the expensive system calls used.
apc.include_once_override=0
apc.lazy_classes=0
apc.lazy_functions=0
; Enables APC handling of signals, such as SIGSEGV, that write core files when signaled.
; APC will attempt to unmap the shared memory segment in order to exclude it from the core file
apc.coredump_unmap=0
; Records a md5 hash of files.
apc.file_md5=0
; not documented
apc.preload_path
UPDATE我也posted on WP forums並得到了W3TotalCache筆者這樣的響應: -
那次經歷在某些網站上並不出乎意料。我將在下一個版本中研究 緩存邏輯以提高APC性能。
所以好像W3TotalCache是碎片的根本原因。
我只有1段(apc.shm_segments = 1),它是256M(apc.shm_size = 256M)。也許我是誤解,但是由於我從未見過超過40%的內存使用,如何增加分段大小會有所幫助? – rowatt 2012-02-15 17:11:50
您正在使用哪個版本的APC? – 2012-02-16 09:25:47
3.1.9(和PHP 5.3.10) – rowatt 2012-02-16 09:52:19