Browse Source

add ringojs

ringo is a JS environment on top of rhino; we use jetty as an embedded
webserver. the db tests are run with plain jdbc and connectionpooling
provided by dbcp
Simon Oberhammer 12 years ago
parent
commit
10f9c540a4
7 changed files with 152 additions and 0 deletions
  1. 7 0
      installer.py
  2. 34 0
      ringojs/README.md
  3. 0 0
      ringojs/__init__.py
  4. 18 0
      ringojs/benchmark_config
  5. 11 0
      ringojs/config/log4j.properties
  6. 56 0
      ringojs/ringo-main.js
  7. 26 0
      ringojs/setup.py

+ 7 - 0
installer.py

@@ -116,6 +116,13 @@ class Installer:
 
     self.__run_command("sudo apt-get install ghc cabal-install", True)
 
+    ##############################
+    # RingoJs
+    ##############################
+    self.__run_command("wget http://www.ringojs.org/downloads/ringojs_0.9-1_all.deb")
+    self.__run_command("dpkg -i ringojs_0.9-1_all.deb")
+    self.__run_command("rm ringojs_0.9_1.all.db")
+
     #######################################
     # Webservers
     #######################################

+ 34 - 0
ringojs/README.md

@@ -0,0 +1,34 @@
+# RingoJs Benchmarking Test
+
+This is the Ringojs portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+
+* [JSON test controller/view](ringo-main.js)
+
+### Data-Store/Database Mapping Test
+
+* [DB test controller/model](ringo-main.js)
+
+## Infrastructure Software Versions
+
+The tests were run with:
+
+* [RingoJs v0.9](http://ringojs.org/)
+* [MySQL 5.5.29](https://dev.mysql.com/)
+
+## Test URLs
+### JSON Encoding Test
+
+http://localhost:8080/json
+
+### Data-Store/Database Mapping Test
+
+MySQL:
+
+http://localhost:8080/db
+
+### Variable Query Test
+
+MySQL:
+http://localhost:8080/db?queries=2

+ 0 - 0
ringojs/__init__.py


+ 18 - 0
ringojs/benchmark_config

@@ -0,0 +1,18 @@
+{
+  "framework": "ringojs",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "port": 8080,
+      "sort": 72
+    },
+    "raw": {
+      "setup_file": "setup",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "port": 8080,
+      "sort": 73
+    }
+  }]
+}

+ 11 - 0
ringojs/config/log4j.properties

@@ -0,0 +1,11 @@
+log4j.reset = true
+log4j.rootLogger = OFF
+
+log4j.appender.console = org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout = org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern = %-4r [%t] %-5p %c %x - %m%n
+
+# Hint: set categories for module names you're working on to DEBUG level, e.g.:
+# log4j.category.main = DEBUG
+# log4j.category.ringo.skin = DEBUG
+# log4j.category.ringo.webapp = DEBUG

+ 56 - 0
ringojs/ringo-main.js

@@ -0,0 +1,56 @@
+var sql = require('sql-ringojs-client');
+
+// DO NOT TOUCH THE FOLLOWING LINE.
+// THIS VARIABLE IS REGEX REPLACED BY setup.py
+var dbHost = 'localhost';
+
+exports.app = function(req) {
+   var path = req.pathInfo;
+   if (path === '/json') {
+      var helloObject = {message: "Hello, world"};
+      // JSON Response Test
+      return {
+         status: 200,
+         headers: {"Content-Type": "application/json; charset=UTF-8"},
+         body: [JSON.stringify(helloObject)]
+      }
+   } else if (path === '/db') {
+      var queryCount = req.env.servletRequest.getParameter('queries');
+      var connection = datasource.getConnection();
+      if (queryCount === null) {
+         var randId = ((Math.random() * 10000) | 0) + 1
+         var world = sql.query(connection, 'select * from World where World.id = ' + randId)[0];
+         // let's just hope it gets to this
+         connection.close();
+         return {
+            status: 200,
+            headers: {"Content-Type": "application/json; charset=UTF-8"},
+            body: [JSON.stringify(world)]
+         }
+      } else {
+         queryCount = parseInt(queryCount, 10);
+         var body = [];
+         var randId, world;
+         for (var i = 0; i < queryCount; i++) {
+            randId = ((Math.random() * 10000) | 0) + 1;
+            world = sql.query(connection, 'select * from World where World.id = ' + randId)[0];
+            body.push(world);
+         }
+         connection.close();
+         return {
+            status: 200,
+            headers: {"Content-Type": "application/json; charset=UTF-8"},
+            body: [JSON.stringify(body)]
+         }
+      }
+   }
+};
+
+
+var datasource = module.singleton('pooling-datasource', function() {
+  return sql.connect("jdbc:mysql://" + dbHost + "/hello_world", 'benchmarkdbuser', 'benchmarkdbpass');
+});
+
+if (require.main == module) {
+    require("ringo/httpserver").main(module.id);
+}

+ 26 - 0
ringojs/setup.py

@@ -0,0 +1,26 @@
+
+import subprocess
+import sys
+import setup_util
+import os
+
+def start(args):
+  setup_util.replace_text("ringojs/ringo-main.js", "dbHost = '.*';", "dbHost = '" + args.database_host + "';")
+
+  try:
+    subprocess.check_call("ringo-admin install oberhamsi/sql-ringojs-client", shell=True, cwd="ringojs")
+    subprocess.Popen("ringo --production ringo-main.js", shell=True, cwd="ringojs")
+    return 0
+  except subprocess.CalledProcessError:
+    return 1
+def stop():
+  p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+  out, err = p.communicate()
+  for line in out.splitlines():
+    if 'ringo-main.js' in line:
+      pid = int(line.split(None, 2)[1])
+      try:
+        os.kill(pid, 9)
+      except OSError:
+        pass
+  return 0