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

How does caching work?

Jaxel

Well-known member
#1
I installed XF1.1 today and added to my config.php:
Code:
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
    'caching'                    => true,
    'lifetime'                    => 3600,
    'cache_id_prefix'            => 'xf_'
);
$config['cache']['cacheSessions'] = true;
I have eAccelerator installed on my server... is this all I need to do? I then enabled the two options 'Minify CSS' and 'Fetch public templates as files'. These options are supposed to make my website FASTER, is that correct?

Since doing all these changes, my website is running slower than ever. The number of queries per page is indeed lower, but timings are higher. Did I do something wrong?
 

Deebs

Well-known member
#6
For both options? Even for Fetch public templates as files?
No, as long as you have an opcode cache installed then Fetch public templates as files? will get cached as they are saved as PHP files.

Here is my config:
Code:
// Setup the frontend caching system
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array('caching'  =>  true,
                                            'automatic_serialization' => true,
                                            'lifetime'    => 1800,
                                            'write_control' => true,
                                            'cache_id_prefix' => 'fh_xf_'
);
 
// Libmemcached setup
$config['cache']['backend'] = 'Libmemcached';
$config['cache']['backendOptions'] = array(
                        'servers' => array(
                                'host' => 'localhost',
                                'port' => 11211, 'persistent' => true,
                                'weight' => 1, 'timeout' => 5,
                                'retry_interval' => 15,
                                'status' => true,
                                'failure_callback' => '' ));
 
// Cache sessions in the backend
$config['cache']['cacheSessions'] = true;
 

Mikey

Well-known member
#7
this is what I have.

Code:
## Caching
#  http://xenforo.com/community/threads/speed-up-your-board-caching.5699/
#  http://xenforo.com/community/threads/tip-use-apc.6456/
$config['cache']['enabled'] = 'true';
$config['cache']['cacheSessions'] = true; // from 1.1 beta 4 onwards
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
                                       'caching'                      => true,
                                       'automatic_serialization'      => true,
                                        'lifetime'                      => 1800,
                                        'cache_id_prefix' => 'tgd_'
);
$config['cache']['backend'] = 'Apc';
 

Jaxel

Well-known member
#8
Okay... I had my host install memcache on my server... how do I confirm that it's working?

Code:
$config['enableGzip'] = false;
 
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
    'caching'                    => true,
    'lifetime'                    => 3600,
    'cache_id_prefix'            => 'xf_'
);
$config['cache']['cacheSessions'] = true;
 
$config['cache']['backend'] = 'Memcached';
$config['cache']['backendOptions'] = array(
    'compression' => false,
    'servers' => array(
        array(
            'host' => 'localhost',
            'port' => 11211,
            'persistent' => true,
            'weight' => 1,
            'timeout' => 5,
            'retry_interval' => 15,
            'status' => true,
        )
    )
);
 

Deebs

Well-known member
#9
You can telnet to 11211 from your host and then type "stats". You will see counters which will indicate whether it is working or not.
 

Jaxel

Well-known member
#10
I ran:
Code:
ps aux | grep memcached
and got back:
nobody 11474 0.2 2.3 86976 34228 ? Sl Nov24 3:34 /usr/local/bin/ memcached -u root -m 16 -p 11211 -u nobody -l 127.0.0.1
root 29988 0.0 0.0 3100 732 pts/0 S+ 16:24 0:00 grep memcached
But I have no idea what that stuff means.
 
#12
Okay... I had my host install memcache on my server... how do I confirm that it's working?

Code:
$config['enableGzip'] = false;
 
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
    'caching'                    => true,
    'lifetime'                    => 3600,
    'cache_id_prefix'            => 'xf_'
);
$config['cache']['cacheSessions'] = true;
 
$config['cache']['backend'] = 'Memcached';
$config['cache']['backendOptions'] = array(
    'compression' => false,
    'servers' => array(
        array(
            'host' => 'localhost',
            'port' => 11211,
            'persistent' => true,
            'weight' => 1,
            'timeout' => 5,
            'retry_interval' => 15,
            'status' => true,
        )
    )
);
telnet 127.0.0.1 11211
stats

memcache.png

(11211) Does this port need to be opened up externaly to the internet for this to work or is it an internal server side thing?
 

Jaxel

Well-known member
#13
STAT pid 11474
STAT uptime 113874
STAT time 1322278682
STAT version 1.4.5
STAT pointer_size 32
STAT rusage_user 37.426310
STAT rusage_system 232.231695
STAT curr_connections 15
STAT total_connections 830
STAT connection_structures 33
STAT cmd_get 6574444
STAT cmd_set 306126
STAT cmd_flush 0
STAT get_hits 6567960
STAT get_misses 6484
STAT delete_misses 2
STAT delete_hits 437
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 402779125
STAT bytes_written 136958870869
STAT limit_maxbytes 16777216
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 3992592
STAT curr_items 3077
STAT total_items 306126
STAT evictions 143483
STAT reclaimed 23644
What the hell does all that crap mean? Does that mean its working?
 
#14
STAT get_hits 6567960
STAT get_misses 6484
STAT delete_misses 2
STAT delete_hits 437

Yep looks good to me. If it wasn't working properly then you wouldn't have any hits. (y)
 

steel_curtain

Well-known member
#15
Yep you have stored items, open connections, successful requests, etc... Not a pro but I can tell you it's working. Some basics on the stats below, and you can read more here.

pid - Process id of this server process
uptime - Number of seconds this server has been running
time - current UNIX time according to the server
version - Version string of this server
pointer_size - Default size of pointers on the host OS
rusage_user - Accumulated user time for this process (seconds:microseconds)
rusage_system - Accumulated system time for this process (seconds:microseconds)
curr_items - Current number of items stored by the server
total_items - Total number of items stored by this server ever since it started
bytes - Current number of bytes used by this server to store items
curr_connections - Number of open connections
total_connections - Total number of connections opened since the server started running
connection_structures - Number of connection structures allocated by the server
cmd_get - Cumulative number of retrieval requests
cmd_set - Cumulative number of storage requests
get_hits - Number of keys that have been requested and found present
get_misses - Number of items that have been requested and not found
evictions - Number of valid items removed from cache to free memory for new items
bytes_read - Total number of bytes read by this server from network
bytes_written - Total number of bytes sent by this server to network
limit_maxbytes - Number of bytes this server is allowed to use for storage.
threads - Number of worker threads requested.
 

Deebs

Well-known member
#16
telnet 127.0.0.1 11211
stats

View attachment 21783

(11211) Does this port need to be opened up externaly to the internet for this to work or is it an internal server side thing?
Absolutely not! Keep it firewalled off from the internet. You only need to be able to access that port locally and if you have any additional servers then you need whitelist their IP addresses as well.
 
#17
Absolutely not! Keep it firewalled off from the internet. You only need to be able to access that port locally and if you have any additional servers then you need whitelist their IP addresses as well.
Guess i must refrain from doing that then. Thanks for the info Deebs. (y)
 

Deebs

Well-known member
#19
I just enabled caching and it seems to have affected the user session logout time. Is that common?
If you have enabled Session Caching and users are being logged out randomly etc then you are most likely running out of space in the cache and variables are being evicted.
 

TheBigK

Well-known member
#20
If you have enabled Session Caching and users are being logged out randomly etc then you are most likely running out of space in the cache and variables are being evicted.
I just found that caching itself works fine. If I disable caching for user sessions, then the user quicker logout problem disappears. Does it really make a lot of difference to store user sessions in cache?