После отключения APC на веб-сервере с LAMP сайты начали работать быстрее и разгрузился процессор. WTF?

Здравствуйте, коллеги и товарищи.



Имеем веб-сервер на CentOS 6.3 для хостинга ряда сайтов на Drupal (в основном, седьмой версии), куда накатан традиционный LAMP + nginx в роли обратного прокси. В качестве прекомпилера для PHP использовался APC. На сервере порядка 100 живых сайтов, высокой нагрузки — нет.



Большинство сайтов на веб-сервере появилось недавно, до этого было 5-6 сайтов и всё работало хорошо (с тем же самым APC). Но когда пришло много сайтов (при этом все новички — слабые, по 100 хостов в сутки) мы начали замечать периодические тормоза: один и тот же сайт загружался то нормально, то с затупом (и однозначно затуп воспроизвести не удавалось). Но когда сайты начали выстреливать нотисами типа Unable to allocate memory for pool... — виноватого нашли, им оказался APC (т.е., наверное, не он сам, а наши несовершенные дефолтные конфиги, но тем не менее).



Ситуация развивалась вот так:



apc-fail.png



Возня с настройками сводилась в основном к apc.shm_*, но ситуацию с нагрузкой на процессор — это не решало.



Полный конфиг на момент отключения был таков:



Конфигурация APC
# cat /etc/php.d/apc.ini <br>
; Enable apc extension module<br>
extension = apc.so<br>
<br>
; Options for the APC module version >= 3.1.3<br>
; See http://www.php.net/manual/en/apc.configuration.php<br>
<br>
; This can be set to 0 to disable APC. <br>
apc.enabled=0<br>
; The number of shared memory segments to allocate for the compiler cache. <br>
apc.shm_segments=1<br>
; The size of each shared memory segment, with M/G suffixe<br>
apc.shm_size=6144M<br>
; A "hint" about the number of distinct source files that will be included or <br>
; requested on your web server. Set to zero or omit if you are not sure;<br>
apc.num_files_hint=2048<br>
; Just like num_files_hint, a "hint" about the number of distinct user cache<br>
; variables to store.  Set to zero or omit if you are not sure;<br>
apc.user_entries_hint=4096<br>
; The number of seconds a cache entry is allowed to idle in a slot in case this<br>
; cache entry slot is needed by another entry.<br>
apc.ttl=28800<br>
; use the SAPI request start time for TTL<br>
apc.use_request_time=1<br>
; The number of seconds a user cache entry is allowed to idle in a slot in case<br>
; this cache entry slot is needed by another entry.<br>
apc.user_ttl=28800<br>
; The number of seconds that a cache entry may remain on the garbage-collection list. <br>
apc.gc_ttl=3600<br>
; On by default, but can be set to off and used in conjunction with positive<br>
; apc.filters so that files are only cached if matched by a positive filter.<br>
apc.cache_by_default=1<br>
; A comma-separated list of POSIX extended regular expressions.<br>
apc.filters =  "-(.*)\.tpl\.php$, -(.*)/apc\.php$"<br>
; The mktemp-style file_mask to pass to the mmap module <br>
apc.mmap_file_mask=/tmp/apc.XXXXXX<br>
; This file_update_protection setting puts a delay on caching brand new files.<br>
apc.file_update_protection=2<br>
; Setting this enables APC for the CLI version of PHP (Mostly for testing and debugging).<br>
apc.enable_cli=0<br>
; Prevents large files from being cached<br>
apc.max_file_size=1M<br>
; Whether to stat the main script file and the fullpath includes.<br>
apc.stat=1<br>
; Vertification with ctime will avoid problems caused by programs such as svn or rsync by making <br>
; sure inodes have not changed since the last stat. APC will normally only check mtime.<br>
apc.stat_ctime=0<br>
; Whether to canonicalize paths in stat=0 mode or fall back to stat behaviour<br>
apc.canonicalize=0<br>
; With write_lock enabled, only one process at a time will try to compile an <br>
; uncached script while the other processes will run uncached<br>
apc.write_lock=1<br>
; Logs any scripts that were automatically excluded from being cached due to early/late binding issues.<br>
apc.report_autofilter=0<br>
; RFC1867 File Upload Progress hook handler<br>
apc.rfc1867=0<br>
apc.rfc1867_prefix =upload_<br>
apc.rfc1867_name=APC_UPLOAD_PROGRESS<br>
apc.rfc1867_freq=0<br>
apc.rfc1867_ttl=3600<br>
; Optimize include_once and require_once calls and avoid the expensive system calls used.<br>
apc.include_once_override=0<br>
apc.lazy_classes=0<br>
apc.lazy_functions=0<br>
; Enables APC handling of signals, such as SIGSEGV, that write core files when signaled. <br>
; APC will attempt to unmap the shared memory segment in order to exclude it from the core file<br>
apc.coredump_unmap=0<br>
; Records a md5 hash of files. <br>
apc.file_md5=0<br>
; not documented<br>
apc.preload_path<br>


В итоге, APC деактивировали совсем. Пропали затупы сайтов, разгрузился процессор. «На глаз» мы не видим более медленной работы сайтов, а потому до выяснения обстоятельств оставили сервер совсем без акселератора.



Коллеги, поделитесь, пожалуйста, опытом по теме (можно и горьким тоже) и подскажите в какую сторону крутить конфиги APC?
  • Вопрос задан
  • 6881 просмотр
Пригласить эксперта
Ответы на вопрос 4
opium
@opium
Просто люблю качественно работать
У вас используется какое то страшно большое количество памяти для apc
apc.shm_size=6144M
мне кажется он просто дольше ищет по кешу чем отдает код.
Ответ написан
Комментировать
maxout
@maxout
Unable to allocate memory for pool — вы в багзилле их покопайтесь, тысячи их. Я отчаялся заставить APC работать нормально в продакшне, использую eAccelerator и XCache. Рекомендую взять свеженький XCache.
Ответ написан
@egorinsk
PHP-акселераторы страдают ошибками. Это вам еще повезло, если он только память ел, бывает, процесс PHP падает с случайной вероятностью и не догадаешься, что виноват оп-кешер.
Ответ написан
UncleByte
@UncleByte
Так он на момент «отключения» уже был отключен?
; This can be set to 0 to disable APC. 
apc.enabled=0

Или все-таки был включен с тем бешеным количеством памяти из конфига?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы