Browse Source

Add ubiquity preload (#5362)

* Add preloading for ubiquity & ubiquity-swoole

* Fix typos

* fix typos

* Update php.ini

* Fortunes Improvement
jcheron 5 years ago
parent
commit
e545413a97

+ 12 - 0
frameworks/PHP/ubiquity/app/config/preloader.config.php

@@ -0,0 +1,12 @@
+<?php
+return array(
+	"classes-files" => array(),
+	"excludeds" => array(),
+	"libraries-parts" => array(),
+	"callback" => function ($pre) {
+		$pre->addApplicationControllers()
+			->addUbiquityViews()
+			->addApplicationModels()
+			->addUbiquityBasics(true);
+	}
+);

+ 5 - 0
frameworks/PHP/ubiquity/app/config/preloader.script.php

@@ -0,0 +1,5 @@
+<?php
+define('APP_ROOT', __DIR__ . '/../');
+include_once \APP_ROOT . './../vendor/phpmv/ubiquity/src/Ubiquity/cache/Preloader.php';
+$config = include __DIR__ . '/preloader.config.php';
+\Ubiquity\cache\Preloader::fromArray(\APP_ROOT, $config);

+ 1 - 1
frameworks/PHP/ubiquity/app/controllers/Fortunes.php

@@ -5,7 +5,7 @@ use Ubiquity\orm\DAO;
 use models\Fortune;
 use Ubiquity\controllers\Startup;
 
-class Fortunes extends \Ubiquity\controllers\Controller {
+class Fortunes extends \Ubiquity\controllers\SimpleViewController {
 
 	public function initialize() {
 		\Ubiquity\cache\CacheManager::startProd(Startup::$config);

+ 6 - 8
frameworks/PHP/ubiquity/app/controllers/SwooleFortunes.php

@@ -4,19 +4,17 @@ namespace controllers;
 use models\Fortune;
 use Ubiquity\orm\DAO;
 
-class SwooleFortunes extends \Ubiquity\controllers\Controller
-{
-	
-	public function index()
-	{
+class SwooleFortunes extends \Ubiquity\controllers\SimpleViewAsyncController {
+
+	public function index() {
 		$fortunes = DAO::getAll(Fortune::class, '', false);
 		$fortunes[] = (new Fortune())->setId(0)->setMessage('Additional fortune added at request time.');
 		\usort($fortunes, function ($left, $right) {
 			return $left->message <=> $right->message;
 		});
-			$this->loadView('Fortunes/index.php', [
-				'fortunes' => $fortunes
-			]);
+		$this->loadView('Fortunes/index.php', [
+			'fortunes' => $fortunes
+		]);
 	}
 }
 

+ 3 - 3
frameworks/PHP/ubiquity/app/controllers/WorkerFortunes.php

@@ -4,12 +4,12 @@ namespace controllers;
 use models\Fortune;
 use Ubiquity\orm\DAO;
 
-class WorkerFortunes extends \Ubiquity\controllers\Controller {
+class WorkerFortunes extends \Ubiquity\controllers\SimpleViewAsyncController {
 
 	public function initialize() {
-		\Ubiquity\utils\http\UResponse::setContentType('text/html','utf-8');
+		\Ubiquity\utils\http\UResponse::setContentType('text/html', 'utf-8');
 	}
-	
+
 	public function index() {
 		$fortunes = DAO::getAll(Fortune::class, '', false);
 		$fortunes[] = (new Fortune())->setId(0)->setMessage('Additional fortune added at request time.');

+ 5 - 2
frameworks/PHP/ubiquity/deploy/conf/php-async.ini

@@ -3,8 +3,11 @@ opcache.enable_cli=1
 opcache.validate_timestamps=0
 opcache.save_comments=0
 opcache.enable_file_override=1
-opcache.huge_code_pages=1
+opcache.memory_consumption=256
+opcache.interned_strings_buffer=16
+opcache.max_accelerated_files=7963
+opcache.preload_user=www-data
 
 mysqlnd.collect_statistics = Off
 
-memory_limit = 512M
+memory_limit = 512M

+ 3 - 3
frameworks/PHP/ubiquity/deploy/conf/php-fpm.conf

@@ -14,14 +14,14 @@
 ; Pid file
 ; Note: the default prefix is /var
 ; Default Value: none
-pid = /run/php/php7.3-fpm.pid
+pid = /run/php/php7.4-fpm.pid
 
 ; Error log file
 ; If it's set to "syslog", log is sent to syslogd instead of being written
 ; into a local file.
 ; Note: the default prefix is /var
 ; Default Value: log/php-fpm.log
-;error_log = /var/log/php7.3-fpm.log
+;error_log = /var/log/php7.4-fpm.log
 error_log = /dev/stderr
 
 
@@ -161,7 +161,7 @@ group = www-data
 ;                            (IPv6 and IPv4-mapped) on a specific port;
 ;   '/path/to/unix/socket' - to listen on a unix socket.
 ; Note: This value is mandatory.
-listen = /run/php/php7.3-fpm.sock
+listen = /run/php/php7.4-fpm.sock
 
 ; Set listen(2) backlog.
 ; Default Value: 511 (-1 on FreeBSD and OpenBSD)

+ 15 - 6
frameworks/PHP/ubiquity/deploy/conf/php.ini

@@ -1770,14 +1770,14 @@ opcache.enable=1
 ;opcache.enable_cli=0
 
 ; The OPcache shared memory storage size.
-;opcache.memory_consumption=128
+opcache.memory_consumption=256
 
 ; The amount of memory for interned strings in Mbytes.
-;opcache.interned_strings_buffer=8
+opcache.interned_strings_buffer=16
 
 ; The maximum number of keys (scripts) in the OPcache hash table.
 ; Only numbers between 200 and 1000000 are allowed.
-;opcache.max_accelerated_files=10000
+opcache.max_accelerated_files=7963
 
 ; The maximum percentage of "wasted" memory until a restart is scheduled.
 ;opcache.max_wasted_percentage=5
@@ -1798,11 +1798,11 @@ opcache.validate_timestamps=0
 ;opcache.revalidate_freq=2
 
 ; Enables or disables file search in include_path optimization
-;opcache.revalidate_path=0
+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
+opcache.save_comments=0
 
 ; Allow file existence override (file_exists, etc.) performance feature.
 opcache.enable_file_override=1
@@ -1878,7 +1878,7 @@ opcache.enable_file_override=1
 
 ; Enables or disables copying of PHP code (text segment) into HUGE PAGES.
 ; This should improve performance, but requires appropriate OS configuration.
-opcache.huge_code_pages=1
+;opcache.huge_code_pages=1
 
 ; Validate cached file permissions.
 ;opcache.validate_permission=0
@@ -1886,6 +1886,15 @@ opcache.huge_code_pages=1
 ; Prevent name collisions in chroot'ed environment.
 ;opcache.validate_root=0
 
+; Prevents caching files that are less than this number of seconds old. 
+; It protects from caching of incompletely updated files. 
+; In case all file updates on your site are atomic, you may increase performance by setting it to "0".
+opcache.file_update_protection=0
+
+opcache.fast_shutdown=1
+
+opcache.preload_user=www-data
+
 [curl]
 ; A default value for the CURLOPT_CAINFO option. This is required to be an
 ; absolute path.

+ 1 - 1
frameworks/PHP/ubiquity/deploy/nginx.conf

@@ -40,7 +40,7 @@ http {
 
 
     upstream fastcgi_backend {
-        server unix:/var/run/php/php7.3-fpm.sock;
+        server unix:/var/run/php/php7.4-fpm.sock;
         keepalive 50;
     }
 

+ 4 - 0
frameworks/PHP/ubiquity/ubiquity-swoole.dockerfile

@@ -29,4 +29,8 @@ RUN php composer.phar install --optimize-autoloader --classmap-authoritative --n
 
 RUN chmod 777 -R /ubiquity/.ubiquity/*
 
+RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /usr/local/etc/php/php-async.ini
+
+USER www-data
+
 CMD /ubiquity/vendor/bin/Ubiquity serve -t=swoole -p=8080 -h=0.0.0.0

+ 2 - 0
frameworks/PHP/ubiquity/ubiquity.dockerfile

@@ -20,5 +20,7 @@ RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --q
 
 RUN chmod 777 -R /ubiquity/app/cache/*
 
+RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /etc/php/7.4/fpm/php.ini
+
 CMD service php7.4-fpm start && \
     nginx -c /ubiquity/deploy/nginx.conf -g "daemon off;"