問題描述
我有一個 m3.xlarge EC2 例項,我現在更新到 PHP 5.5.11 。
有了這個更新,它用 php55-pecl-apcu 覆蓋了 php55-pecl-apc 。
閱讀和實驗後,我的理解是,APC 已被 OPCache 替代,除了可以帶回 APCu 的鍵值儲存。
經過調整我的配置,看起來很合理,使用 Wordpress 登入現在是非常緩慢,至少 300-900ms 更糟糕 (前端透過清漆快取,並且工作完美… 但是當你使用管理員故意沒有快取,慢如罪) 。
當我升級時,我做了一系列的基準測試,每個步驟都有一個小樣本。當我繼續下去時,它變得越來越糟。
-
APC(升級前)
--> -
OPCache +否 APCu
--> -
用於 APCU 的 OPCache + APCu + WP 外掛
現在我剛剛和 OPCache 一起閒逛,沒有 APCu 。
-
如何達到相同的表現?我喜歡管理介面,我喜歡這麼快。我老實說看不出這是一個什麼改進,真的很令人沮喪,除非有一些我不知道的超級 Library 。這當然不是我所知道的,也可能沒有配置好。
-
假設#1 的答案是 「你配置好像球」,那麼你會介意看看這個,看看這是否合理?
對於我的設定我使用最新的 wordpress,一些大的外掛,但我不能把它們關掉,因為它們很重要。幸運的是,清漆大部分都是在工作。我的網站根目錄有 4 個核心,16GB 記憶體,〜 10k 個檔案。我也沒有真正的硬核應用程式或除 wordpress 之外的任何東西,這是一個相當的香草設定。我認為這是可能有幫助的東西。
配置:
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.max_wasted_percentage=5
opcache.use_cwd=1
opcache.validate_timestamps=1
opcache.revalidate_freq=0
opcache.revalidate_path=0
opcache.save_comments=0
opcache.load_comments=0
opcache.fast_shutdown=1
opcache.enable_file_override=0
opcache.optimization_level=0xffffffff
opcache.inherited_hack=1
opcache.dups_fix=0
opcache.blacklist_filename=/etc/php-5.5.d/opcache*.blacklist
opcache.max_file_size=2M
opcache.consistency_checks=1
opcache.force_restart_timeout=180
opcache.error_log=/var/log/php-fpm/5.5/opcache.log
opcache.log_verbosity_level=1
opcache.preferred_memory_model=
opcache.protect_memory=0
最佳解決思路
現在您正在檢查每個檔案的每個請求的更改,這可能不是你想要的生產系統。
我通常只是停用它 (請記住在進行更改後重新啟動 Web 伺服器):
opcache.validate_timestamps=0
或者,您可以嘗試將頻率設定為 0 以外的值,並保持啟用:
opcache.validate_timestamps=1
opcache.revalidate_freq=300
理論上講,這隻需要每 5 分鐘檢查一次。
次佳解決思路
你也有
opcache.consistency_checks=1
根據檔案說,這會降低效能。把它關掉
opcache.consistency_checks integerIf non-zero, OPcache will verify the cache checksum every N requests, where N is the value of this configuration directive. This should only be enabled when debugging, as it will impair performance.
第三種解決思路
從負責將 OPCache 整合到 PHP 中的 RFC:
APC can reclaim memory of old invalidated scripts. APC uses a memory manager and can reclaim memory associated with a script that is no longer in use; Optimizer+ works differently, and marks such memory as 『dirty』, but never actually reclaims it. Once the dirty percentage climbs above a configurable threshold – Optimizer+ restarts itself. Note that this behavior has both stability advantages and disadvantages.
我的猜測是,您正在觸發觸發操作碼快取重新啟動的閾值。
參考:https://wiki.php.net/rfc/optimizerplus#advantages_of_apc_over_optimizer
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。