Browse Source

Add ubiquity with roadrunner (#5534)

* code refactoring

* Add roadrunner files

* Fix typo

* add --quiet for composer
jcheron 5 years ago
parent
commit
5def1271be

+ 22 - 0
frameworks/PHP/ubiquity/.ubiquity/.rr.yml

@@ -0,0 +1,22 @@
+http:
+  address:         "0.0.0.0:8080"
+  workers.command: "php-cgi ./.ubiquity/_roadrunner.php"
+  workers:
+    pool:
+      # Set numWorkers to 1 while debugging
+      numWorkers: ${NUM_WORKERS}
+      maxJobs:    0
+
+# static file serving. remove this section to disable static file serving.
+static:
+  # root directory for static file (http would not serve .php and .htaccess files).
+  dir:   "."
+
+  # list of extensions for forbid for serving.
+  forbid: [".php", ".htaccess", ".yml"]
+
+  always: [".ico", ".html", ".css", ".js"]
+
+headers:
+  response:
+    "Server": "RoadRunner"

+ 23 - 0
frameworks/PHP/ubiquity/.ubiquity/_roadrunner.php

@@ -0,0 +1,23 @@
+<?php
+use RoadRunnerUbiquity\Request;
+use Ubiquity\controllers\StartupAsync;
+
+define ( 'DS', DIRECTORY_SEPARATOR );
+define ( 'ROOT', __DIR__ . DS . '..' . DS . 'app' . DS );
+
+ini_set ( 'display_errors', 'stderr' );
+ini_set ( 'max_execution_time', 0 );
+
+$config = include_once ROOT . 'config/config.php';
+$config ['siteUrl'] = 'http://127.0.0.1:8080/';
+
+require_once ROOT . '../vendor/autoload.php';
+require_once ROOT . 'config/rrServices.php';
+
+$request = new Request ( $config );
+StartupAsync::init ( $config );
+
+while ( $request->acceptRequest () ) {
+	StartupAsync::forward ( $request->ubiquityRoute () );
+	$request->sendResponse ()->garbageCollect ();
+}

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

@@ -5,10 +5,10 @@
 	'models\\World' => 'pgsql'
 	'models\\World' => 'pgsql'
 ]);
 ]);
 \Ubiquity\cache\CacheManager::warmUpControllers([
 \Ubiquity\cache\CacheManager::warmUpControllers([
-	'controllers\\PlaintextAsync',
-	'controllers\\JsonAsync',
-	'controllers\\WorkerDb',
-	'controllers\\WorkerFortunes'
+	'controllers\\Plaintext_',
+	'controllers\\Json_',
+	'controllers\\DbPg',
+	'controllers\\Fortunes_'
 ]);
 ]);
 $workerServer->onWorkerStart = function () use ($config) {
 $workerServer->onWorkerStart = function () use ($config) {
 	\Ubiquity\orm\DAO::startDatabase($config, 'pgsql');
 	\Ubiquity\orm\DAO::startDatabase($config, 'pgsql');

+ 1 - 1
frameworks/PHP/ubiquity/app/controllers/SwooleDbMy.php → frameworks/PHP/ubiquity/app/controllers/DbMy.php

@@ -6,7 +6,7 @@ use Ubiquity\orm\DAO;
 /**
 /**
  * Bench controller.
  * Bench controller.
  */
  */
-class SwooleDbMy extends SwooleDb {
+class DbMy extends DbPg {
 
 
 	public function update($queries = 1) {
 	public function update($queries = 1) {
 		$worlds = [];
 		$worlds = [];

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

@@ -6,7 +6,7 @@ use Ubiquity\orm\DAO;
 /**
 /**
  * Bench controller.
  * Bench controller.
  */
  */
-class WorkerDb extends \Ubiquity\controllers\Controller {
+class DbPg extends \Ubiquity\controllers\Controller {
 
 
 	public function __construct() {}
 	public function __construct() {}
 
 

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

@@ -3,7 +3,7 @@ namespace controllers;
 
 
 use models\Fortune;
 use models\Fortune;
 
 
-class WorkerFortunes extends \Ubiquity\controllers\SimpleViewAsyncController {
+class Fortunes_ extends \Ubiquity\controllers\SimpleViewAsyncController {
 
 
 	public function initialize() {
 	public function initialize() {
 		\Ubiquity\utils\http\UResponse::setContentType('text/html', 'utf-8');
 		\Ubiquity\utils\http\UResponse::setContentType('text/html', 'utf-8');

+ 1 - 1
frameworks/PHP/ubiquity/app/controllers/JsonAsync.php → frameworks/PHP/ubiquity/app/controllers/Json_.php

@@ -4,7 +4,7 @@ namespace controllers;
 /**
 /**
  * Json controller.
  * Json controller.
  */
  */
-class JsonAsync extends \Ubiquity\controllers\Controller {
+class Json_ extends \Ubiquity\controllers\Controller {
 
 
 	public function __construct() {}
 	public function __construct() {}
 
 

+ 1 - 1
frameworks/PHP/ubiquity/app/controllers/PlaintextAsync.php → frameworks/PHP/ubiquity/app/controllers/Plaintext_.php

@@ -4,7 +4,7 @@ namespace controllers;
 /**
 /**
  * Plaintext controller.
  * Plaintext controller.
  */
  */
-class PlaintextAsync extends \Ubiquity\controllers\Controller {
+class Plaintext_ extends \Ubiquity\controllers\Controller {
 
 
 	public function __construct() {}
 	public function __construct() {}
 
 

+ 0 - 49
frameworks/PHP/ubiquity/app/controllers/SwooleDb.php

@@ -1,49 +0,0 @@
-<?php
-namespace controllers;
-
-use Ubiquity\orm\DAO;
-
-/**
- * Bench controller.
- */
-class SwooleDb extends \Ubiquity\controllers\Controller {
-
-	public function __construct() {}
-
-	public function initialize() {
-		\Ubiquity\utils\http\UResponse::setContentType('application/json');
-	}
-
-	public function index() {
-		$world = DAO::executePrepared('world', [
-			'id' => \mt_rand(1, 10000)
-		]);
-		echo \json_encode($world->_rest);
-	}
-
-	public function query($queries = 1) {
-		$worlds = [];
-		$queries = \min(\max($queries, 1), 500);
-		for ($i = 0; $i < $queries; ++ $i) {
-			$worlds[] = (DAO::executePrepared('world', [
-				'id' => \mt_rand(1, 10000)
-			]))->_rest;
-		}
-		echo \json_encode($worlds);
-	}
-
-	public function update($queries = 1) {
-		$worlds = [];
-		$queries = \min(\max($queries, 1), 500);
-		for ($i = 0; $i < $queries; ++ $i) {
-			$world = DAO::executePrepared('world', [
-				'id' => \mt_rand(1, 10000)
-			]);
-			$world->randomNumber = \mt_rand(1, 10000);
-			DAO::toUpdate($world);
-			$worlds[] = $world->_rest;
-		}
-		DAO::flushUpdates();
-		echo \json_encode($worlds);
-	}
-}

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

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

+ 57 - 13
frameworks/PHP/ubiquity/benchmark_config.json

@@ -26,12 +26,12 @@
         "versus": "php"
         "versus": "php"
       },
       },
       "workerman": {
       "workerman": {
-        "json_url": "/JsonAsync",
-        "plaintext_url": "/PlaintextAsync",
-        "db_url": "/WorkerDb",
-        "query_url": "/WorkerDb/query/",
-        "fortune_url": "/WorkerFortunes",
-        "update_url": "/WorkerDb/update/",
+        "json_url": "/Json_",
+        "plaintext_url": "/Plaintext_",
+        "db_url": "/DbPg",
+        "query_url": "/DbPg/query/",
+        "fortune_url": "/Fortunes_",
+        "update_url": "/DbPg/update/",
         "port": 8080,
         "port": 8080,
         "approach": "Realistic",
         "approach": "Realistic",
         "classification": "Fullstack",
         "classification": "Fullstack",
@@ -49,12 +49,12 @@
         "versus": "workerman"
         "versus": "workerman"
       },
       },
       "swoole": {
       "swoole": {
-        "json_url": "/JsonAsync",
-        "plaintext_url": "/PlaintextAsync",
-        "db_url": "/SwooleDb",
-        "update_url": "/SwooleDb/update/",
-        "query_url": "/SwooleDb/query/",
-        "fortune_url": "/SwooleFortunes",
+        "json_url": "/Json_",
+        "plaintext_url": "/Plaintext_",
+        "db_url": "/DbPg",
+        "update_url": "/DbPg/update/",
+        "query_url": "/DbPg/query/",
+        "fortune_url": "/Fortunes_",
         "port": 8080,
         "port": 8080,
         "approach": "Realistic",
         "approach": "Realistic",
         "classification": "Fullstack",
         "classification": "Fullstack",
@@ -72,7 +72,7 @@
         "versus": "swoole"
         "versus": "swoole"
       },
       },
       "swoole-mysql": {
       "swoole-mysql": {
-        "update_url": "/SwooleDbMy/update/",
+        "update_url": "/DbMy/update/",
         "port": 8080,
         "port": 8080,
         "approach": "Realistic",
         "approach": "Realistic",
         "classification": "Fullstack",
         "classification": "Fullstack",
@@ -108,6 +108,50 @@
         "display_name": "ubiquity-swoole-mysql",
         "display_name": "ubiquity-swoole-mysql",
         "notes": "",
         "notes": "",
         "versus": "swoole"
         "versus": "swoole"
+      },
+      "roadrunner": {
+        "json_url": "/Json_",
+        "plaintext_url": "/Plaintext_",
+        "db_url": "/DbPg",
+        "query_url": "/DbPg/query/",
+        "fortune_url": "/Fortunes_",
+        "update_url": "/DbPg/update/",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "Postgres",
+        "framework": "Ubiquity",
+        "language": "PHP",
+        "flavor": "PHP7",
+        "orm": "Full",
+        "platform": "RoadRunner",
+        "webserver": "none",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity-roadrunner",
+        "notes": "",
+        "versus": "php"
+      },
+      "roadrunner-mysql": {
+        "db_url": "/DbMy",
+        "query_url": "/DbMy/query/",
+        "fortune_url": "/Fortunes_",
+        "update_url": "/DbMy/update/",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "Mysql",
+        "framework": "Ubiquity",
+        "language": "PHP",
+        "flavor": "PHP7",
+        "orm": "Full",
+        "platform": "RoadRunner",
+        "webserver": "none",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity-roadrunner-mysql",
+        "notes": "",
+        "versus": "php"
       }
       }
     }
     }
   ]
   ]

+ 3 - 0
frameworks/PHP/ubiquity/deploy/roadrunner/envwrapper.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+export NUM_WORKERS=$(($(nproc)*3))
+$*

+ 17 - 0
frameworks/PHP/ubiquity/deploy/roadrunner/rrMysqlServices.php

@@ -0,0 +1,17 @@
+<?php
+\Ubiquity\cache\CacheManager::startProd($config);
+
+\Ubiquity\orm\DAO::setModelsDatabases([
+	'models\\World' => 'default',
+	'models\\Fortune' => 'default'
+]);
+
+\Ubiquity\cache\CacheManager::warmUpControllers([
+	'controllers\\DbMy',
+	'controllers\\Fortunes_'
+]);
+
+\Ubiquity\orm\DAO::startDatabase($config, 'default');
+\Ubiquity\orm\DAO::prepareGetById('world', 'models\\World');
+\Ubiquity\orm\DAO::prepareGetAll('fortune', 'models\\Fortune');
+

+ 16 - 0
frameworks/PHP/ubiquity/deploy/roadrunner/rrPgsqlServices.php

@@ -0,0 +1,16 @@
+<?php
+\Ubiquity\cache\CacheManager::startProd($config);
+\Ubiquity\orm\DAO::setModelsDatabases([
+	'models\\Fortune' => 'pgsql',
+	'models\\World' => 'pgsql'
+]);
+\Ubiquity\cache\CacheManager::warmUpControllers([
+	'controllers\\Plaintext_',
+	'controllers\\Json_',
+	'controllers\\DbPg',
+	'controllers\\Fortunes_'
+]);
+
+\Ubiquity\orm\DAO::startDatabase($config, 'pgsql');
+\Ubiquity\orm\DAO::prepareGetById('world', 'models\\World');
+\Ubiquity\orm\DAO::prepareGetAll('fortune', 'models\\Fortune');

+ 1 - 1
frameworks/PHP/ubiquity/deploy/swoole/swooleMysqlServices.php

@@ -4,7 +4,7 @@
 	'models\\World' => 'default'
 	'models\\World' => 'default'
 ]);
 ]);
 \Ubiquity\cache\CacheManager::warmUpControllers([
 \Ubiquity\cache\CacheManager::warmUpControllers([
-	'controllers\\SwooleDbMy'
+	'controllers\\DbMy'
 ]);
 ]);
 $swooleServer->on('workerStart', function ($srv) use (&$config) {
 $swooleServer->on('workerStart', function ($srv) use (&$config) {
 	\Ubiquity\orm\DAO::startDatabase($config, 'default');
 	\Ubiquity\orm\DAO::startDatabase($config, 'default');

+ 4 - 4
frameworks/PHP/ubiquity/deploy/swoole/swoolePgsqlServices.php

@@ -5,10 +5,10 @@
 	'models\\World' => 'pgsql'
 	'models\\World' => 'pgsql'
 ]);
 ]);
 \Ubiquity\cache\CacheManager::warmUpControllers([
 \Ubiquity\cache\CacheManager::warmUpControllers([
-	'controllers\\PlaintextAsync',
-	'controllers\\JsonAsync',
-	'controllers\\SwooleDb',
-	'controllers\\SwooleFortunes'
+	'controllers\\Plaintext_',
+	'controllers\\Json_',
+	'controllers\\DbPg',
+	'controllers\\Fortunes_'
 ]);
 ]);
 $swooleServer->on('workerStart', function ($srv) use (&$config) {
 $swooleServer->on('workerStart', function ($srv) use (&$config) {
 	\Ubiquity\orm\DAO::startDatabase($config, 'pgsql');
 	\Ubiquity\orm\DAO::startDatabase($config, 'pgsql');

+ 44 - 0
frameworks/PHP/ubiquity/ubiquity-roadrunner-mysql.dockerfile

@@ -0,0 +1,44 @@
+FROM ubuntu:19.10
+
+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.4 php7.4-common php7.4-cgi php7.4-pgsql php-curl php7.4-mysql > /dev/null
+
+RUN apt-get install -yqq composer > /dev/null
+
+RUN apt-get install -y php-pear php-dev > /dev/null
+
+COPY deploy/conf/php-async.ini /etc/php/7.4/cgi/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 lapinskas/roadrunner-ubiquity:dev-master --quiet
+
+RUN vendor/bin/rr get
+
+RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+
+COPY deploy/roadrunner/envwrapper.sh /bin/
+RUN ln -s /ubiquity/.ubiquity/.rr.yml /ubiquity/.rr.yml
+RUN chmod 755 /bin/envwrapper.sh
+
+RUN chmod 777 -R /ubiquity/.ubiquity/*
+
+#RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /etc/php/7.4/cgi/php.ini
+
+COPY deploy/roadrunner/rrMysqlServices.php app/config/rrServices.php
+
+CMD envwrapper.sh /ubiquity/rr serve

+ 46 - 0
frameworks/PHP/ubiquity/ubiquity-roadrunner.dockerfile

@@ -0,0 +1,46 @@
+  
+FROM ubuntu:19.10
+
+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.4 php7.4-common php7.4-cgi php7.4-pgsql php-curl > /dev/null
+
+RUN apt-get install -yqq composer > /dev/null
+
+RUN apt-get install -y php-pear php-dev > /dev/null
+
+
+COPY deploy/conf/php-async.ini /etc/php/7.4/cgi/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 lapinskas/roadrunner-ubiquity:dev-master --quiet
+
+RUN vendor/bin/rr get
+
+RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+
+COPY deploy/roadrunner/envwrapper.sh /bin/
+RUN ln -s /ubiquity/.ubiquity/.rr.yml /ubiquity/.rr.yml
+RUN chmod 755 /bin/envwrapper.sh
+
+RUN chmod 777 -R /ubiquity/.ubiquity/*
+
+#RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /etc/php/7.4/cgi/php.ini
+
+COPY deploy/roadrunner/rrPgsqlServices.php app/config/rrServices.php
+
+CMD envwrapper.sh /ubiquity/rr serve