Optimize APC Caching
Asked Answered
A

3

18

here is a link to how my APC is running : [removed]

As you can see, it fills up pretty quickly and my Cache Full Count goes over 1000 sometimes

My website uses Wordpress.

I notice that every time I make a new post or edit a post, 2 things happen.

1) APC Memory "USED" resets 2) I get a whole lot of Fragments

I've tried giving more Memory to APC (512 mb) but then it crashes sometimes, it seems 384 is best. I also have a Cron job that restarts apache, clearing all APC of fragments and used memory, every 4 hours. Again, my apache crashes if APC is running for a long period of time, I think due to the fragment buildup.

Should I use the apc.Filters and filter out some stuff that should not be cached?

I am really beginner at this sort of stuff, so if someone can explain with full instructions, Thank you very much !!!

Affenpinscher answered 25/8, 2010 at 20:56 Comment(0)
M
10

The APC ttl should take care of fragment build up. I usually set it at 7200. I am running it on a small VPS with WordPress and my settings are:

apc.enabled=1
apc.shm_segments=3
apc.shm_size=32
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=2048
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1
apc.max_file_size=10M

You will also get a lot more benefit from it by using WordPress's built in object cache and Mark Jaquith wrote a really good drop in plugin that should also help with some of your fragmentation issues when saving or editing a post.

Mallette answered 19/9, 2010 at 0:33 Comment(0)
K
41

I work as a Linux Systems Admin, the wordpress server runs 5 different WordPress installs. If you are running just one, I will comment the configurations to consider.

APC / PHP Versions, 3.1.9 / 5.3.7

Here is my complete apc.conf,

apc.enabled=1
apc.shm_segments=1

; I would try 32M per WP install, go from there
apc.shm_size=128M

; Relative to approx cached PHP files,
apc.num_files_hint=512

; Relative to approx WP size W/ APC Object Cache Backend, 
apc.user_entries_hint=4096

apc.ttl=7200
apc.use_request_time=1
apc.user_ttl=7200
apc.gc_ttl=3600
apc.cache_by_default=1
apc.filters
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.file_update_protection=2
apc.enable_cli=0
apc.max_file_size=2M

;This should be used when you are finished with PHP file changes.
;As you must clear the APC cache to recompile already cached files.
;If you are still developing, set this to 1.
apc.stat=0

apc.stat_ctime=0
apc.canonicalize=1
apc.write_lock=1
apc.report_autofilter=0
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600

;This MUST be 0, WP can have errors otherwise!
apc.include_once_override=0

apc.lazy_classes=0
apc.lazy_functions=0
apc.coredump_unmap=0
apc.file_md5=0
apc.preload_path

@Chris_O, your configuration is not optimal in a few aspects.

1. apc.shm_segments=3

If you run a modern Linux Distro, your SHM should be sufficiantly large enough. If it is too small search how to set sysctl.conf entries, You can check like this.

#Check Max Segment size
cat /proc/sys/kernel/shmmax

Exception when running on certain BSD's, or Other Unix's, Or managed hosts you don't control. There is disadvantages to not having a contiguous segment, read details of APC for that info.

2. apc.enable_cli=1

BAD BAD BAD, this is for debug only! Every time you run php-cli, it clears the APC cache.

3. apc.max_file_size=10M

Unnecessary and ridiculous! If you had a file that big, it would eat 1/3rd of that small 32M SHM. Even though you specify 3, they don't just act like one big segment in three pieces. Regardless WP doesn't even have single PHP files even close to that size.

'hope I helped people with their apc.conf.

Kelwunn answered 26/8, 2011 at 16:8 Comment(4)
@TechZilla, I am using Yii framework and it makes use of lazy loading of classes heavily, so should I enable apc.lazy_classes and apc.lazy_functions, can it affect anything else?Iridescence
@Uday Sawant: Lazy loading for APC is different from lazy loading in the Yii framework. Yii was written specifically in the 'lazy' manner, while with APC it is about loading 'lazy' generally. Esspecially with Yii, I would still keep those decelerations as '0'. The Manual 'lazy' loading is likely to perform best without external interference. I also want to mention those APC decelerations are still fairly new, and need more testing/stats/maturity before I would consider setting '1'.Kelwunn
@TechZilla: Thanks Bro... can you recommend any tool to benchmark these settings.Iridescence
@Uday Sawant: When I need a quick benchmark, rather than a serious Jmeter profiling, I use either ab or httperf. You can usually install ab, Apache HTTP server benchmarking tool, from your disro's repository. EL5 rpm package httpd, EL6 rpm package httpd-tools, Ubuntu/Debian Deb Package apache2-utils.Kelwunn
M
10

The APC ttl should take care of fragment build up. I usually set it at 7200. I am running it on a small VPS with WordPress and my settings are:

apc.enabled=1
apc.shm_segments=3
apc.shm_size=32
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=2048
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1
apc.max_file_size=10M

You will also get a lot more benefit from it by using WordPress's built in object cache and Mark Jaquith wrote a really good drop in plugin that should also help with some of your fragmentation issues when saving or editing a post.

Mallette answered 19/9, 2010 at 0:33 Comment(0)
T
1

You really should set apc.stat=0 on your production server and it will prevent APC from actually going to the IO to check if the file has been changed.

Check out documentation first: http://php.net/manual/en/apc.configuration.php

Thomson answered 17/10, 2010 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.