소스 검색

mongodb test

Kpacha 11 년 전
부모
커밋
49bca0a9b0

+ 15 - 6
php-phalcon/README.md

@@ -9,9 +9,10 @@ Uses the PHP standard [JSON encoder](http://www.php.net/manual/en/function.json-
 
 
 ### Data-Store/Database Mapping Test
-Uses the built-in ORM of Phalcon PHP
+Uses the built-in ORM/ODM of Phalcon PHP
 
-* [DB test controller](app/controllers/BenchController.php)
+* MySQL: [DB test controller](app/controllers/BenchController.php)
+* MongoDB: [DB test controller](app/controllers/MongobenchController.php)
 
 ### Template Test
 Uses Phalcons template engine 'Volt'
@@ -26,6 +27,7 @@ The tests were run with:
 * [PHP Version 5.4.13](http://www.php.net/) with FPM, APC and Phalcon extension
 * [nginx 1.4.0](http://nginx.org/)
 * [MySQL 5.5.29](https://dev.mysql.com/)
+* [MongoDB 2.4.8](https://mongodb.org/)
 
 ## Test URLs
 ### JSON Encoding Test
@@ -34,12 +36,19 @@ http://localhost/json
 
 ### Data-Store/Database Mapping Test
 
-http://localhost/db
+MySQL: http://localhost/db
+MongoDB: http://localhost/mongodb/db
 
 ### Variable Query Test
     
-http://localhost/db?queries=2
+MySQL: http://localhost/db?queries=2
+MongoDB: http://localhost/mongodb/db?queries=2
 
-### Templating Test
+### Update Test
+    
+MySQL: http://localhost/update
 
-http://localhost/fortunes
+### Fortunes Test
+    
+MySQL: http://localhost/fortunes
+MongoDB: http://localhost/mongodb/fortunes

+ 11 - 0
php-phalcon/app/config/routes.php

@@ -23,4 +23,15 @@ $router->add('/update', array(
     'action' => 'update',
 ));
 
+// Handles "/db" as well as "/db?queries={queries}"
+$router->add('/mongodb/db', array(
+    'controller' => 'mongobench',
+    'action' => 'db',
+));
+
+$router->add('/mongodb/fortunes', array(
+    'controller' => 'mongobench',
+    'action' => 'fortunes',
+));
+
 return $router;

+ 47 - 0
php-phalcon/app/controllers/MongobenchController.php

@@ -0,0 +1,47 @@
+<?php
+
+use Phalcon\Mvc\View,
+    Phalcon\Mvc\Model\Resultset;
+
+class MongobenchController extends BenchController
+{
+
+    protected function getRandomWorld()
+    {
+        return WorldsCollection::findFirst(array(array('_id' => mt_rand(1, 10000))));
+    }
+
+    protected function getFortunesArray()
+    {
+        return FortunesCollection::find();
+    }
+
+    protected function buildFortune()
+    {
+        $fortune = parent::buildFortune();
+        $newFortune = new FortunesCollection();
+        $newFortune->_id = $fortune['id'];
+        $newFortune->message = $fortune['message'];
+        return $newFortune;
+    }
+
+    protected function sortFortunes($fortunes)
+    {
+        usort($fortunes,
+                function($left, $right) {
+                    $l = $left->message;
+                    $r = $right->message;
+                    if ($l === $r) {
+                        return 0;
+                    } else {
+                        if ($l > $r) {
+                            return 1;
+                        } else {
+                            return -1;
+                        }
+                    }
+                });
+        return $fortunes;
+    }
+
+}

+ 1 - 0
php-phalcon/app/views/mongobench/fortunes.volt

@@ -0,0 +1 @@
+<table><tr><th>id</th><th>message</th></tr>{% for fortune in fortunes %}<tr><td>{{ fortune._id }}</td><td>{{ fortune.message | e }}</td></tr>{% endfor %}</table>

+ 21 - 0
php-phalcon/benchmark_config

@@ -22,6 +22,27 @@
       "display_name": "phalcon",
       "notes": "",
       "versus": "php"
+    },
+    "mongodb": {
+      "setup_file": "setup",
+      "db_url": "/mongodb/db",
+      "query_url": "/mongodb/db?queries=",
+      "fortune_url": "/mongodb/fortunes",
+      "update_url": "/mongodb/update?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MongoDB",
+      "framework": "phalcon",
+      "language": "PHP",
+      "orm": "Full",
+      "platform": "PHP-FPM",
+      "webserver": "nginx",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "phalcon",
+      "notes": "",
+      "versus": "php"
     }
   }]
 }