Browse Source

Ubiquity swoole mysql (#5468)

* Add Mysql DB controller

* Remove workerman preloading (core dump)
jcheron 5 years ago
parent
commit
6d757fde1c

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

@@ -8,6 +8,7 @@
 	'controllers\\PlaintextAsync',
 	'controllers\\PlaintextAsync',
 	'controllers\\JsonAsync',
 	'controllers\\JsonAsync',
 	'controllers\\SwooleDb',
 	'controllers\\SwooleDb',
+	'controllers\\SwooleDbMy',
 	'controllers\\SwooleFortunes'
 	'controllers\\SwooleFortunes'
 ]);
 ]);
 $swooleServer->on('workerStart', function ($srv) use (&$config) {
 $swooleServer->on('workerStart', function ($srv) use (&$config) {

+ 37 - 0
frameworks/PHP/ubiquity/app/controllers/SwooleDbMy.php

@@ -0,0 +1,37 @@
+<?php
+namespace controllers;
+
+use Ubiquity\orm\DAO;
+
+/**
+ * Bench controller.
+ */
+class SwooleDbMy extends SwooleDb {
+
+	public function update($queries = 1) {
+		$worlds = [];
+		$queries = \min(\max($queries, 1), 500);
+		$ids = $this->getUniqueRandomNumbers($queries);
+		foreach ($ids as $id) {
+			$world = DAO::executePrepared('world', [
+				'id' => $id
+			]);
+			$world->randomNumber = \mt_rand(1, 10000);
+			DAO::toUpdate($world);
+			$worlds[] = $world->_rest;
+		}
+		DAO::updateGroups($queries);
+		echo \json_encode($worlds);
+	}
+
+	private function getUniqueRandomNumbers($count) {
+		$res = [];
+		do {
+			$res[\mt_rand(1, 10000)] = 1;
+		} while (\count($res) < $count);
+
+		\ksort($res);
+
+		return \array_keys($res);
+	}
+}

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

@@ -70,6 +70,27 @@
         "display_name": "ubiquity-swoole-pgsql",
         "display_name": "ubiquity-swoole-pgsql",
         "notes": "",
         "notes": "",
         "versus": "swoole"
         "versus": "swoole"
+      },
+      "swoole-mysql": {
+        "db_url": "/SwooleDb",
+        "update_url": "/SwooleDbMy/update/",
+        "query_url": "/SwooleDb/query/",
+        "fortune_url": "/SwooleFortunes",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "MYSQL",
+        "framework": "ubiquity",
+        "language": "PHP",
+        "flavor": "PHP7",
+        "orm": "Full",
+        "platform": "swoole",
+        "webserver": "none",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity-swoole-mysql",
+        "notes": "",
+        "versus": "swoole"
       }
       }
     }
     }
   ]
   ]

+ 37 - 0
frameworks/PHP/ubiquity/ubiquity-swoole-mysql.dockerfile

@@ -0,0 +1,37 @@
+FROM php:7.4
+
+RUN apt-get update > /dev/null
+
+RUN pecl install swoole-4.4.14 > /dev/null && \
+    docker-php-ext-enable swoole
+
+RUN docker-php-ext-install pdo_mysql > /dev/null
+
+COPY deploy/conf/php-async.ini /usr/local/etc/php/php.ini
+RUN echo "zend_extension=opcache.so" >> /usr/local/etc/php/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-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/*
+
+RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /usr/local/etc/php/php.ini
+
+USER www-data
+
+RUN sed -i "s|'pgsql'|'default'|g" /ubiquity/app/config/swooleServices.php
+
+CMD /ubiquity/vendor/bin/Ubiquity serve -t=swoole -p=8080 -h=0.0.0.0

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

@@ -35,6 +35,6 @@ RUN chmod 777 -R /ubiquity/.ubiquity/*
 
 
 RUN sed -i "s|'worker'|'pgsql'|g" /ubiquity/app/config/workerServices.php
 RUN sed -i "s|'worker'|'pgsql'|g" /ubiquity/app/config/workerServices.php
 
 
-RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /etc/php/7.4/cli/php.ini
+#RUN echo "opcache.preload=/ubiquity/app/config/preloader.script.php" >> /etc/php/7.4/cli/php.ini
 
 
 CMD /ubiquity/vendor/bin/Ubiquity serve -t=workerman -p=8080 -h=0.0.0.0
 CMD /ubiquity/vendor/bin/Ubiquity serve -t=workerman -p=8080 -h=0.0.0.0