PHP+APC "Unable to allocate memory for pool." error
Bug #696742 reported by
Ben Alcala
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
IUS Community Project |
Fix Released
|
Undecided
|
Jeffrey Ness |
Bug Description
Latest RHEL 5.5 x86_64 PHP 5.2.16-1 and APC 3.1.6-2 RPMs are hitting this bug:
http://
apc.mmap_
apc.shm_size=64M
Triggered by Magento Community Edition and AMFphp Flash shopping cart.
To post a comment you must log in.
After much investigation I have found the cause of this APC behavior.
The cause of this behavior is related to how we have APC configured within the /etc/php.d/apc.ini:
; Enable apc extension module shm_segments= 1 optimization= 0 shm_size= 32M user_ttl= 7200 num_files_ hint=1024 mmap_file_ mask=/tmp/ apc.XXXXXX enable_ cli=1 cache_by_ default= 1
extension = apc.so
; Options for the apc module
apc.enabled=1
apc.
apc.
apc.
apc.ttl=7200
apc.
apc.
apc.
apc.
apc.
Above you will see apc.ttl is set to 7200 seconds, or 2 hours. APC's documentation says this
setting is related to each cache objects 'time to live', and when it 'can' be removed to make room for new objects:
http:// www.php. net/manual/ en/apc. configuration. php#ini. apc.ttl
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.
Leaving this at zero means that APC's cache could potentially fill up with stale entries while newer entries won't be cached.
In the event of a cache running out of available memory, the cache will be completely expunged if ttl is equal to 0. Otherwise,
if the ttl is greater than 0, APC will attempt to remove expired entries.
In all cases the server reached there apc.shm_size (set at 32M by default) long before any object hit its apc.ttl.
What this meant was APC could not remove any object to make room for new objects, and thus a APC Warning was displayed:
Warning: require_once() [function. require- once]: Unable to allocate memory for pool. in require_once()
In most cases APC was able to handle this by stepping aside and letting the PHP page be ran normally, however some cases
this would render a page unavailable, or splattered with PHP Warnings (I noticed Drupal and Magneto as the latter).
* Now for why we did not noticed this behavior in 3.0.19:
In version 3.0.19 APC did not perform a 'Allocation' check, this is new behavior in the 3.1.x branch. In previous version
APC would hit its max apc.shm_size and not cache anything further until apc.ttl was hit, and more room was made.
* The Solution:
APC has a set of 'default' settings for everything we have been explicitly settings, this can be seen at the URL below:
http:// www.php. net/manual/ en/apc. configuration. php
You will notice apc.ttl (the cause of our issues) is defaulted to 0, what this means is:
"In the event of a cache running out of available memory, the cache will be completely expunged if ttl is equal to 0"
After settings apc.ttl to 0 (or letting it default) you will need to be aware of the apc.shm_size, for most users 32M
will be plenty. However for the users that fill 32M quickly it may be come inefficient for APC to continue caching and
clearing every couple seconds/minutes, in these cases apc.shm_size will need to be raised to an amount reasonable
for that servers workload and configuration.
What I would like to do is create a generic apc.ini with all settings commented out (allowing the Default to take effect),
then 'if' any settings needs modified the user can edit the apc.ini by uncommenting the line they need.