Răsfoiți Sursa

add simps orm (#5632)

test ci
Luffy 5 ani în urmă
părinte
comite
940020fbf1

+ 54 - 1
frameworks/PHP/simps/app/Controller/IndexController.php

@@ -11,8 +11,8 @@ declare(strict_types=1);
 
 
 namespace App\Controller;
 namespace App\Controller;
 
 
-use Simps\Server\Protocol\HTTP\SimpleResponse;
 use App\Model\DbModel;
 use App\Model\DbModel;
+use Simps\Server\Protocol\HTTP\SimpleResponse;
 
 
 class IndexController
 class IndexController
 {
 {
@@ -120,4 +120,57 @@ class IndexController
             )
             )
         );
         );
     }
     }
+
+    public function microDb($server, $fd)
+    {
+        $db = new DbModel();
+        $res = $db->microDb();
+
+        $server->send(
+            $fd,
+            SimpleResponse::build(
+                $res,
+                200,
+                ['Content-Type' => 'application/json', 'Date' => gmdate("D, d M Y H:i:s T")]
+            )
+        );
+    }
+
+    public function microQueries($server, $fd, $data)
+    {
+        $db = new DbModel();
+        if (isset($data['queries'])) {
+            $res = $db->microQueries((int)$data['queries']);
+        } else {
+            $res = $db->microQueries();
+        }
+
+        $server->send(
+            $fd,
+            SimpleResponse::build(
+                $res,
+                200,
+                ['Content-Type' => 'application/json', 'Date' => gmdate("D, d M Y H:i:s T")]
+            )
+        );
+    }
+
+    public function microUpdates($server, $fd, $data)
+    {
+        $db = new DbModel();
+        if (isset($data['queries'])) {
+            $res = $db->microUpdates((int)$data['queries']);
+        } else {
+            $res = $db->microUpdates();
+        }
+
+        $server->send(
+            $fd,
+            SimpleResponse::build(
+                $res,
+                200,
+                ['Content-Type' => 'application/json', 'Date' => gmdate("D, d M Y H:i:s T")]
+            )
+        );
+    }
 }
 }

+ 87 - 0
frameworks/PHP/simps/app/Model/DbModel.php

@@ -94,4 +94,91 @@ class DbModel extends BaseModel
 
 
         return \json_encode($arr, JSON_NUMERIC_CHECK);
         return \json_encode($arr, JSON_NUMERIC_CHECK);
     }
     }
+
+    public function microDb()
+    {
+        $id = mt_rand(1, 10000);
+        $data = $this->get(
+            "World",
+            [
+                'id',
+                'randomNumber'
+            ],
+            [
+                "id" => $id
+            ]
+        );
+        return \json_encode($data, JSON_NUMERIC_CHECK);
+    }
+
+    public function microQueries(int $queries = 0)
+    {
+        $query_count = 1;
+        if ($queries > 1) {
+            $query_count = $queries > 500 ? 500 : $queries;
+        }
+
+        $arr = [];
+
+        while ($query_count--) {
+            $id = mt_rand(1, 10000);
+            $data = $this->get(
+                "World",
+                [
+                    'id',
+                    'randomNumber'
+                ],
+                [
+                    "id" => $id
+                ]
+            );
+
+            // Store result in array.
+            $arr[] = $data;
+        }
+
+        return \json_encode($arr, JSON_NUMERIC_CHECK);
+    }
+
+    public function microUpdates(int $queries = 0)
+    {
+        $query_count = 1;
+        if ($queries > 1) {
+            $query_count = $queries > 500 ? 500 : $queries;
+        }
+
+        $arr = [];
+
+        while ($query_count--) {
+            $id = mt_rand(1, 10000);
+            $randomNumber = mt_rand(1, 10000);
+            $data = $this->get(
+                "World",
+                [
+                    'id',
+                    'randomNumber'
+                ],
+                [
+                    "id" => $id
+                ]
+            );
+
+            $world = ['id' => $id, 'randomNumber' => $data['randomNumber']];
+            $world['randomNumber'] = $randomNumber;
+
+            $this->update(
+                "World",
+                [
+                    'randomNumber' => $randomNumber
+                ],
+                [
+                    "id" => $id
+                ]
+            );
+
+            $arr[] = $world;
+        }
+
+        return \json_encode($arr, JSON_NUMERIC_CHECK);
+    }
 }
 }

+ 20 - 0
frameworks/PHP/simps/benchmark_config.json

@@ -24,6 +24,26 @@
         "display_name": "Simps",
         "display_name": "Simps",
         "notes": "",
         "notes": "",
         "versus": "swoole"
         "versus": "swoole"
+      },
+      "micro": {
+        "db_url": "/micro-db",
+        "query_url": "/micro-queries/",
+        "update_url": "/micro-updates/",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "MySQL",
+        "framework": "Simps",
+        "language": "PHP",
+        "flavor": "None",
+        "orm": "Micro",
+        "platform": "swoole",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Simps",
+        "notes": "",
+        "versus": "swoole"
       }
       }
     }
     }
   ]
   ]

+ 3 - 0
frameworks/PHP/simps/config/routes.php

@@ -16,4 +16,7 @@ return [
     ['GET', '/db', '\App\Controller\IndexController@db'],
     ['GET', '/db', '\App\Controller\IndexController@db'],
     ['GET', '/queries/[{queries}]', '\App\Controller\IndexController@queries'],
     ['GET', '/queries/[{queries}]', '\App\Controller\IndexController@queries'],
     ['GET', '/updates/[{queries}]', '\App\Controller\IndexController@updates'],
     ['GET', '/updates/[{queries}]', '\App\Controller\IndexController@updates'],
+    ['GET', '/micro-db', '\App\Controller\IndexController@microDb'],
+    ['GET', '/micro-queries/[{queries}]', '\App\Controller\IndexController@microQueries'],
+    ['GET', '/micro-updates/[{queries}]', '\App\Controller\IndexController@microUpdates'],
 ];
 ];

+ 20 - 0
frameworks/PHP/simps/simps-micro.dockerfile

@@ -0,0 +1,20 @@
+FROM php:7.4
+
+RUN pecl install swoole > /dev/null && \
+    docker-php-ext-enable swoole
+
+RUN docker-php-ext-install pdo_mysql > /dev/null
+
+RUN apt -yqq update > /dev/null && \
+    apt -yqq install git unzip > /dev/null
+
+WORKDIR /simps
+
+COPY . /simps
+COPY php.ini /usr/local/etc/php/
+
+RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
+RUN composer install --no-dev --classmap-authoritative --quiet > /dev/null
+RUN composer dumpautoload -o
+
+CMD php sbin/simps.php http:start