Tuning APC Opcode Cache

APC SHM SizeThe past week I noticed errors and sometimes stalling performance of my PHP-applications. After some research I realized that the error might be related to some Linux distributions using only a small shared memory size which might cause APC to malfunction.

Changing Shared Memory Segment Size

The fix is rather easy, I have increased the shared memory size to the same value used by APC. On CentOS you can do set the by adding this to your „/etc/sysctl.conf“:

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 268435456

and make sure you set the same size in „/etc/php.d/apc.ini“

extension = apc.so
apc.enabled = 1
apc.shm_size = 256
apc.include_once_override = 1
apc.shm_segments=1
apc.ttl=3600
apc.user_ttl=3600
Selective caching

If you cannot change the shared memory segment size on your server then you should set APC nevertheless to the same value that „cat /proc/sys/kernel/shmmax“ returns and increase the number of apc.shm_segments.

Everything has been working nice since the changes have been applied.

File Cache Information
Cached Files	1047 (142.6 MBytes)
Hits	495742
Misses	1085
Request Rate (hits, misses)	15.57 cache requests/second
Hit Rate	15.55 cache requests/second
Miss Rate	0.01 cache requests/second
Insert Rate	0.01 cache requests/second
Cache full count	0

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.