Browse Source

Mitol server tests for NodeJS framework (#2695)

* Mitol server implementation added

* Mitol server implementation added

* Readme updated
Marko Biškup 8 years ago
parent
commit
e6fc67ceb4

+ 5 - 1
frameworks/JavaScript/nodejs/README.md

@@ -10,6 +10,10 @@ The logic for the test cases live in these.
 * [MongoDB raw](handlers/mongodb-raw.js)
 * [Mongoose (MySQL)](handlers/mongoose.js)
 
+### Alternative server Test
+This test suite also contains tests using an alternative http server. [Mitol](https://github.com/Helidium/Mitol) is a NodeJS addon written in C++.
+The server is currently in Alpha state, but aims to be a drop-in replacement for high performance demands.
+
 ## Infrastructure Software Versions
 The tests were run with:
 * [Node.js v7.5.0](http://nodejs.org/)
@@ -25,4 +29,4 @@ See the [Benchmark config](benchmark_config.json) file for a list of the tested
 
 `/json` and `/plaintext` are implemented
 
-The four db-required tests, Single Query, Multiple Query, Fortunes, and Updates have been implemented for each of the 5 database approaches that this test covers
+The four db-required tests, Single Query, Multiple Query, Fortunes, and Updates have been implemented for each of the 5 database approaches that this test covers.

+ 19 - 0
frameworks/JavaScript/nodejs/app-mitol.js

@@ -0,0 +1,19 @@
+const cluster = require('cluster');
+const numCPUs = require('os').cpus().length;
+
+if (cluster.isMaster) {
+  // Fork workers.
+  for (let i = 0; i < numCPUs; i++) {
+    cluster.fork();
+  }
+
+  cluster.on('exit', (worker, code, signal) => {
+  	console.log([
+  	  'A process exit was triggered, most likely due to a failed database action',
+  	  'NodeJS test server shutting down now'].join('\n'));
+    process.exit(1);
+  });
+} else {
+  // Task for forked worker
+  require('./create-server-mitol');
+}

+ 112 - 1
frameworks/JavaScript/nodejs/benchmark_config.json

@@ -111,6 +111,117 @@
       "display_name": "nodejs",
       "notes": "",
       "versus": "nodejs"
-    }
+    },
+    "default-mitol": {
+      "setup_file": "setup-mitol",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "db_url": "/mysql/db",
+      "query_url": "/mysql/queries?queries=",
+      "update_url": "/mysql/updates?queries=",
+      "fortune_url": "/mysql/fortunes",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MySQL",
+      "framework": "None",
+      "language": "JavaScript",
+      "flavor": "NodeJS",
+      "orm": "Raw",
+      "platform": "nodejs",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "nodejs-mitol",
+      "notes": "",
+      "versus": "nodejs"
+    },
+    "mongodb-mitol": {
+      "setup_file": "setup-mitol",
+      "db_url": "/mongoose/db",
+      "query_url": "/mongoose/queries?queries=",
+      "update_url": "/mongoose/updates?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MongoDB",
+      "framework": "None",
+      "language": "JavaScript",
+      "flavor": "NodeJS",
+      "orm": "Full",
+      "platform": "nodejs",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "nodejs-mitol",
+      "notes": "",
+      "versus": "nodejs"
+    },
+    "mongodb-raw-mitol": {
+      "setup_file": "setup-mitol",
+      "db_url": "/mongodb/db",
+      "query_url": "/mongodb/queries?queries=",
+      "update_url": "/mongodb/updates?queries=",
+      "fortune_url": "/mongodb/fortunes",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MongoDB",
+      "framework": "None",
+      "language": "JavaScript",
+      "flavor": "NodeJS",
+      "orm": "Raw",
+      "platform": "nodejs",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "nodejs-mitol",
+      "notes": "",
+      "versus": "nodejs"
+    },
+    "mysql-mitol": {
+      "setup_file": "setup-mitol",
+      "db_url": "/sequelize/db",
+      "query_url": "/sequelize/queries?queries=",
+      "update_url": "/sequelize/updates?queries=",
+      "fortune_url": "/sequelize/fortunes",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MySQL",
+      "framework": "None",
+      "language": "JavaScript",
+      "flavor": "NodeJS",
+      "orm": "Full",
+      "platform": "nodejs",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "nodejs-mitol",
+      "notes": "",
+      "versus": "nodejs"
+    },
+    "postgres-mitol": {
+      "setup_file": "setup-mitol",
+      "db_url": "/sequelize-pg/db",
+      "query_url": "/sequelize-pg/queries?queries=",
+      "update_url": "/sequelize-pg/updates?queries=",
+      "fortune_url": "/sequelize-pg/fortunes",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "Postgres",
+      "framework": "None",
+      "language": "JavaScript",
+      "flavor": "NodeJS",
+      "orm": "Full",
+      "platform": "nodejs",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "nodejs-mitol",
+      "notes": "",
+      "versus": "nodejs"
+    }    
   }]
 }

+ 33 - 0
frameworks/JavaScript/nodejs/create-server-mitol.js

@@ -0,0 +1,33 @@
+// Forked workers will run this code when found to not be
+// the master of the cluster.
+
+const http = require('mns');
+const parseurl = require('parseurl'); // faster than native nodejs url package
+
+// Initialize routes & their handlers (once)
+const routing = require('./routing');
+const basicHandler = routing.BasicHandler;
+const queryHandler = routing.QueryHandler;
+const routeNotImplemented = require('./helper').responses.routeNotImplemented;
+
+module.exports = http.createServer(function (req, res) {
+  const url = parseurl(req);
+  const route = url.pathname;
+
+  // Routes that do no require a `queries` parameter
+  if (basicHandler.has(route)) {
+    return basicHandler.handle(route, req, res);
+  } else {
+    // naive: only works if there is one query param, as is the case in TFB
+    let queries = url.query && url.query.split('=')[1];
+    queries = ~~(queries) || 1;
+    queries = Math.min(Math.max(queries, 1), 500);
+
+    if (queryHandler.has(route)) {
+      return queryHandler.handle(route, queries, req, res);
+    } else {
+      return routeNotImplemented(req, res);
+    }
+  }
+
+}).listen(8080, () => console.log("NodeJS worker listening on port 8080"));

+ 4 - 5
frameworks/JavaScript/nodejs/helper.js

@@ -41,16 +41,15 @@ const self = module.exports = {
   },
 
   addTfbHeaders: (res, headerType) => {
-    const headers = { 'Server': 'Node' };
     const headerTypes = {
       plain: 'text/plain',
       json:  'application/json',
       html:  'text/html; charset=UTF-8'
     };
-    headers['Content-Type'] = headerTypes[headerType];
-
-    res.writeHead(200, headers);
-  },
+    
+    res.setHeader('Server', 'Node');
+    res.setHeader('Content-Type', headerTypes[headerType]);
+},
 
   responses: {
 

+ 15 - 0
frameworks/JavaScript/nodejs/setup-mitol.sh

@@ -0,0 +1,15 @@
+#!/bin/bash
+
+fw_depends mongodb mysql postgresql nodejs
+
+npm install
+
+# Mitol installation
+mkdir -p node_modules/mns & mkdir -p tmp
+wget https://github.com/Helidium/Mitol/archive/v0.0.1.tar.gz -P tmp
+tar -xzvf tmp/v0.0.1.tar.gz -C tmp
+make -C tmp/Mitol-0.0.1/node
+cp tmp/Mitol-0.0.1/node/dist/* node_modules/mns
+rm -R tmp
+
+node app-mitol.js &