Biggest APC Configuration mistake


I’ve searched for Best APC Configuration on the net and applied it to my server. But later on I’ve stumbled to a problem. My Virtual server started getting slower.

Best APC Configuration

I’ve stumbled to the article by Greg Rickaby titled The Perfect APC Configuration which worked very good for me.

Here is my APC configuration:

apc.enabled=1
apc.shm_segments=1

;32M per WordPress install
apc.shm_size=256

;Relative to the number of cached files (you may need to watch your stats for a day or two to find out a good number)
apc.num_files_hint=7000

;Relative to the size of WordPress
apc.user_entries_hint=4096

;The number of seconds a cache entry is allowed to idle in a slot before APC dumps the cache
apc.ttl=7200
apc.user_ttl=7200
apc.gc_ttl=3600

;Setting this to 0 will give you the best performance, as APC will
;not have to check the IO for changes. However, you must clear 
;the APC cache to recompile already cached files. If you are still
;developing, updating your site daily in WP-ADMIN, and running W3TC
;set this to 1
apc.stat=1

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

;Only set to 1 while debugging
apc.enable_cli=0

;Allow 2 seconds after a file is created before it is cached to prevent users from seeing half-written/weird pages
apc.file_update_protection=2

;Leave at 2M or lower. WordPress does't have any file sizes close to 2M
apc.max_file_size=2M

apc.cache_by_default=1
apc.use_request_time=1
apc.slam_defense=0
apc.mmap_file_mask=/tmp/apc/apc.XXXXXX
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
apc.lazy_classes=0
apc.lazy_functions=0

There are just a few modifications to the APC configuration from the one that Greg’s posted.

Changed the APC size to 256MB and removed the M at the end because my version of APC was crashing with it: apc.shm_size=256

And now the biggest problem, I’ve changed the mmap file mask to /tmp/apc folder apc.mmap_file_mask=/tmp/apc/apc.XXXXXX

Also there are some suggestions that apc.stat should be set to 0 on production servers, but as explained there are some suggestions from W3TC and also i had problems logging in on the OpenX admin interface. I have mine set to enabled 1.

Why there is a problem

When running Virtual Machines your biggest problem will be disk IO, so running cache on disk is not a good idea.

After installing APC on my machine I’ve noticed high disk usage under load. Using iotop showed disk usage by [flush-8:0] and my Apache user which directed me to the problem.

Solving the problem

I’ve moved apc.shm_size to a tmpfs 

mkdir /tmp/apc

Edit your /etc/fstab file

vi /etc/fstab

Append the following

tmpfs /tmp/apc tmpfs size=256M 0 0

Mount the partition

mount /tmp/apc

With this I’ve alocated 256MB of RAM to be used for APC Memory Mapping. After this changes the Disk IO was back to normal and the website load was amazing.

If you have any suggestions let me know. But for now this configuration works for me.



Subscribe
Notify of
guest
9 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Enrique
Enrique
11 years ago

Hello,

nice post and I have got a question

why do you allocate 1000M of ram if your apc.shm_size=256 ?

Thanks

nstojanoski
nstojanoski
11 years ago
Reply to  Enrique

Sorry for over-allocating in the example, I’ve edited the post.
I was using more ram on my install.

Regards

KS
KS
10 years ago

I think you should have just left apc.mmap_file_mask at where it was (=default). apc.ini says: Leaving it undefined will force an anonymous mmap. = no file-based cache. And that’s what I see here.

Anonymous
Anonymous
10 years ago

Many many thanks to you! Moving APC mmap to TMPFS lowered disk utilization twice. Yeeehaaa!!!

David Hansel
David Hansel
10 years ago

Nice post!
May I know what is your consideration to set the shm_size to 256? May I know how big is your VPS ram? I tried to tune up my apc setting. Whenever I tried to push the load to 50 concurent users access at the same time, the server will memory will overload never release the memory usage.

Communitatem Mediatorem
Communitatem Mediatorem
9 years ago

Hello!
Thanks for contribution. However, for me the post is a bit misleading, because all info about APC around the net states that APC uses RAM memory not disk. So can you elaboarate on the reasons why do you explicitly move apc file on RAM.
Is it an APC architecture mistake ..or… ?
BR..

Hernawan Id
9 years ago

i have set it, btw how to check the performance of apc?

travisbotello
travisbotello
8 years ago

Hey guys, I am having a problem with APC and APCIterator class in general. I am using APCIterator to retrieve certain items and hand it over to apc_delete($iterator) without having to flush the whole cache. My problem is the following: Once I created these items I can easily retrieve them using APCIterator, but after a certain amount amount of the time certain items can’t be retrieved by APCIterator anymore, they are stuck in cache and APCIterator is empty…I have absolutely no clue why and how this is happening. Maybe my APC settings?? Here is a more detailed explanation of my… Read more »

nstojanoski
nstojanoski
8 years ago
Reply to  travisbotello

I don’t know if I’m pointing you to a right direction, but there i a ttl value for the items, you should check if value exists and retrieve it, if it doesn’t exists recreate it in cache

Every read should be: check if value is in cache, if it’s now create it, next time check if it’s in cache if it is get it, if not create it again.

Regards,

Advertisement