Browse Source

Ubiquity update Swoole & Workerman (#5095)

* initPooling in onWorkerStart event

* Update README

* remove session

* Update docker file with Swoole pecl install

* [ci skip] Update mysql to 8.0 in README
jcheron 5 years ago
parent
commit
9727bc2c1c

+ 3 - 3
frameworks/PHP/ubiquity/.ubiquity/_swoole.php

@@ -12,7 +12,7 @@ $config["sessionName"]=null;
 $address=$sConfig['host'].':'.$sConfig['port'];
 $address=$sConfig['host'].':'.$sConfig['port'];
 $config ["siteUrl"] = 'http://'.$address;
 $config ["siteUrl"] = 'http://'.$address;
 require ROOT . './../vendor/autoload.php';
 require ROOT . './../vendor/autoload.php';
-$reactServer=new \Ubiquity\servers\swoole\SwooleServer();
-$reactServer->init($config, __DIR__);
+$swooleServer=new \Ubiquity\servers\swoole\SwooleServer();
+$swooleServer->init($config, __DIR__);
 require ROOT.'config/services.php';
 require ROOT.'config/services.php';
-$reactServer->run($sConfig['host'],$sConfig['port']);
+$swooleServer->run($sConfig['host'],$sConfig['port']);

+ 1 - 1
frameworks/PHP/ubiquity/.ubiquity/_workerman.php

@@ -8,7 +8,7 @@ if (! defined ( 'DS' )) {
 }
 }
 $config=include ROOT.'config/config.php';
 $config=include ROOT.'config/config.php';
 $sConfig= include __DIR__.\DS.'workerman-config.php';
 $sConfig= include __DIR__.\DS.'workerman-config.php';
-$config["sessionName"]=$sConfig["sessionName"];
+$config["sessionName"]=null;
 $address=$sConfig['host'].':'.$sConfig['port'];
 $address=$sConfig['host'].':'.$sConfig['port'];
 $config ["siteUrl"] = 'http://'.$address;
 $config ["siteUrl"] = 'http://'.$address;
 require ROOT . './../vendor/autoload.php';
 require ROOT . './../vendor/autoload.php';

+ 20 - 11
frameworks/PHP/ubiquity/README.md

@@ -9,6 +9,7 @@ Tests are available with NginX server, Swoole and Workerman platforms.
 
 
 ## Test Type Implementation Source Code
 ## Test Type Implementation Source Code
 The tests are separated into 7 controllers:
 The tests are separated into 7 controllers:
+### Ubiquity + PDO
 - `Json` for JSON response
 - `Json` for JSON response
   * [JSON](app/controllers/Json.php)
   * [JSON](app/controllers/Json.php)
 - `Db` for database access with ORM (PDO Mysql)
 - `Db` for database access with ORM (PDO Mysql)
@@ -20,23 +21,25 @@ The tests are separated into 7 controllers:
   * [FORTUNES](app/controllers/Fortunes.php)
   * [FORTUNES](app/controllers/Fortunes.php)
 - `Plaintext` for plaintext response
 - `Plaintext` for plaintext response
   * [PLAINTEXT](app/controllers/Plaintext.php)
   * [PLAINTEXT](app/controllers/Plaintext.php)
+### Ubiquity Swoole + Coroutine Mysql
 - `SwooleDb` for database access with Swoole coroutine Mysql driver
 - `SwooleDb` for database access with Swoole coroutine Mysql driver
   * [SwooleDb](app/controllers/SwooleDb.php)
   * [SwooleDb](app/controllers/SwooleDb.php)
+- `SwooleFortunes` used with Swoole
+  * [SwooleFortunes](app/controllers/SwooleFortunes.php)
+### Ubiquity Workerman + Mysqli
 - `Workerman` with Mysqli driver
 - `Workerman` with Mysqli driver
   * [WorkerDb](app/controllers/WorkerDb.php)
   * [WorkerDb](app/controllers/WorkerDb.php)
-- `AsyncFortunes` used with Swoole or Workerman
-  * [AsyncFortunes](app/controllers/AsyncFortunes.php)
+- `WorkerFortunes` used with Workerman
+  * [WorkerFortunes](app/controllers/WorkerFortunes.php)
 
 
 ## Important Libraries
 ## Important Libraries
 The tests were run with:
 The tests were run with:
 * [Ubiquity 2.3.*](https://ubiquity.kobject.net/)
 * [Ubiquity 2.3.*](https://ubiquity.kobject.net/)
 * [PHP Version 7.3.*](http://www.php.net/) with FPM and APC
 * [PHP Version 7.3.*](http://www.php.net/) with FPM and APC
 * [nginx 1.14](http://nginx.org/)
 * [nginx 1.14](http://nginx.org/)
-* [Swoole](https://www.swoole.com/)
-* [Ubiquity-swoole](https://github.com/phpMv/ubiquity-swoole)
-* [Workerman](https://github.com/walkor/Workerman)
-* [Ubiquity-workerman](https://github.com/phpMv/ubiquity-workerman)
-* [MySQL 5.7](https://dev.mysql.com/)
+* [Swoole](https://www.swoole.com/), [Ubiquity-swoole](https://github.com/phpMv/ubiquity-swoole)
+* [Workerman](https://github.com/walkor/Workerman), [Ubiquity-workerman](https://github.com/phpMv/ubiquity-workerman)
+* [MySQL 8.0](https://dev.mysql.com/)
 
 
 
 
 ## Test URLs
 ## Test URLs
@@ -54,16 +57,22 @@ http://localhost:8080/Db
 
 
 ### QUERY
 ### QUERY
 
 
-http://localhost:8080/Db/query/
+- http://localhost:8080/Db/query/
+- http://localhost:8080/SwooleDb/query/
+- http://localhost:8080/WorkerDb/query/
 
 
 ### CACHED QUERY
 ### CACHED QUERY
 
 
-http://localhost:8080/Db/query/
+
 
 
 ### UPDATE
 ### UPDATE
 
 
-http://localhost:8080/Db/update/
+- http://localhost:8080/Db/update/
+- http://localhost:8080/SwooleDb/update/
+- http://localhost:8080/WorkerDb/update/
 
 
 ### FORTUNES
 ### FORTUNES
 
 
-http://localhost:8080/Fortunes
+- http://localhost:8080/Fortunes
+- http://localhost:8080/SwooleFortunes
+- http://localhost:8080/WorkerFortunes

+ 4 - 2
frameworks/PHP/ubiquity/app/config/services.php

@@ -1,5 +1,7 @@
 <?php
 <?php
 \Ubiquity\cache\CacheManager::startProd($config);
 \Ubiquity\cache\CacheManager::startProd($config);
 \Ubiquity\controllers\Startup::$templateEngine = new \Ubiquity\views\engine\micro\MicroTemplateEngine();
 \Ubiquity\controllers\Startup::$templateEngine = new \Ubiquity\views\engine\micro\MicroTemplateEngine();
-\Ubiquity\orm\DAO::setModelsDatabases(["models\\Fortune"=>"default","models\\World"=>"swoole"]);
-\Ubiquity\orm\DAO::initPooling($config,'swoole');
+\Ubiquity\orm\DAO::setModelsDatabases(["models\\Fortune"=>"swoole","models\\World"=>"swoole"]);
+$swooleServer->on('workerStart',function($srv) use($config){
+	\Ubiquity\orm\DAO::initPooling($config,'swoole',\intdiv(512,$srv->setting['worker_num']));
+});

+ 1 - 0
frameworks/PHP/ubiquity/app/config/workerServices.php

@@ -2,3 +2,4 @@
 \Ubiquity\cache\CacheManager::startProd($config);
 \Ubiquity\cache\CacheManager::startProd($config);
 \Ubiquity\controllers\Startup::$templateEngine = new \Ubiquity\views\engine\micro\MicroTemplateEngine();
 \Ubiquity\controllers\Startup::$templateEngine = new \Ubiquity\views\engine\micro\MicroTemplateEngine();
 \Ubiquity\orm\DAO::setModelsDatabases(["models\\Fortune"=>"worker","models\\World"=>"worker"]);
 \Ubiquity\orm\DAO::setModelsDatabases(["models\\Fortune"=>"worker","models\\World"=>"worker"]);
+\Ubiquity\orm\DAO::startDatabase($config,'worker');

+ 1 - 2
frameworks/PHP/ubiquity/app/controllers/Db.php

@@ -16,8 +16,7 @@ class Db extends \Ubiquity\controllers\Controller {
 	}
 	}
 	
 	
 	public function index() {
 	public function index() {
-		$world = DAO::getById(World::class, \mt_rand(1, 10000), false);
-		echo \json_encode($world->_rest);
+		echo \json_encode((DAO::getById(World::class, \mt_rand(1, 10000), false))->_rest);
 	}
 	}
 	
 	
 	public function query($queries = 1) {
 	public function query($queries = 1) {

+ 22 - 0
frameworks/PHP/ubiquity/app/controllers/SwooleFortunes.php

@@ -0,0 +1,22 @@
+<?php
+namespace controllers;
+
+use models\Fortune;
+use Ubiquity\orm\DAO;
+
+class SwooleFortunes extends \Ubiquity\controllers\Controller {
+
+	public function index() {
+		$dbInstance=DAO::pool('swoole');
+		$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;
+		});
+		DAO::freePool($dbInstance);
+		$this->loadView('Fortunes/index.php', [
+			'fortunes' => $fortunes
+		]);
+	}
+}
+

+ 1 - 1
frameworks/PHP/ubiquity/app/controllers/AsyncFortunes.php → frameworks/PHP/ubiquity/app/controllers/WorkerFortunes.php

@@ -4,7 +4,7 @@ namespace controllers;
 use models\Fortune;
 use models\Fortune;
 use Ubiquity\orm\DAO;
 use Ubiquity\orm\DAO;
 
 
-class AsyncFortunes extends \Ubiquity\controllers\Controller {
+class WorkerFortunes extends \Ubiquity\controllers\Controller {
 
 
 	public function index() {
 	public function index() {
 		$fortunes = DAO::getAll(Fortune::class, '', false);
 		$fortunes = DAO::getAll(Fortune::class, '', false);

+ 0 - 4
frameworks/PHP/ubiquity/app/views/Fortunes/raw-index.php

@@ -1,4 +0,0 @@
-<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>
-<?php foreach ($fortunes as $id=>$message) : ?>
-<tr><td><?= $id ?></td><td><?= \htmlentities($message) ?></td></tr>
-<?php endforeach ?></table></body></html>

+ 2 - 2
frameworks/PHP/ubiquity/benchmark_config.json

@@ -30,7 +30,7 @@
         "plaintext_url": "/Plaintext",
         "plaintext_url": "/Plaintext",
         "db_url": "/WorkerDb",
         "db_url": "/WorkerDb",
         "query_url": "/WorkerDb/query/",
         "query_url": "/WorkerDb/query/",
-        "fortune_url": "/AsyncFortunes",
+        "fortune_url": "/WorkerFortunes",
         "update_url": "/WorkerDb/update/",
         "update_url": "/WorkerDb/update/",
         "port": 8080,
         "port": 8080,
         "approach": "Realistic",
         "approach": "Realistic",
@@ -54,7 +54,7 @@
         "db_url": "/SwooleDb",
         "db_url": "/SwooleDb",
         "update_url": "/SwooleDb/update/",
         "update_url": "/SwooleDb/update/",
         "query_url": "/SwooleDb/query/",
         "query_url": "/SwooleDb/query/",
-        "fortune_url": "/AsyncFortunes",
+        "fortune_url": "/SwooleFortunes",
         "port": 8080,
         "port": 8080,
         "approach": "Realistic",
         "approach": "Realistic",
         "classification": "Fullstack",
         "classification": "Fullstack",

+ 1 - 1
frameworks/PHP/ubiquity/composer.json

@@ -1,7 +1,7 @@
 {
 {
 	"require" : {
 	"require" : {
 		"php" : "^7.1",
 		"php" : "^7.1",
-		"phpmv/ubiquity" : "2.4.x-dev"
+		"phpmv/ubiquity" : "dev-techempower-benchmarks"
 	},
 	},
 	"require-dev" : {
 	"require-dev" : {
 		"monolog/monolog" : "^1.24",
 		"monolog/monolog" : "^1.24",

+ 0 - 2
frameworks/PHP/ubiquity/index.php

@@ -1,6 +1,4 @@
 <?php
 <?php
-error_reporting(E_ALL);
-
 define('DS', DIRECTORY_SEPARATOR);
 define('DS', DIRECTORY_SEPARATOR);
 define('ROOT', __DIR__ . DS . 'app' . DS);
 define('ROOT', __DIR__ . DS . 'app' . DS);
 $config = include_once ROOT . 'config/config.php';
 $config = include_once ROOT . 'config/config.php';

+ 0 - 24
frameworks/PHP/ubiquity/ubiquity-raw.dockerfile

@@ -1,24 +0,0 @@
-FROM ubuntu:19.04
-
-ARG DEBIAN_FRONTEND=noninteractive
-
-RUN apt-get update -yqq && apt-get install -yqq software-properties-common > /dev/null
-RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
-RUN apt-get update -yqq > /dev/null && \
-    apt-get install -yqq nginx git unzip php7.3 php7.3-common php7.3-cli php7.3-fpm php7.3-mysql  > /dev/null
-
-RUN apt-get install -yqq composer > /dev/null
-
-COPY deploy/conf/* /etc/php/7.3/fpm/
-
-ADD ./ /ubiquity
-WORKDIR /ubiquity
-
-RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/7.3/fpm/php-fpm.conf ; fi;
-
-RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
-
-RUN chmod 777 -R /ubiquity/app/cache/*
-
-CMD service php7.3-fpm start && \
-    nginx -c /ubiquity/deploy/nginx.conf -g "daemon off;"

+ 3 - 7
frameworks/PHP/ubiquity/ubiquity-swoole.dockerfile

@@ -1,11 +1,7 @@
 FROM php:7.3
 FROM php:7.3
 
 
-ENV SWOOLE_VERSION=4.4.5
-
-RUN cd /tmp && curl -sSL "https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz" | tar xzf - \
-        && cd swoole-src-${SWOOLE_VERSION} \
-        && phpize && ./configure > /dev/null && make > /dev/null && make install > /dev/null \
-        && docker-php-ext-enable swoole
+RUN pecl install swoole-4.4.7 > /dev/null && \
+    docker-php-ext-enable swoole
 
 
 RUN docker-php-ext-install pdo_mysql pcntl > /dev/null
 RUN docker-php-ext-install pdo_mysql pcntl > /dev/null
 
 
@@ -23,7 +19,7 @@ RUN deploy/run/install-composer.sh
 RUN apt-get update -yqq > /dev/null && \
 RUN apt-get update -yqq > /dev/null && \
     apt-get install -yqq git unzip > /dev/null
     apt-get install -yqq git unzip > /dev/null
 
 
-RUN php composer.phar require phpmv/ubiquity-devtools:dev-master phpmv/ubiquity-swoole:dev-master --quiet
+RUN php composer.phar require phpmv/ubiquity-devtools:dev-techempower-benchmarks phpmv/ubiquity-swoole:dev-techempower-benchmarks --quiet
 
 
 RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet
 RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet
 
 

+ 1 - 1
frameworks/PHP/ubiquity/ubiquity-workerman.dockerfile

@@ -27,7 +27,7 @@ RUN deploy/run/install-composer.sh
 RUN apt-get update -yqq > /dev/null && \
 RUN apt-get update -yqq > /dev/null && \
     apt-get install -yqq git unzip > /dev/null
     apt-get install -yqq git unzip > /dev/null
 
 
-RUN php composer.phar require phpmv/ubiquity-devtools:dev-master phpmv/ubiquity-workerman:dev-master phpmv/ubiquity-mysqli:dev-master --quiet
+RUN php composer.phar require phpmv/ubiquity-devtools:dev-techempower-benchmarks phpmv/ubiquity-workerman:dev-techempower-benchmarks phpmv/ubiquity-mysqli:dev-techempower-benchmarks --quiet
 
 
 RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet
 RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet