Browse Source

hapi - update tests

Valentin Agachi 12 years ago
parent
commit
9456e36701
3 changed files with 83 additions and 0 deletions
  1. 9 0
      hapi/README.md
  2. 72 0
      hapi/app.js
  3. 2 0
      hapi/benchmark_config

+ 9 - 0
hapi/README.md

@@ -43,3 +43,12 @@ http://localhost:8080/mysql-orm/2
 
 MySQL:
 http://localhost:8080/fortune
+
+### Database Update Test
+
+MongoDB:
+http://localhost:8080/mongoose-update/2
+
+MySQL:
+http://localhost:8080/mysql-orm-update/2
+

+ 72 - 0
hapi/app.js

@@ -119,5 +119,77 @@ if (cluster.isMaster) {
 		}
 	});
 
+	server.route({
+		method: 'GET',
+		path: '/mongoose-update/{queries?}',
+		handler: function(req){
+			var queries = req.params.queries || 1,
+				selectFunctions = [];
+
+			queries = Math.max(Math.min(queries, 500), 1);
+
+			for (var i = 1; i <= queries; i++) {
+				selectFunctions.push(function(callback){
+					MWorld.findOne({ id: Math.floor(Math.random() * 10000) + 1 }).exec(callback);
+				});
+			}
+
+			async.parallel(selectFunctions, function(err, worlds) {
+				var updateFunctions = [];
+
+				for (var i = 0; i < queries; i++) {
+					(function(i){
+						updateFunctions.push(function(callback){
+							worlds[i].randomNumber = Math.ceil(Math.random() * 10000);
+							MWorld.update({
+								id: worlds[i]
+							}, {
+								randomNumber: worlds[i].randomNumber
+							}, callback);
+						});
+					})(i);
+				}
+
+				async.parallel(updateFunctions, function(err, updates) {
+					req.reply(worlds).header('Server', 'hapi');
+				});
+			});
+		}		
+	});
+
+	server.route({
+		method: 'GET',
+		path: '/mysql-orm-update/{queries?}',
+		handler: function(req){
+			var queries = req.params.queries || 1,
+				selectFunctions = [];
+
+			queries = Math.max(Math.min(queries, 500), 1);
+
+			for (var i = 1; i <= queries; i++) {
+				selectFunctions.push(function(callback){
+					World.findById(Math.floor(Math.random() * 10000) + 1, callback);
+				});
+			}
+
+			async.parallel(selectFunctions, function(err, worlds) {
+				var updateFunctions = [];
+
+				for (var i = 0; i < queries; i++) {
+					(function(i){
+						updateFunctions.push(function(callback){
+							worlds[i].randomNumber = Math.ceil(Math.random() * 10000);
+							World.save(worlds[i], callback);
+						});
+					})(i);
+				}
+
+				async.parallel(updateFunctions, function(err, updates) {
+					req.reply(worlds).header('Server', 'hapi');
+				});
+			});
+		}
+	});
+
 	server.start();
 }

+ 2 - 0
hapi/benchmark_config

@@ -11,6 +11,7 @@
       "setup_file": "setup",
       "db_url": "/mongoose/",
       "query_url": "/mongoose/",
+      "update_url": "/mongoose-update/",
       "port": 8080,
       "sort": 119
     },
@@ -19,6 +20,7 @@
       "db_url": "/mysql-orm/",
       "query_url": "/mysql-orm/",
       "fortune_url": "/fortune",
+      "update_url": "/mysql-orm-update/",
       "port": 8080,
       "sort": 120
     }