Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APC -> APCu / OPCache, performance poor

I have an m3.xlarge EC2 instance that I updated to PHP 5.5.11 today.

With this update, it overwrote php55-pecl-apc with php55-pecl-apcu.

After reading and experimenting, my understanding is that APC has been replaced with OPCache, except for a key value store which can be brought back with APCu.

After tweaking my config to something that looks reasonable, using Wordpress while logged in is now terribly slow, at least 300-900ms worse (the front end is cached via varnish, and works perfect... but when you're using the admin it is deliberately not cached, and slow as sin).

I did a series of benchmarks as I upgraded, across a small sample size for each step. It degraded worse and worse as I went on.

  • APC (before upgrade) -->
  • OPCache + no APCu -->
  • OPCache + APCu + WP Plugin for APCu

Right now I'm just hanging out with OPCache, and no APCu.

  1. How can I achieve the same performance? I loved the admin interface, I loved how fast it was. I honestly don't see how this is an improvement at all, it's quite depressing really... unless there is some super library out there that I'm not aware of. It's certainly not what I have though, or maybe it's not configured well.
  2. Assuming the answer to #1 is 'you configured it like balls', then would you mind taking a look at this and seeing if this is reasonable?

For my setup I'm using latest wordpress, a few large plugins but I can't take them off because they're important. Luckily varnish takes care of most of the work. I have 4 cores, 16GB memory, ~10k files in my website root. I also have no real hardcore apps or anything other than wordpress, it's a fairly vanilla setup. I think that's it for stuff that might help.

Config:

zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=0 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.max_wasted_percentage=5 opcache.use_cwd=1 opcache.validate_timestamps=1 opcache.revalidate_freq=0 opcache.revalidate_path=0 opcache.save_comments=0 opcache.load_comments=0 opcache.fast_shutdown=1 opcache.enable_file_override=0 opcache.optimization_level=0xffffffff opcache.inherited_hack=1 opcache.dups_fix=0 opcache.blacklist_filename=/etc/php-5.5.d/opcache*.blacklist opcache.max_file_size=2M opcache.consistency_checks=1 opcache.force_restart_timeout=180 opcache.error_log=/var/log/php-fpm/5.5/opcache.log opcache.log_verbosity_level=1 opcache.preferred_memory_model= opcache.protect_memory=0 
like image 303
Tallboy Avatar asked Apr 30 '14 07:04

Tallboy


People also ask

How do I clear my APCu cache?

You can call the apc_clear_cache() function to clear the cache. To clear the user cache (key/value), you can use apc_cache_clear('user') . To clear the system cache, the one that holds the byte-code of the PHP files (the so called “opcode” cache), just call apc_cache_clear() without options.

What is APCu cache?

APCu is a user-accessible PHP cache. Pantheon provides APCu by default across all plans, but the size of the APCu memory cache (apc. shm_size) varies depending on the service level. See the Application Containers overview to learn more about APCu on Pantheon's container architecture.

How do I use OPCache in PHP?

OPCache can only be compiled as a shared extension under this version. Firstly, you need to enable the building of default extension with –enable-opcache option to make it available. Afterwards, you can use the zend_extension configuration directive to lead the OP Cache extension into PHP.


1 Answers

Right now you are checking every file on every request for changes, which probably isn't what you want on a production system.

I usually just disable it (remember to restart the web server after making changes):

opcache.validate_timestamps=0 

Alternatively, you can try setting the frequency to something other than 0 and keep it enabled:

opcache.validate_timestamps=1   opcache.revalidate_freq=300 

This should theoretically only check for changes every 5 minutes.

like image 63
knrdk Avatar answered Oct 02 '22 14:10

knrdk