Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature optimize opcache #943

Merged

Conversation

freephile
Copy link
Contributor

Changes to the php.ini to optimize PHP's Opcache

Introduces new config called 'm_mode' (default 'production').
meza mode (development or production)

  1. production being as performant and secure as possible
  2. development being less secure and providing optional features useful for dev

Greg Rundlett added 2 commits March 18, 2018 16:16
In production, PHP files are never checked for modification on the filesystem.
They are simply read into the PHP Opcache, and used from cache. (fast) Also,
There is less verbose logging in production.
This switch allows for easier enabling of features like profiling that
may only ever be used in development.
@freephile
Copy link
Contributor Author

I documented 'Opcache' at https://meta.qualitybox.us/wiki/Opcache

@jamesmontalvo3
Copy link
Contributor

Regarding opcache.validate_timestamps...how does this work with meza deploy? How will deploy know when it has to restart httpd?

@freephile
Copy link
Contributor Author

freephile commented Mar 20, 2018

Well, the only PHP files would theoretically be local extensions, core extensions, or core updates (and a few miscellaneous like ServerPerformance, WikiBlender). I think Apache gets restarted on the 'mediawiki' role....checking.... nope there isn't a handler.

OK, so we should have a handler that can stop Apache (or at least put the wiki into read-only with a site notice) and then do the mediawiki role, and then start or reload Apache. That would perhaps require a new setup in HAProxy or Apache that could serve a static file during deploys.

@jamesmontalvo3
Copy link
Contributor

Taking the site down or substantially limiting it seems like a heavy handed approach. Also I wasn't under the impression that Apache needed to stop during deploy...just that after a file-changing deploy it'd need to be restarted. How hard would it be to detect if anything changed in /opt/htdocs during deploy, and if so then restart httpd?

@jamesmontalvo3
Copy link
Contributor

opcache.max_accelerated_files=7963

You chose this number based on the number of PHP files in /opt/htdocs and /opt/.deploy-meza I assume? What if an install has a substantial number of large extensions? By default we may want to make this larger...with plenty of room to add extensions, but could make the value configurable via public.yml for systems that want to dial in the efficiency.

@jamesmontalvo3
Copy link
Contributor

m_mode seems a little vague. How about m_environment_purpose or something like that? e.g. "what's the purpose of this environment? Production."

@jamesmontalvo3
Copy link
Contributor

Rather than restart Apache, I think we could just reset opcache by doing the following:

  1. Create /opt/htdocs/flush-cache.php with contents
<?php

if ( 
	! isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && 
	( $_SERVER['REMOTE_ADDR'] === 'localhost' || $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) 
) {
	opcache_reset();
}
else {
	header('HTTP/1.0 403 Forbidden');
}
  1. On every meza deploy do curl localhost:8080/flush-cache.php

This seems less invasive to me than doing an Apache restart which could cause users to lose data.

Ref: https://ma.ttias.be/how-to-clear-php-opcache/

@freephile
Copy link
Contributor Author

You chose this number based on the number of PHP files in /opt/htdocs and /opt/.deploy-meza I assume? What if an install has a substantial number of large extensions? By default we may want to make this larger...with plenty of room to add extensions, but could make the value configurable via public.yml for systems that want to dial in the efficiency.

I think we could raise it to ~10000 without losing efficiency, and that would be good for almost anyone because I based the number on my QualityBox demo with 101 extensions.

@jamesmontalvo3 jamesmontalvo3 changed the base branch from master to opcache September 15, 2018 00:01
@jamesmontalvo3
Copy link
Contributor

@freephile I'd like to experiment with this on one of our dev servers a bit. I've changed the branch it pulls into to keep it out of master for now. I'll load it on a dev server and give it a try and go from there. Thanks for the commit! Sorry for the huge delay.

@jamesmontalvo3 jamesmontalvo3 merged commit e3ddd50 into enterprisemediawiki:opcache Sep 15, 2018
@jamesmontalvo3
Copy link
Contributor

@freephile is there an issue with having Opcache.max_accelerated_files be 20000 even though that's larger than it needs to be? Having it bigger than we need with base Meza leaves room for local extensions.

@jamesmontalvo3 jamesmontalvo3 mentioned this pull request Sep 17, 2018
2 tasks
@freephile freephile deleted the featureOptimizeOpcache branch July 10, 2019 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants