• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

APC and caching

RobParker

Well-known member
#1
I was wondering if someone could explain how I shoud go about utilising APC for caching.

I've seen a few contradictory bits of advice so I'm a bit confused.

Will APC "just work" without doing anything or do I need to add anything to my xf config file?
 
F

Floris

Guest
#2
It will work out of the box, because just having APC on the server for PHP will mean it attempts to cache your PHP stuff. Yay.

Additionally you can optimize this for XenForo by updating your config.php file.
 

Adam Howard

Well-known member
#4
Cheers

Do you mean my APC config file or my XF one?
For your config.php

Code:
## Caching
#  http://xenforo.com/community/threads/speed-up-your-board-caching.5699/
#  http://xenforo.com/community/threads/tip-use-apc.6456/
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
                                        'caching'                      => true,
                                        'automatic_serialization'      => true,
                                        'lifetime'                      => 10800,
                                        'cache_id_prefix' => 'xf'
);
$config['cache']['backend'] = 'Apc';
I kept my cache id prefix short as to improve load and naming resolve resources. You could name it to anything really, but the shorter the better.

You shouldn't have the need to change anything in your APC config file, but if you want to try something new and have at least 2GB of ram

I found this post most useful
http://xenforo.com/community/threads/tip-use-apc.6456/page-5#post-317902
 

RobParker

Well-known member
#5
Thanks, that's what I meant about conflicting advice. Kier's post previously said APC will just work but then there's other posts like the one you quote above so I was a bit confused regarding what was really needed.

Kier said previously that: I'd like to make myself clear on this - I personally do not recommend that you use APC for shared memory caching via your config file.

Isn't that what you've just done above?
 

Adam Howard

Well-known member
#6
Thanks, that's what I meant about conflicting advice. Kier's post previously said APC will just work but then there's other posts like the one you quote above so I was a bit confused regarding what was really needed.
You're very much welcome.

So much information you feel overwhelmed. I can understand that.

The basic need is only adding it to the config.php file. The link I gave you is good if you want to take it 1 step further.

The choice is always yours. :)

(backup always before doing things though)
 

Adam Howard

Well-known member
#8
Sorry I edited my post while you were replying. Didn't Kier advise NOT to do what you suggest with the config file?
I don't think he did and if he did, in my opinion he would be wrong.

The XenForo manual suggest that you add only

Code:
$config['cache']['backend'] = 'Apc';
But also goes into detail and admits that it can (will) cause cache slams.

The code provided in my post, will work without causing any cache slams and has been used on large sites (1,000,000 post) and on my own site as well (100,000 post).
 

RobParker

Well-known member
#9
Cheers

If I want to enable Fetch public templates as files is the above configuration sufficient?

It states that:

For performance reasons, you may choose to have the public-facing side of XenForo load its templates from files rather than the database. Note that in order for this to be of benefit, you must have an opcode cache installed on your server (APC, eAccelerator, XCache etc.)
 

RobParker

Well-known member
#11
Cheers

At the minute my server load seems quite a bit higher than it used to on VB :-(

It hovered around 0.4 most of the time but on XF it's at around 1-1.5. I'm hoping this is just the fact that it's new and not yet cached locally for our visitors and should level out.

Are there any other "easy" optimisations?
 

Adam Howard

Well-known member
#13
Cheers

At the minute my server load seems quite a bit higher than it used to on VB :-(

It hovered around 0.4 most of the time but on XF it's at around 1-1.5. I'm hoping this is just the fact that it's new and not yet cached locally for our visitors and should level out.

Are there any other "easy" optimisations?
At your command prompt type the following

top

If this command is not understood, do the following

Cent OS = yum install htop

Debian or Ubuntu = aptitude install htop

Then type this command

htop

This will show you what is using so much CPU and Ram. Please report back
 

mrGTB

Well-known member
#15
For your config.php

Code:
## Caching
#  http://xenforo.com/community/threads/speed-up-your-board-caching.5699/
#  http://xenforo.com/community/threads/tip-use-apc.6456/
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
                                        'caching'                      => true,
                                        'automatic_serialization'      => true,
                                        'lifetime'                      => 10800,
                                        'cache_id_prefix' => 'xf'
);
$config['cache']['backend'] = 'Apc';
I kept my cache id prefix short as to improve load and naming resolve resources. You could name it to anything really, but the shorter the better.

You shouldn't have the need to change anything in your APC config file, but if you want to try something new and have at least 2GB of ram

I found this post most useful
http://xenforo.com/community/threads/tip-use-apc.6456/page-5#post-317902

Something I spotted, think your missing an underscore line in your prefix like so below.

'cache_id_prefix' => 'xf_'
 

RobParker

Well-known member
#16
Output from top

Screen Shot 2012-04-07 at 14.57.02.png

Most of the day the load has been around 0.8 or so but just had a bit of an increase due to traffic.

Even then we only had 500 users online (half guests) and VB was able to cope with several thousands.
 

CTXMedia

Formerly CyclingTribe
#17
Have you accounted for Google reindexing your entire site?

Also check for Baidu spider too (Chinese search engine) - I was seeing a massive spike which disappeared when I blocked Baidu (added their spider IPs to my firewall).

Just a thought ... :)
 
F

Floris

Guest
#19
Block baidu, ... because nobody cares about it except SEO spammers and chinese government.
 

RobParker

Well-known member
#20
APC is working but we seem to be getting far more cache requests than we used to and this looks a bit suspicious.

Screen Shot 2012-04-09 at 16.55.40.png

Anything to be worried about?