Browse Source

Update ubiquity (#5173)

* remove workerman mysql + move Ubiquity to pgsql

* move swoole to pdo Mysql

* update in worker
jcheron 5 years ago
parent
commit
ebb5816216

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

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

+ 4 - 4
frameworks/PHP/ubiquity/README.md

@@ -9,7 +9,7 @@ Tests are available with NginX server, Swoole and Workerman platforms.
 
 ## Test Type Implementation Source Code
 The tests are separated into 7 controllers:
-### Ubiquity + PDO
+### Ubiquity + PDO pgsql
 - `Json` for JSON response
   * [JSON](app/controllers/Json.php)
 - `Db` for database access with ORM (PDO Mysql)
@@ -21,13 +21,13 @@ The tests are separated into 7 controllers:
   * [FORTUNES](app/controllers/Fortunes.php)
 - `Plaintext` for plaintext response
   * [PLAINTEXT](app/controllers/Plaintext.php)
-### Ubiquity Swoole + Coroutine Mysql
+### Ubiquity Swoole + PDO Mysql
 - `SwooleDb` for database access with Swoole coroutine Mysql driver
   * [SwooleDb](app/controllers/SwooleDb.php)
 - `SwooleFortunes` used with Swoole
   * [SwooleFortunes](app/controllers/SwooleFortunes.php)
-### Ubiquity Workerman + Mysqli
-- `Workerman` with Mysqli driver
+### Ubiquity Workerman + PDO pgsql
+- `Workerman` with PDO pgsql driver
   * [WorkerDb](app/controllers/WorkerDb.php)
 - `WorkerFortunes` used with Workerman
   * [WorkerFortunes](app/controllers/WorkerFortunes.php)

+ 1 - 23
frameworks/PHP/ubiquity/app/config/config.php

@@ -6,7 +6,7 @@ return array(
 			"type" => "mysql",
 			"dbName" => "hello_world",
 			"serverName" => "tfb-database", // tfb-database
-			"port" => "3306",
+			"port" => 3306,
 			"user" => "benchmarkdbuser", // benchmarkdbuser
 			"password" => "benchmarkdbpass", // benchmarkdbpass
 			"options" => [
@@ -14,28 +14,6 @@ return array(
 			],
 			"cache"=>false
 		],
-		'swoole'=>[
-			"wrapper"=>"\\Ubiquity\\db\\providers\\swoole\\SwooleWrapper",
-			"type" => "mysql",
-			"dbName" => "hello_world",
-			"serverName" => "tfb-database", // tfb-database
-			"port" => "3306",
-			"user" => "benchmarkdbuser", // benchmarkdbuser
-			"password" => "benchmarkdbpass", // benchmarkdbpass
-			"options" => [],
-			"cache" => false
-		],
-		'worker'=>[
-			"wrapper"=>"\\Ubiquity\\db\\providers\\mysqli\\MysqliWrapper",
-			"type" => "mysql",
-			"dbName" => "hello_world",
-			"serverName" => "p:tfb-database", // tfb-database
-			"port" => "3306",
-			"user" => "benchmarkdbuser", // benchmarkdbuser
-			"password" => "benchmarkdbpass", // benchmarkdbpass
-			"options" => [],
-			"cache" => false
-		],
 		'pgsql'=>[
 			"wrapper"=>"\\Ubiquity\\db\\providers\\pdo\\PDOWrapper",
 			"type" => "pgsql",

+ 0 - 7
frameworks/PHP/ubiquity/app/config/services.php

@@ -1,7 +0,0 @@
-<?php
-\Ubiquity\cache\CacheManager::startProd($config);
-\Ubiquity\controllers\Startup::$templateEngine = new \Ubiquity\views\engine\micro\MicroTemplateEngine();
-\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']));
-});

+ 11 - 0
frameworks/PHP/ubiquity/app/config/swooleServices.php

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

+ 2 - 2
frameworks/PHP/ubiquity/app/config/workerServices.php

@@ -1,8 +1,8 @@
 <?php
 \Ubiquity\cache\CacheManager::startProd($config);
 \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"=>'pgsql',"models\\World"=>'pgsql']);
 $workerServer->onWorkerStart=function() use($config){
-	\Ubiquity\orm\DAO::startDatabase($config,'worker');
+	\Ubiquity\orm\DAO::startDatabase($config,'pgsql');
 };
 

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

@@ -12,7 +12,7 @@ class Db extends \Ubiquity\controllers\Controller {
 	public function initialize() {
 		\header('Content-Type: application/json');
 		\Ubiquity\cache\CacheManager::startProd(\Ubiquity\controllers\Startup::$config);
-		DAO::setModelDatabase(World::class);
+		DAO::setModelDatabase(World::class, 'pgsql');
 	}
 	
 	public function index() {
@@ -34,9 +34,10 @@ class Db extends \Ubiquity\controllers\Controller {
 		for ($i = 0; $i < $queries; ++ $i) {
 			$world = DAO::getById(World::class, \mt_rand(1, 10000), false);
 			$world->randomNumber = \mt_rand(1, 10000);
-			DAO::update($world);
+			DAO::toUpdate($world);
 			$worlds[] = $world->_rest;
 		}
+		DAO::flushUpdates();
 		echo \json_encode($worlds);
 	}
 }

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

@@ -10,7 +10,7 @@ class Fortunes extends \Ubiquity\controllers\Controller {
 	public function initialize() {
 		\Ubiquity\cache\CacheManager::startProd(Startup::$config);
 		Startup::$templateEngine = new \Ubiquity\views\engine\micro\MicroTemplateEngine();
-		DAO::setModelDatabase(Fortune::class);
+		DAO::setModelDatabase(Fortune::class, 'pgsql');
 	}
 
 	public function index() {

+ 10 - 13
frameworks/PHP/ubiquity/app/controllers/SwooleDb.php

@@ -7,41 +7,38 @@ use models\World;
 /**
  * Bench controller.
  */
-class SwooleDb extends \Ubiquity\controllers\Controller {
-
-	public function initialize() {
+class SwooleDb extends \Ubiquity\controllers\Controller
+{
+	
+	public function initialize()
+	{
 		\Ubiquity\utils\http\UResponse::setContentType('application/json');
 	}
 	
-	public function index() {
-		$dbInstance=DAO::pool('swoole');
+	public function index()
+	{
 		$world = DAO::getById(World::class, \mt_rand(1, 10000), false);
-		DAO::freePool($dbInstance);
 		echo \json_encode($world->_rest);
 	}
 	
-	public function query($queries = 1) {
+	public function query($queries = 1){
 		$worlds = [];
 		$queries = \min(\max($queries, 1), 500);
-		$dbInstance=DAO::pool('swoole');
 		for ($i = 0; $i < $queries; ++ $i) {
 			$worlds[] = (DAO::getById(World::class, \mt_rand(1, 10000), false))->_rest;
 		}
-		DAO::freePool($dbInstance);
 		echo \json_encode($worlds);
 	}
 	
-	public function update($queries = 1) {
+	public function update($queries = 1){
 		$worlds = [];
 		$queries = \min(\max($queries, 1), 500);
-		$dbInstance=DAO::pool('swoole');
 		for ($i = 0; $i < $queries; ++ $i) {
 			$world = DAO::getById(World::class, \mt_rand(1, 10000), false);
 			$world->randomNumber = \mt_rand(1, 10000);
 			DAO::update($world);
-			$worlds[]=$world->_rest;
+			$worlds[] = $world->_rest;
 		}
-		DAO::freePool($dbInstance);
 		echo \json_encode($worlds);
 	}
 }

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

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

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

@@ -33,9 +33,10 @@ class WorkerDb extends \Ubiquity\controllers\Controller {
 		for ($i = 0; $i < $queries; ++ $i) {
 			$world = DAO::getById(World::class, \mt_rand(1, 10000), false);
 			$world->randomNumber = \mt_rand(1, 10000);
-			DAO::update($world);
+			DAO::toUpdate($world);
 			$worlds[]=$world->_rest;
 		}
+		DAO::flushUpdates();
 		echo \json_encode($worlds);
 	}
 }

+ 3 - 24
frameworks/PHP/ubiquity/benchmark_config.json

@@ -12,7 +12,7 @@
         "port": 8080,
         "approach": "Realistic",
         "classification": "Fullstack",
-        "database": "MySQL",
+        "database": "Postgres",
         "framework": "ubiquity",
         "language": "PHP",
         "flavor": "PHP7",
@@ -28,27 +28,6 @@
       "workerman": {
         "json_url": "/Json",
         "plaintext_url": "/Plaintext",
-        "db_url": "/WorkerDb",
-        "query_url": "/WorkerDb/query/",
-        "fortune_url": "/WorkerFortunes",
-        "update_url": "/WorkerDb/update/",
-        "port": 8080,
-        "approach": "Realistic",
-        "classification": "Fullstack",
-        "database": "MySQL",
-        "framework": "Ubiquity",
-        "language": "PHP",
-        "flavor": "PHP7",
-        "orm": "Full",
-        "platform": "workerman",
-        "webserver": "none",
-        "os": "Linux",
-        "database_os": "Linux",
-        "display_name": "ubiquity-workerman",
-        "notes": "",
-        "versus": "workerman"
-      },
-      "workerman-pgsql": {
         "db_url": "/WorkerDb",
         "query_url": "/WorkerDb/query/",
         "fortune_url": "/WorkerFortunes",
@@ -65,7 +44,7 @@
         "webserver": "none",
         "os": "Linux",
         "database_os": "Linux",
-        "display_name": "ubiquity-workerman-pgsql",
+        "display_name": "ubiquity-workerman",
         "notes": "",
         "versus": "workerman"
       },
@@ -88,7 +67,7 @@
         "webserver": "none",
         "os": "Linux",
         "database_os": "Linux",
-        "display_name": "ubiquity-swoole",
+        "display_name": "ubiquity-swoole-mysql",
         "notes": "",
         "versus": "swoole"
       }

+ 0 - 38
frameworks/PHP/ubiquity/ubiquity-workerman-pgsql.dockerfile

@@ -1,38 +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 php7.3 php7.3-common php7.3-cli php7.3-pgsql > /dev/null
-
-RUN apt-get install -yqq composer > /dev/null
-
-RUN apt-get install -y php-pear php-dev libevent-dev > /dev/null
-RUN printf "\n\n /usr/lib/x86_64-linux-gnu/\n\n\nno\n\n\n" | pecl install event > /dev/null && echo "extension=event.so" > /etc/php/7.3/cli/conf.d/event.ini
-
-COPY deploy/conf/php-async.ini /etc/php/7.3/cli/php.ini
-
-ADD ./ /ubiquity
-WORKDIR /ubiquity
-
-RUN chmod -R 777 /ubiquity
-
-RUN ["chmod", "+x", "deploy/run/install-composer.sh"]
-
-RUN deploy/run/install-composer.sh
-
-RUN apt-get update -yqq > /dev/null && \
-    apt-get install -yqq git unzip > /dev/null
-
-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 chmod 777 -R /ubiquity/.ubiquity/*
-
-RUN sed -i "s|'worker'|'pgsql'|g" /ubiquity/app/config/workerServices.php
-
-CMD /ubiquity/vendor/bin/Ubiquity serve -t=workerman -p=8080 -h=0.0.0.0

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

@@ -6,7 +6,7 @@ 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 php7.3 php7.3-common php7.3-cli php7.3-mysql  > /dev/null
+    apt-get install -yqq php7.3 php7.3-common php7.3-cli php7.3-pgsql > /dev/null
 
 RUN apt-get install -yqq composer > /dev/null
 
@@ -33,4 +33,6 @@ RUN php composer.phar install --optimize-autoloader --classmap-authoritative --n
 
 RUN chmod 777 -R /ubiquity/.ubiquity/*
 
+RUN sed -i "s|'worker'|'pgsql'|g" /ubiquity/app/config/workerServices.php
+
 CMD /ubiquity/vendor/bin/Ubiquity serve -t=workerman -p=8080 -h=0.0.0.0

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

@@ -5,7 +5,7 @@ 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
+    apt-get install -yqq nginx git unzip php7.3 php7.3-common php7.3-cli php7.3-fpm php7.3-pgsql  > /dev/null
 
 RUN apt-get install -yqq composer > /dev/null