瀏覽代碼

Add Ubiquity-swoole (#4840)

* Add ubiquity-swoole server

* Update ubiquity-swoole.dockerfile

* Update ubiquity-swoole.dockerfile

* Remove transactions in ubiquity(update)

* Update Db_.php

* update php-pm (react) to 64 workers

* Update Db_.php

* add pcntl ext
jcheron 6 年之前
父節點
當前提交
108f483f20

+ 1 - 0
.gitignore

@@ -106,3 +106,4 @@ build/
 # Elixir
 _build/
 deps/
+frameworks/PHP/ubiquity/.buildpath

+ 18 - 0
frameworks/PHP/ubiquity/.ubiquity/_swoole.php

@@ -0,0 +1,18 @@
+#!/usr/bin/env php
+<?php
+// swoole.php
+
+if (! defined ( 'DS' )) {
+	define ( 'DS', DIRECTORY_SEPARATOR );
+	define ( 'ROOT', __DIR__ . \DS .'..'.\DS. 'app' . \DS );
+}
+$config=include ROOT.'config/config.php';
+$sConfig= include __DIR__.\DS.'swoole-config.php';
+$config["sessionName"]=$sConfig["sessionName"];
+$address=$sConfig['host'].':'.$sConfig['port'];
+$config ["siteUrl"] = 'http://'.$address;
+require ROOT . './../vendor/autoload.php';
+require ROOT.'config/services.php';
+$reactServer=new \Ubiquity\servers\swoole\SwooleServer();
+$reactServer->init($config, __DIR__);
+$reactServer->run($sConfig['host'],$sConfig['port']);

+ 5 - 0
frameworks/PHP/ubiquity/.ubiquity/swoole-config.php

@@ -0,0 +1,5 @@
+<?php
+return array(
+	"host" => "0.0.0.0",
+	"port" => 8080
+);

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

@@ -5,7 +5,7 @@ Ubiquity is a full-stack php framework, These tests involve:
 - the ORM part (Full)
 - the JSON serialization (native php)
 
-Tests are available with NginX and PHP-PM servers.
+Tests are available with NginX, Swoole and PHP-PM (beta) servers.
 
 ## Test Type Implementation Source Code
 The tests are separated into 4 controllers:
@@ -30,11 +30,13 @@ The tests were run with:
 * [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: 32
+- workers: 64
 - max-requests: 1024
 
 ## Test URLs

+ 21 - 7
frameworks/PHP/ubiquity/app/controllers/Db_.php

@@ -3,15 +3,29 @@ namespace controllers;
 
 use Ubiquity\controllers\Startup;
 use Ubiquity\utils\http\UResponse;
-
+use Ubiquity\orm\DAO;
+use models\World;
 
 /**
  * Bench controller.
- **/
-class Db_ extends Db{
-	public function initialize(){
-		UResponse::setContentType( 'application/json' );
-		$config=Startup::getConfig();
-		\Ubiquity\orm\DAO::startDatabase($config);
+ */
+class Db_ extends Db {
+
+	public function initialize() {
+		UResponse::setContentType('application/json');
+		$config = Startup::getConfig();
+		DAO::startDatabase($config);
+	}
+
+	public function update($queries = 1) {
+		$worlds = [];
+		$queries = is_numeric($queries) ? min(max($queries, 1), 500) : 1;
+		for ($i = 0; $i < $queries; ++ $i) {
+			$world = DAO::getById(World::class, mt_rand(1, 10000), false);
+			$world->setRandomNumber(mt_rand(1, 10000));
+			DAO::update($world);
+			$worlds[] = $world->_rest;
+		}
+		echo \json_encode($worlds);
 	}
 }

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

@@ -47,6 +47,29 @@
         "display_name": "ubiquity-php-pm",
         "notes": "",
         "versus": "php"
+      },
+      "swoole": {
+        "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": "None",
+        "webserver": "swoole",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity-swoole",
+        "notes": "",
+        "versus": "php"
       }
     }
   ]

+ 2 - 0
frameworks/PHP/ubiquity/deploy/conf/php-swoole.ini

@@ -0,0 +1,2 @@
+opcache.enable_cli=1
+opcache.validate_timestamps=0

+ 17 - 0
frameworks/PHP/ubiquity/deploy/run/install-composer.sh

@@ -0,0 +1,17 @@
+#!/bin/sh
+
+EXPECTED_SIGNATURE="$(curl -s https://composer.github.io/installer.sig)"
+php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
+ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"
+
+if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
+then
+    >&2 echo 'ERROR: Invalid installer signature'
+    rm composer-setup.php
+    exit 1
+fi
+
+php composer-setup.php --quiet
+RESULT=$?
+rm composer-setup.php
+exit $RESULT

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

@@ -26,4 +26,4 @@ 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 32 --max-requests 1024 --host=0.0.0.0 --port=8080
+CMD /ubiquity/vendor/bin/ppm --bridge='\PHPPM\Ubiquity' --bootstrap='\PHPPM\Ubiquity' start --debug 0 --logging 0 --workers 64 --max-requests 1024 --host=0.0.0.0 --port=8080

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

@@ -0,0 +1,32 @@
+FROM php:7.3
+
+ENV SWOOLE_VERSION=4.3.4
+
+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 docker-php-ext-install pdo_mysql pcntl > /dev/null
+
+COPY deploy/conf/php-swoole.ini /usr/local/etc/php/
+
+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-master phpmv/ubiquity-swoole:dev-master --quiet
+
+RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+
+RUN chmod 777 -R /ubiquity/.ubiquity/*
+
+CMD /ubiquity/vendor/bin/Ubiquity serve -t=swoole -p=8080 -h=0.0.0.0