Browse Source

Add Ubiquity raw + update to 2.3.0 (#4965)

* update to Ubiquity 2.3.0

* Add raw controllers

* Update react with 512 workers

* Update RawFortunes.php

* remove uses

* Decrease the number of php-pm workers to pass tests

* Remove Ubiquity-react

Impossible to increase the number of workers without causing errors in travis-ci
jcheron 6 years ago
parent
commit
3dad80b176

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

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

+ 8 - 12
frameworks/PHP/ubiquity/README.md

@@ -5,13 +5,13 @@ Ubiquity is a full-stack php framework, These tests involve:
 - the ORM part (Full)
 - the JSON serialization (native php)
 
-Tests are available with NginX, Swoole and PHP-PM (beta) servers.
+Tests are available with NginX server and Swoole platform.
 
 ## Test Type Implementation Source Code
-The tests are separated into 4 controllers:
+The tests are separated into 6 controllers:
 - `Json` for JSON response
   * [JSON](app/controllers/Json.php)
-- `Db` for database access
+- `Db` for database access with ORM
   * [DB](app/controllers/Db.php)
   * [QUERY](app/controllers/Db.php)
   * [CACHED QUERY (not implemented)]()
@@ -20,24 +20,20 @@ The tests are separated into 4 controllers:
   * [FORTUNES](app/controllers/Fortunes.php)
 - `Plaintext` for plaintext response
   * [PLAINTEXT](app/controllers/Plaintext.php)
-
+- `Raw` for database access without ORM
+  * [Raw](app/controllers/Raw.php)
+- `RawFortunes` without ORM and without template engine
+  * [FORTUNES](app/controllers/RawFortunes.php)
 
 ## Important Libraries
 The tests were run with:
-* [Ubiquity 2.1.*](https://ubiquity.kobject.net/)
+* [Ubiquity 2.3.*](https://ubiquity.kobject.net/)
 * [PHP Version 7.3.*](http://www.php.net/) with FPM and APC
 * [nginx 1.14](http://nginx.org/)
-* [PHP-PM](https://github.com/php-pm/php-pm)
-* [Ubiquity-reactphp server](https://github.com/phpMv/ubiquity-reactphp)
-* [Ubiquity-php-pm bridge](https://github.com/phpMv/ubiquity-php-pm)
 * [Swoole](https://www.swoole.com/)
 * [Ubiquity-swoole](https://github.com/phpMv/ubiquity-swoole)
 * [MySQL 5.7](https://dev.mysql.com/)
 
-## Servers
-PHP-PM server (beta version) is configured with this values:
-- workers: 64
-- max-requests: 1024
 
 ## Test URLs
 ### JSON

+ 5 - 6
frameworks/PHP/ubiquity/app/controllers/Db.php

@@ -14,24 +14,23 @@ class Db extends Controller {
 
 	public function initialize() {
 		UResponse::setContentType('application/json');
-		DAO::startDatabase(Startup::$config);
+		DAO::setModelDatabase(World::class);
 	}
-
+	
 	public function index() {
 		$world = DAO::getById(World::class, \mt_rand(1, 10000), false);
 		echo \json_encode($world->_rest);
 	}
-
+	
 	public function query($queries = 1) {
 		$worlds = [];
 		$queries = \min(\max($queries, 1), 500);
 		for ($i = 0; $i < $queries; ++ $i) {
-			$world = DAO::getById(World::class, \mt_rand(1, 10000), false);
-			$worlds[] = $world->_rest;
+			$worlds[] = (DAO::getById(World::class, \mt_rand(1, 10000), false))->_rest;
 		}
 		echo \json_encode($worlds);
 	}
-
+	
 	public function update($queries = 1) {
 		$worlds = [];
 		$queries = \min(\max($queries, 1), 500);

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

@@ -11,7 +11,7 @@ class Fortunes extends Controller {
 
 	public function initialize() {
 		Startup::$templateEngine = new MicroTemplateEngine();
-		DAO::startDatabase(Startup::$config);
+		DAO::setModelDatabase(Fortune::class);
 	}
 
 	public function index() {

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

@@ -13,7 +13,7 @@ class Plaintext extends Controller{
 		UResponse::setContentType('text/plain; charset=utf-8');
 	}
 	public function index() {
-		echo "Hello, World!";
+		echo 'Hello, World!';
 	}
 
 }

+ 46 - 0
frameworks/PHP/ubiquity/app/controllers/Raw.php

@@ -0,0 +1,46 @@
+<?php
+namespace controllers;
+
+/**
+ * Bench controller.
+ */
+class Raw extends \Ubiquity\controllers\Controller {
+	protected $db;
+	
+	public function initialize() {
+		\header('Content-type: application/json');
+		$this->db=\Ubiquity\db\Database::start();
+	}
+	
+	public function index() {
+		echo \json_encode($this->getRandomWorld(\mt_rand(1, 10000)));
+	}
+	
+	public function query($queries = 1) {
+		$worlds = [];
+		$queries = \min(\max($queries, 1), 500);
+		for ($i = 0; $i < $queries; ++ $i) {
+			$worlds[] = $this->getRandomWorld(\mt_rand(1, 10000));
+		}
+		echo \json_encode($worlds);
+	}
+	
+	public function update($queries = 1) {
+		$worlds = [];
+		$queries = \min(\max($queries, 1), 500);
+		for ($i = 0; $i < $queries; ++ $i) {
+			$world = $this->getRandomWorld(\mt_rand(1, 10000));
+			$this->db->prepareAndExecuteUpdate("UPDATE World SET randomNumber = ? WHERE id = ?",[$world['randomNumber'] = \mt_rand(1, 10000),$world['id']]);
+			$worlds[] = $world;
+		}
+		echo \json_encode($worlds);
+	}
+	
+	private function getRandomWorld($id) {
+		return $this->db->prepareAndFetchOne('SELECT id,randomNumber FROM World WHERE id = ? LIMIT 1', [
+			$id
+		],\PDO::FETCH_ASSOC);
+	}
+}
+
+

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

@@ -0,0 +1,22 @@
+<?php
+namespace controllers;
+
+class RawFortunes extends \Ubiquity\controllers\Controller {
+	
+	public function index() {
+		$fortunes = \Ubiquity\db\Database::start()->fetchAll('SELECT id,message FROM Fortune',\PDO::FETCH_KEY_PAIR);
+		$fortunes[0] = 'Additional fortune added at request time.';
+		\asort($fortunes);
+		?>
+		<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>
+		<?php
+		foreach ($fortunes as $id => $fortune) :
+		?>
+		<tr><td><?=$id?></td><td><?=\htmlspecialchars($fortune, ENT_QUOTES, 'UTF-8')?></td></tr>
+		<?php
+		endforeach
+		?></table></body></html><?php
+	}
+}
+
+

+ 21 - 23
frameworks/PHP/ubiquity/benchmark_config.json

@@ -25,29 +25,27 @@
         "notes": "",
         "versus": "php"
       },
-      "react": {
-        "json_url": "/Json",
-        "plaintext_url": "/Plaintext",
-        "db_url": "/Db",
-        "update_url": "/Db/update/",
-        "query_url": "/Db/query/",
-        "fortune_url": "/Fortunes",
-        "port": 8080,
-        "approach": "Realistic",
-        "classification": "Fullstack",
-        "database": "MySQL",
-        "framework": "ubiquity",
-        "language": "PHP",
-        "flavor": "PHP7",
-        "orm": "Full",
-        "platform": "php-pm",
-        "webserver": "None",
-        "os": "Linux",
-        "database_os": "Linux",
-        "display_name": "ubiquity-php-pm",
-        "notes": "",
-        "versus": "php"
-      },
+      "raw": {
+            "db_url": "/Raw",
+            "query_url": "/Raw/query/",
+            "fortune_url": "/RawFortunes",
+            "update_url": "/Raw/update/",
+            "port": 8080,
+            "approach": "Realistic",
+            "classification": "Fullstack",
+            "database": "MySQL",
+            "framework": "Ubiquity",
+            "language": "PHP",
+            "flavor": "PHP7",
+            "orm": "Raw",
+            "platform": "None",
+            "webserver": "nginx",
+            "os": "Linux",
+            "database_os": "Linux",
+            "display_name": "ubiquity-raw",
+            "notes": "",
+            "versus": "php"
+          },
       "swoole": {
         "json_url": "/Json",
         "plaintext_url": "/Plaintext",

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

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

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

@@ -0,0 +1,24 @@
+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;"

+ 0 - 29
frameworks/PHP/ubiquity/ubiquity-react.dockerfile

@@ -1,29 +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 git unzip php7.3 php7.3-common php7.3-cli php7.3-mysql php7.3-mbstring php7.3-cgi > /dev/null
-
-RUN apt-get install -yqq composer > /dev/null
-
-RUN ln -s /usr/lib/cgi-bin/php /usr/bin/php7.3-cgi
-
-COPY deploy/conf/php.ini /etc/php/7.3/cgi/php.ini
-
-ADD ./ /ubiquity
-WORKDIR /ubiquity
-
-RUN composer require phpmv/ubiquity-php-pm:dev-master --quiet
-
-RUN composer install --optimize-autoloader --classmap-authoritative --no-dev --quiet
-
-RUN chmod 777 -R /ubiquity/app/cache/*
-
-RUN chmod 777 -R /ubiquity/.ubiquity/*
-
-RUN chmod 777 /ubiquity/vendor/bin/ppm
-
-CMD /ubiquity/vendor/bin/ppm --bridge='\PHPPM\Ubiquity' --bootstrap='\PHPPM\Ubiquity' start --debug 0 --logging 0 --workers 128 --max-requests 1024 --host=0.0.0.0 --port=8080