Bläddra i källkod

Add ubiquity mongo (#5954)

* update cache

* Fix World case pb with pgsql

* fix case pbs

* add quote in config (pgsql)

* Update ubiquity-workerman.dockerfile

* Update ubiquity-workerman.dockerfile

* add mongo files

* Update ubiquity-workerman.dockerfile

* add --quiet
jcheron 5 år sedan
förälder
incheckning
22f17290af

+ 26 - 1
frameworks/PHP/ubiquity/app/cache/models/CachedWorld.cache.php

@@ -1,2 +1,27 @@
 <?php
-return array("#tableName"=>"World","#primaryKeys"=>array("id"=>"id"),"#manyToOne"=>array(),"#fieldNames"=>array("id"=>"id","randomNumber"=>"randomnumber"),"#fieldTypes"=>array("id"=>"int(11)","randomNumber"=>"int(11)"),"#nullable"=>array(),"#notSerializable"=>array(),"#transformers"=>array(),"#accessors"=>array("id"=>"setId","randomNumber"=>"setRandomNumber"));
+return array(
+	"#tableName" => "world",
+	"#primaryKeys" => array(
+		"id" => "id"
+	),
+	"#manyToOne" => array(),
+	"#fieldNames" => array(
+		"id" => "id",
+		"randomNumber" => "randomNumber"
+	),
+	"#memberNames" => array(
+		"id" => "id",
+		"randomNumber" => "randomNumber"
+	),
+	"#fieldTypes" => array(
+		"id" => "int(11)",
+		"randomNumber" => "int(11)"
+	),
+	"#nullable" => array(),
+	"#notSerializable" => array(),
+	"#transformers" => array(),
+	"#accessors" => array(
+		"id" => "setId",
+		"randomNumber" => "setRandomNumber"
+	)
+);

+ 26 - 1
frameworks/PHP/ubiquity/app/cache/models/Fortune.cache.php

@@ -1,2 +1,27 @@
 <?php
-return array("#tableName"=>"Fortune","#primaryKeys"=>array("id"=>"id"),"#manyToOne"=>array(),"#fieldNames"=>array("id"=>"id","message"=>"message"),"#fieldTypes"=>array("id"=>"int(11)","message"=>"varchar(100)"),"#nullable"=>array(),"#notSerializable"=>array(),"#transformers"=>array(),"#accessors"=>array("id"=>"setId","message"=>"setMessage"));
+return array(
+	"#tableName" => "fortune",
+	"#primaryKeys" => array(
+		"id" => "id"
+	),
+	"#manyToOne" => array(),
+	"#fieldNames" => array(
+		"id" => "id",
+		"message" => "message"
+	),
+	"#memberNames" => array(
+		"id" => "id",
+		"message" => "message"
+	),
+	"#fieldTypes" => array(
+		"id" => "int(11)",
+		"message" => "varchar(100)"
+	),
+	"#nullable" => array(),
+	"#notSerializable" => array(),
+	"#transformers" => array(),
+	"#accessors" => array(
+		"id" => "setId",
+		"message" => "setMessage"
+	)
+);

+ 26 - 1
frameworks/PHP/ubiquity/app/cache/models/World.cache.php

@@ -1,2 +1,27 @@
 <?php
-return array("#tableName"=>"World","#primaryKeys"=>array("id"=>"id"),"#manyToOne"=>array(),"#fieldNames"=>array("id"=>"id","randomNumber"=>"randomnumber"),"#fieldTypes"=>array("id"=>"int(11)","randomNumber"=>"int(11)"),"#nullable"=>array(),"#notSerializable"=>array(),"#transformers"=>array(),"#accessors"=>array("id"=>"setId","randomNumber"=>"setRandomNumber"));
+return array(
+	"#tableName" => "world",
+	"#primaryKeys" => array(
+		"id" => "id"
+	),
+	"#manyToOne" => array(),
+	"#fieldNames" => array(
+		"id" => "id",
+		"randomNumber" => "randomNumber"
+	),
+	"#memberNames" => array(
+		"id" => "id",
+		"randomNumber" => "randomNumber"
+	),
+	"#fieldTypes" => array(
+		"id" => "int(11)",
+		"randomNumber" => "int(11)"
+	),
+	"#nullable" => array(),
+	"#notSerializable" => array(),
+	"#transformers" => array(),
+	"#accessors" => array(
+		"id" => "setId",
+		"randomNumber" => "setRandomNumber"
+	)
+);

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

@@ -23,7 +23,8 @@ return array(
 			"user" => "benchmarkdbuser", // benchmarkdbuser
 			"password" => "benchmarkdbpass", // benchmarkdbpass
 			"options" => [
-				\PDO::ATTR_EMULATE_PREPARES => false
+				\PDO::ATTR_EMULATE_PREPARES => false,
+				'quote' => ''
 			],
 			"cache" => false
 		],
@@ -35,6 +36,19 @@ return array(
 			"port" => 5432,
 			"user" => "benchmarkdbuser", // benchmarkdbuser
 			"password" => "benchmarkdbpass", // benchmarkdbpass
+			"options" => [
+				'quote' => ''
+			],
+			"cache" => false
+		],
+		'mongo' => [
+			"wrapper" => "\\Ubiquity\\db\\providers\\MongoDbWrapper",
+			"type" => "mongo",
+			"dbName" => "hello_world",
+			"serverName" => "tfb-database", // tfb-database
+			"port" => 27017,
+			"user" => "", // benchmarkdbuser
+			"password" => "", // benchmarkdbpass
 			"options" => [],
 			"cache" => false
 		]

+ 47 - 0
frameworks/PHP/ubiquity/app/controllers/DbMongo.php

@@ -0,0 +1,47 @@
+<?php
+namespace controllers;
+
+use Ubiquity\orm\DAONosql;
+use Ubiquity\orm\core\prepared\DAONosqlPreparedQueryById;
+use models\World;
+
+/**
+ * Bench controller.
+ */
+class DbMongo extends Db_ {
+
+	public static function warmup() {
+		self::$pDao = new DAONosqlPreparedQueryById('models\\World');
+	}
+
+	public function update($queries = 1) {
+		$worlds = [];
+		$count = $this->getCount($queries);
+		$ids = $this->getUniqueRandomNumbers($count);
+		foreach ($ids as $id) {
+			$world = self::$pDao->execute([
+				'id' => $id
+			]);
+			do {
+				$nRn = \mt_rand(1, 10000);
+			} while ($world->randomNumber === $nRn);
+			$world->randomNumber = $nRn;
+			DAONosql::toUpdate($world);
+			$worlds[] = $world->_rest;
+		}
+		DAONosql::flush(World::class, false);
+
+		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);
+	}
+}

+ 12 - 0
frameworks/PHP/ubiquity/app/controllers/FortunesMongo.php

@@ -0,0 +1,12 @@
+<?php
+namespace controllers;
+
+use Ubiquity\orm\core\prepared\DAONosqlPreparedQueryAll;
+
+class FortunesMongo extends Fortunes_ {
+
+	public static function warmup() {
+		self::$pDao = new DAONosqlPreparedQueryAll('models\\Fortune');
+	}
+}
+

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

@@ -157,6 +157,27 @@
         "display_name": "ubiquity-workerman-mysql",
         "notes": "",
         "versus": "php"
+      },
+      "workerman-mongo": {
+        "db_url": "/DbMongo",
+        "query_url": "/DbMongo/query/",
+        "fortune_url": "/FortunesMongo",
+        "update_url": "/DbMongo/update/",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "MongoDB",
+        "framework": "Ubiquity",
+        "language": "PHP",
+        "flavor": "PHP7",
+        "orm": "Full",
+        "platform": "workerman",
+        "webserver": "none",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ubiquity-workerman-mongo",
+        "notes": "",
+        "versus": "php"
       }
     }
   ]

+ 18 - 0
frameworks/PHP/ubiquity/deploy/conf/workerman/mongo/workerServices.php

@@ -0,0 +1,18 @@
+<?php
+\Ubiquity\cache\CacheManager::startProd($config);
+\Ubiquity\orm\DAONosql::setModelsDatabases([
+	'models\\Fortune' => 'mongo',
+	'models\\World' => 'mongo'
+]);
+
+\Ubiquity\cache\CacheManager::warmUpControllers([
+	\controllers\DbMongo::class,
+	\controllers\FortunesMongo::class
+]);
+
+$workerServer->onWorkerStart = function () use ($config) {
+	\Ubiquity\orm\DAONosql::startDatabase($config, 'mongo');
+	\controllers\DbMongo::warmup();
+	\controllers\FortunesMongo::warmup();
+};
+

+ 42 - 0
frameworks/PHP/ubiquity/ubiquity-workerman-mongo.dockerfile

@@ -0,0 +1,42 @@
+  
+FROM ubuntu:20.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.4 php7.4-common php7.4-cli php7.4-mongodb > /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.4/cli/conf.d/event.ini
+
+COPY deploy/conf/php-async.ini /etc/php/7.4/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:dev-nosql-prepare phpmv/ubiquity-devtools:dev-master phpmv/ubiquity-workerman:dev-master phpmv/ubiquity-nosql:dev-master --quiet
+
+RUN php composer.phar install --optimize-autoloader --classmap-authoritative --no-dev --quiet
+
+RUN chmod 777 -R /ubiquity/.ubiquity/*
+
+COPY deploy/conf/workerman/mongo/workerServices.php app/config/workerServices.php
+
+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