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

my experience with cache (file, xcache, apc)

jacko

Well-known member
#1
For years I had been using shared hosting. On my recent host I noticed that Xenforo site is working slower when I enable file based cache. In the recent weeks I moved the site to VPS and I noticed the same unusual behaviour. Similarily, enabling APC or Xcache in config.php is making the site a bit slower. With both Xcache and APC I noticed that the site got siginificantly quicker just after installing and running either of them on the server, without configuring cache in config.php. Perhaps there are some server settings that I should take care of? Currently I'm running Xcache and Xenforo is being cached nicely without the cache being configured in Xenforo's config.php. I'm going to leave it at that.
 

Adam Howard

Well-known member
#2
You want real speed.... xcache with opcache ... You'll never want anything else.

I tried this combination and a few people had never thought of it. So 2 other people here thought to give it a try and they seem pleased.
 

MattW

Well-known member
#3
For years I had been using shared hosting. On my recent host I noticed that Xenforo site is working slower when I enable file based cache. In the recent weeks I moved the site to VPS and I noticed the same unusual behaviour. Similarily, enabling APC or Xcache in config.php is making the site a bit slower. With both Xcache and APC I noticed that the site got siginificantly quicker just after installing and running either of them on the server, without configuring cache in config.php. Perhaps there are some server settings that I should take care of? Currently I'm running Xcache and Xenforo is being cached nicely without the cache being configured in Xenforo's config.php. I'm going to leave it at that.
That is because Xcache and APC will be performing opcode caching, which doesn't require anything specific to be set in the XenForo config file. You can however, set the Performance option to Fetch public templates as files
 

Adam Howard

Well-known member
#5
how that can be set up?
This is what I have in my config.php

PHP:
// System Cache
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions']['cache_id_prefix'] = 'su_';
// Session Cache
$config['cache']['cacheSessions'] = true;
// Backend Cache
$config['cache']['backend'] = 'xcache';
I simply install php5-opcode and php5-xcache

This is the value I have in xcache.ini
PHP:
; configuration for php Xcache module

[xcache-common]
;; non-Windows example:
extension = xcache.so
;; Windows example:
; extension = php_xcache.dll

[xcache.admin]
xcache.admin.enable_auth = On
; Configure this to use admin pages
; xcache.admin.user = "mOo"
; xcache.admin.pass = md5($your_password)
; xcache.admin.pass = ""

[xcache]
; ini only settings, all the values here is default unless explained

; select low level shm implemenation
xcache.shm_scheme =        "mmap"
; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
xcache.size  =               60M
; set to cpu count (cat /proc/cpuinfo |grep -c processor)
xcache.count =                 1
; just a hash hints, you can always store count(items) > slots
xcache.slots =                8K
; ttl of the cache item, 0=forever
xcache.ttl   =                 0
; interval of gc scanning expired items, 0=no scan, other values is in seconds
xcache.gc_interval =           0

; same as aboves but for variable cache
xcache.var_size  =            4M
xcache.var_count =             1
xcache.var_slots =            8K
; default value for $ttl parameter of xcache_*() functions
xcache.var_ttl   =             0
; hard limit ttl that cannot be exceed by xcache_*() functions. 0=unlimited
xcache.var_maxttl   =          0
xcache.var_gc_interval =     300

; mode:0, const string specified by xcache.var_namespace
; mode:1, $_SERVER[xcache.var_namespace]
; mode:2, uid or gid (specified by xcache.var_namespace)
xcache.var_namespace_mode =    0
xcache.var_namespace =        ""

; N/A for /dev/zero
xcache.readonly_protection = Off
; for *nix, xcache.mmap_path is a file path, not directory. (auto create/overwrite)
; Use something like "/tmp/xcache" instead of "/dev/*" if you want to turn on ReadonlyProtection
; different process group of php won't share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path
xcache.mmap_path =    "/dev/zero"


; Useful when XCache crash. leave it blank(disabled) or "/tmp/phpcore/" (writable by php)
xcache.coredump_directory =   ""
; Windows only. leave it as 0 (default) until you're told by XCache dev
xcache.coredump_type =         0

; disable cache after crash
xcache.disable_on_crash =    Off

; enable experimental documented features for each release if available
xcache.experimental =        Off

; per request settings. can ini_set, .htaccess etc
xcache.cacher =               On
xcache.stat   =               On
xcache.optimizer =           Off

[xcache.coverager]
; enabling this feature will impact performance
; enabled only if xcache.coverager == On && xcache.coveragedump_directory == "non-empty-value"

; per request settings. can ini_set, .htaccess etc
; enable coverage data collecting and xcache_coverager_start/stop/get/clean() functions
xcache.coverager =          Off
xcache.coverager_autostart =  On

; set in php ini file only
; make sure it's readable (open_basedir is checked) by coverage viewer script
xcache.coveragedump_directory = ""
This is the value I use in opcache.ini
PHP:
; configuration for php ZendOpcache module
; priority=05
zend_extension=opcache.so
opcache.enable=1
opcache.memory_consumption=512
opcache.interned_strings_buffer=8
opcache.max_wasted_percentage=5
opcache.max_accelerated_files=8000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=0
opcache.save_comments=1
opcache.enable_file_override=1
opcache.validate_timestamps=1
And pay special attention to this in php.ini and the php.ini in /etc/php5/cli
PHP:
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1

; The OPcache shared memory storage size.
opcache.memory_consumption=256

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=8000

; The maximum percentage of "wasted" memory until a restart is scheduled.
opcache.max_wasted_percentage=5

; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thus eliminating possible collisions between
; files with the same name (basename). Disabling the directive improves
; performance, but may break existing applications.
;opcache.use_cwd=1

; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
opcache.validate_timestamps=1

; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
opcache.revalidate_freq=60

; Enables or disables file search in include_path optimization
;opcache.revalidate_path=0

; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
opcache.save_comments=1

; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments"
; may be always stored (save_comments=1), but not loaded by applications
; that don't need them anyway.
;opcache.load_comments=1

; If enabled, a fast shutdown sequence is used for the accelerated code
;opcache.fast_shutdown=0

; Allow file existence override (file_exists, etc.) performance feature.
opcache.enable_file_override=1

; A bitmask, where each bit enables or disables the appropriate OPcache
; passes
;opcache.optimization_level=0xffffffff

;opcache.inherited_hack=1
;opcache.dups_fix=0

; The location of the OPcache blacklist file (wildcards allowed).
; Each OPcache blacklist file is a text file that holds the names of files
; that should not be accelerated. The file format is to add each filename
; to a new line. The filename may be a full path or just a file prefix
; (i.e., /var/www/x  blacklists all the files and directories in /var/www
; that start with 'x'). Line starting with a ; are ignored (comments).
;opcache.blacklist_filename=

; Allows exclusion of large files from being cached. By default all files
; are cached.
;opcache.max_file_size=0

; Check the cache checksum each N requests.
; The default value of "0" means that the checks are disabled.
;opcache.consistency_checks=0

; How long to wait (in seconds) for a scheduled restart to begin if the cache
; is not being accessed.
;opcache.force_restart_timeout=180

; OPcache error_log file name. Empty string assumes "stderr".
;opcache.error_log=

; All OPcache errors go to the Web server log.
; By default, only fatal errors (level 0) or errors (level 1) are logged.
; You can also enable warnings (level 2), info messages (level 3) or
; debug messages (level 4).
;opcache.log_verbosity_level=1

; Preferred Shared Memory back-end. Leave empty and let the system decide.
;opcache.preferred_memory_model=

; Protect the shared memory from unexpected writing during script execution.
; Useful for internal debugging only.
;opcache.protect_memory=0
 

jacko

Well-known member
#7
Done. Zend Opcache installed. So far I see that Xcache has hundreds hits, but Opcache is showing 0 hits. Any idea why?
 

jacko

Well-known member
#8
Still, site is a touch faster if I don't set cache in config.php file. Xenforo is nicely using Xcache anyway (up to hundreds of hits per second). I don't know if Opcache has made any difference. It caches Xenforo, but there are zero cache hits.
 

jacko

Well-known member
#9
I disabled Xcache and now Opcache is getting hits! :)
Apparently having both doesn't help (only Xcache is getting hits). Opcache is supposed to be faster. Let's see.
 

Tracy Perry

Well-known member
#10
I disabled Xcache and now Opcache is getting hits! :)
Apparently having both doesn't help (only Xcache is getting hits). Opcache is supposed to be faster. Let's see.
If I had to choose between the two I'd kick xCache to the curb in a heartbeat. :p
Of course, it does help that I'm running memcached also.
 

Adam Howard

Well-known member
#11
@jacko

Did you make sure you opcache.ini was not empty?

Using both or at least doing as I noticed in my post... I noticed a big speed boot (one I could even measure on page load). Why that is... No idea, but it works.
 

jacko

Well-known member
#12
@jacko

Did you make sure you opcache.ini was not empty?

Using both or at least doing as I noticed in my post... I noticed a big speed boot (one I could even measure on page load). Why that is... No idea, but it works.
Sure, settings were all set. The opcache.php script was showing that things were cached but there were no hits. After I disabled Xcache, the Opcache started getting thousands of hits. Install opcache.php on your server and see if you're getting any hits.
 

jacko

Well-known member
#14
With the settings above that Adam has posted, both Xcache and zendopcache will be trying to cache the compiled php files. This isn't what you want to happen.
That's what I thought. As I said - Zend Opcache wasn't even working properly - just consuming memory by caching scripts but never using them. After disabling Xcache the Opcache is working great and very fast.
 

Adam Howard

Well-known member
#15
With the settings above that Adam has posted, both Xcache and zendopcache will be trying to cache the compiled php files. This isn't what you want to happen.
I'm told this. I've read this. But oddly, my site works faster with this.

Do not know why. In all likelihood, it shouldn't, but it does. I cannot explain it. Not going to try. Just enjoying.

(This is one of those times, ignorance is bliss)
 

Adam Howard

Well-known member
#18
I installed Zend Opcache on PHP 5.4. Is it going to be faster if I recompile Apache with PHP 5.5?
php 5.5 does give a speed boost over 5.4, just as 5.6 (currently in beta) gives it more of speed boost over 5.4 and 5.5. So yes, add in the newest version with the newest Apache and you will get more speed.

But if you really want more speed, you should try nginx.
 

Solidus

Well-known member
#19
The ONLY way to go. For OP, read why here, here and here.
Absolutely. When they are configured correctly, you get amazing results. You can see my opcache settings and such here.
Nearly 2 million cache hits and just 2000 misses. Memcached is looking similar too. It results in this,



Doesn't look impressive at first glance, but that load time is from New York to my server in Paris, nearly 4000 miles away. My homepage has a LOT going on too.
 

jacko

Well-known member
#20
Absolutely. When they are configured correctly, you get amazing results. You can see my opcache settings and such here.
Nearly 2 million cache hits and just 2000 misses. Memcached is looking similar too. It results in this,



Doesn't look impressive at first glance, but that load time is from New York to my server in Paris, nearly 4000 miles away. My homepage has a LOT going on too.
mine is looking like this:
http://dzwiek.org/xcache/opcache.php