Browse Source

Merge branch 'oberhamsi-ringojs-convinient'

Patrick Falls 12 years ago
parent
commit
a4e759850b

+ 27 - 15
installer.py

@@ -2,7 +2,7 @@ import subprocess
 import os
 import os
 
 
 class Installer:
 class Installer:
-  
+
   ############################################################
   ############################################################
   # install_software
   # install_software
   ############################################################
   ############################################################
@@ -38,7 +38,7 @@ class Installer:
     self.__run_command("wget -O - http://binaries.erlang-solutions.com/debian/erlang_solutions.asc | sudo apt-key add -")
     self.__run_command("wget -O - http://binaries.erlang-solutions.com/debian/erlang_solutions.asc | sudo apt-key add -")
     self.__run_command("sudo apt-get update")
     self.__run_command("sudo apt-get update")
     self.__run_command("sudo apt-get install esl-erlang", True)
     self.__run_command("sudo apt-get install esl-erlang", True)
-    
+
     #
     #
     # Python
     # Python
     #
     #
@@ -62,10 +62,10 @@ class Installer:
     #
     #
     # Java
     # Java
     #
     #
-    
+
     self.__run_command("sudo apt-get install openjdk-7-jdk", True)
     self.__run_command("sudo apt-get install openjdk-7-jdk", True)
     self.__run_command("sudo apt-get remove --purge openjdk-6-jre openjdk-6-jre-headless", True)
     self.__run_command("sudo apt-get remove --purge openjdk-6-jre openjdk-6-jre-headless", True)
-    
+
     #
     #
     # Ruby/JRuby
     # Ruby/JRuby
     #
     #
@@ -76,7 +76,7 @@ class Installer:
     subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install bundler"])
     subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install bundler"])
     subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install jruby-1.7.3"])
     subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install jruby-1.7.3"])
     subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do gem install bundler"])
     subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do gem install bundler"])
-    
+
     # We need a newer version of jruby-rack
     # We need a newer version of jruby-rack
     self.__run_command("git clone git://github.com/jruby/jruby-rack.git")
     self.__run_command("git clone git://github.com/jruby/jruby-rack.git")
     subprocess.call(["bash", "-c", "cd installs/jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do bundle install"])
     subprocess.call(["bash", "-c", "cd installs/jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do bundle install"])
@@ -116,6 +116,18 @@ class Installer:
 
 
     self.__run_command("sudo apt-get install ghc cabal-install", True)
     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("sudo apt-get install jsvc")
+    self.__run_command("sudo dpkg -i ringojs_0.9-1_all.deb")
+    self.__run_command("rm ringojs_0.9-1_all.deb")
+    self.__run_command("sudo ringo-admin install oberhamsi/sql-ringojs-client")
+    self.__run_command("sudo ringo-admin install ringo/stick")
+    self.__run_command("sudo ringo-admin install oberhamsi/reinhardt")
+    self.__run_command("sudo ringo-admin install grob/ringo-sqlstore")
+
     #######################################
     #######################################
     # Webservers
     # Webservers
     #######################################
     #######################################
@@ -130,7 +142,7 @@ class Installer:
     self.__run_command("sudo mv /etc/apache2/ports.conf /etc/apache2/ports.conf.orig")
     self.__run_command("sudo mv /etc/apache2/ports.conf /etc/apache2/ports.conf.orig")
     self.__run_command("sudo sh -c \"cat ../config/ports.conf > /etc/apache2/ports.conf\"")
     self.__run_command("sudo sh -c \"cat ../config/ports.conf > /etc/apache2/ports.conf\"")
     self.__run_command("sudo /etc/init.d/apache2 stop")
     self.__run_command("sudo /etc/init.d/apache2 stop")
-    
+
     #
     #
     # Nginx
     # Nginx
     #
     #
@@ -138,7 +150,7 @@ class Installer:
     self.__run_command("./configure", cwd="nginx-1.2.7")
     self.__run_command("./configure", cwd="nginx-1.2.7")
     self.__run_command("make", cwd="nginx-1.2.7")
     self.__run_command("make", cwd="nginx-1.2.7")
     self.__run_command("sudo make install", cwd="nginx-1.2.7")
     self.__run_command("sudo make install", cwd="nginx-1.2.7")
-    
+
     #
     #
     # Openresty (nginx with openresty stuff)
     # Openresty (nginx with openresty stuff)
     #
     #
@@ -146,7 +158,7 @@ class Installer:
     self.__run_command("./configure --with-luajit", cwd="ngx_openresty-1.2.7.5")
     self.__run_command("./configure --with-luajit", cwd="ngx_openresty-1.2.7.5")
     self.__run_command("make", cwd="ngx_openresty-1.2.7.5")
     self.__run_command("make", cwd="ngx_openresty-1.2.7.5")
     self.__run_command("sudo make install", cwd="ngx_openresty-1.2.7.5")
     self.__run_command("sudo make install", cwd="ngx_openresty-1.2.7.5")
-    
+
     #
     #
     # Gunicorn
     # Gunicorn
     #
     #
@@ -224,7 +236,7 @@ class Installer:
     self.__run_command("wget http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.1.1.zip")
     self.__run_command("wget http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.1.1.zip")
     self.__run_command("unzip -o grails-2.1.1.zip")
     self.__run_command("unzip -o grails-2.1.1.zip")
     self.__run_command("rm grails-2.1.1.zip")
     self.__run_command("rm grails-2.1.1.zip")
-    
+
 
 
     ##############################
     ##############################
     # Flask
     # Flask
@@ -237,7 +249,7 @@ class Installer:
     self.__run_command("wget http://downloads.typesafe.com/play/2.1.1/play-2.1.1.zip")
     self.__run_command("wget http://downloads.typesafe.com/play/2.1.1/play-2.1.1.zip")
     self.__run_command("unzip -o play-2.1.1.zip")
     self.__run_command("unzip -o play-2.1.1.zip")
     self.__run_command("rm play-2.1.1.zip")
     self.__run_command("rm play-2.1.1.zip")
-    
+
     ##############################
     ##############################
     # Play 1
     # Play 1
     ##############################
     ##############################
@@ -245,7 +257,7 @@ class Installer:
     self.__run_command("unzip -o play-1.2.5.zip")
     self.__run_command("unzip -o play-1.2.5.zip")
     self.__run_command("rm play-1.2.5.zip")
     self.__run_command("rm play-1.2.5.zip")
     self.__run_command("mv play-1.2.5/play play-1.2.5/play1")
     self.__run_command("mv play-1.2.5/play play-1.2.5/play1")
-    
+
     # siena
     # siena
     self.__run_command("play-1.2.5/play1 install siena", send_yes=True)
     self.__run_command("play-1.2.5/play1 install siena", send_yes=True)
 
 
@@ -323,7 +335,7 @@ class Installer:
     ./waf build
     ./waf build
     sudo ./waf install
     sudo ./waf install
     cd ~
     cd ~
-    
+
     ##############################
     ##############################
     # wrk
     # wrk
     ##############################
     ##############################
@@ -339,16 +351,16 @@ class Installer:
     ##############################
     ##############################
     sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
     sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
     sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
     sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
-    sudo apt-get update 
+    sudo apt-get update
     yes | sudo apt-get install mongodb-10gen
     yes | sudo apt-get install mongodb-10gen
-    
+
     sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
     sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
     sudo mv mongodb.conf /etc/mongodb.conf
     sudo mv mongodb.conf /etc/mongodb.conf
     sudo restart mongodb
     sudo restart mongodb
     """
     """
     p = subprocess.Popen(self.benchmarker.ssh_string.split(" "), stdin=subprocess.PIPE)
     p = subprocess.Popen(self.benchmarker.ssh_string.split(" "), stdin=subprocess.PIPE)
     p.communicate(remote_script)
     p.communicate(remote_script)
-    
+
   ############################################################
   ############################################################
   # End __parse_results
   # End __parse_results
   ############################################################
   ############################################################

+ 34 - 0
ringojs-convinient/README.md

@@ -0,0 +1,34 @@
+# RingoJs Benchmarking Test
+
+This is the Ringojs with the Stick framework portion of the [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-convinient/__init__.py


+ 39 - 0
ringojs-convinient/app/models.js

@@ -0,0 +1,39 @@
+var {Store, ConnectionPool, Cache} = require('ringo-sqlstore');
+
+// DO NOT TOUCH THE FOLLOWING LINE.
+// THIS VARIABLE IS REGEX REPLACED BY setup.py
+var dbHost = 'localhost';
+
+// create and configure store
+var connectionPool = module.singleton("connectionPool", function() {
+    return new ConnectionPool({
+        "url": "jdbc:mysql://" + dbHost + "/hello_world",
+        "driver": "com.mysql.jdbc.Driver",
+        "username": "benchmarkdbuser",
+        "password": "benchmarkdbpass"
+    });
+});
+var store = exports.store = new Store(connectionPool);
+var queryCache = module.singleton("queryCache", function() {
+    return new Cache(10000);
+});
+store.setQueryCache(queryCache);
+
+// define entities in DB
+exports.World = store.defineEntity('World', {
+	table: 'World',
+	properties: {
+		randomNumber: 'integer'
+	}
+});
+
+var Fortune = exports.Fortune = store.defineEntity('Fortune', {
+	table: 'Fortune',
+	properties: {
+		message: 'string'
+	}
+});
+
+Fortune.sort = function(a, b) {
+ return (a.message < b.message) ? -1 : (a.message > b.message) ? 1 : 0;
+};

+ 39 - 0
ringojs-convinient/app/views.js

@@ -0,0 +1,39 @@
+var {Application} = require("stick");
+var fs = require('fs');
+var response = require('ringo/jsgi/response');
+var models = require('./models');
+
+var {Template} = require('reinhardt/template');
+var fortuneTemplate = module.singleton('fortuneTemplate', function() {
+   return new Template(fs.read(module.resolve('../templates/fortunes.reinhardt')));
+});
+
+var app = exports.app = Application();
+app.configure("params", "route");
+
+app.get('/json', function() {
+   var helloObject = {message: "Hello, world"};
+   return response.json(helloObject);
+});
+
+app.get('/db/:queries?', function(request, queries) {
+   queries = parseInt(queries, 10) || 1;
+   var worlds = [];
+   var randId, world;
+   for (var i = 0; i < queries; i++) {
+      randId = ((Math.random() * 10000) | 0) + 1;
+      world = models.store.query('select World.* from World where World.id = :id', {id: randId})[0];
+      worlds.push(world.toJSON());
+   }
+   return response.json(worlds);
+});
+
+app.get('/fortune', function() {
+   var fortunes = models.Fortune.all();
+   fortunes.push({
+      _id: 0,
+      message: 'Additional fortune added at request time.'
+   });
+   fortunes.sort(models.Fortune.sort);
+   return response.html(fortuneTemplate.render({fortunes: fortunes}));
+});

+ 14 - 0
ringojs-convinient/benchmark_config

@@ -0,0 +1,14 @@
+{
+  "framework": "ringojs-convinient",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db/",
+      "fortune_url": "/fortune",
+      "port": 8080,
+      "sort": 75
+    }
+  }]
+}

+ 9 - 0
ringojs-convinient/ringo-main.js

@@ -0,0 +1,9 @@
+var {Application} = require("stick");
+
+var app = exports.app = Application();
+app.configure("mount");
+app.mount("/", require("./app/views"));
+
+if (require.main == module) {
+    require("ringo/httpserver").main(module.id);
+}

+ 28 - 0
ringojs-convinient/setup.py

@@ -0,0 +1,28 @@
+
+import subprocess
+import sys
+import setup_util
+import os
+
+def start(args):
+  setup_util.replace_text("ringojs-convinient/app/models.js", "dbHost = '.*';", "dbHost = '" + args.database_host + "';")
+
+  try:
+    subprocess.check_call("sudo mkdir -p /usr/share/ringojs/packages/ringo-sqlstore/jars/", shell=True)
+    
+    subprocess.check_call("sudo cp /usr/share/ringojs//packages/sql-ringojs-client/jars/mysql.jar /usr/share/ringojs/packages/ringo-sqlstore/jars/", shell=True)
+    subprocess.Popen("ringo --production ringo-main.js", shell=True, cwd="ringojs-convinient")
+    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

+ 20 - 0
ringojs-convinient/templates/fortunes.reinhardt

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+{% for fortune in fortunes %}
+<tr>
+<td>{{fortune._id}}</td>
+<td>{{fortune.message}}</td>
+</tr>
+{% endfor %}
+</table>
+</body>
+</html>

+ 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


+ 19 - 0
ringojs/benchmark_config

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

+ 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

+ 91 - 0
ringojs/ringo-main.js

@@ -0,0 +1,91 @@
+var sql = require('sql-ringojs-client');
+var mustache = require('ringo/mustache');
+
+// DO NOT TOUCH THE FOLLOWING LINE.
+// THIS VARIABLE IS REGEX REPLACED BY setup.py
+var dbHost = 'localhost';
+
+var sortFortunes = function(a, b) {
+ return (a.message < b.message) ? -1 : (a.message > b.message) ? 1 : 0;
+};
+
+var fortuneTemplate = require('fs').read(module.resolve('./templates/fortune.mustache'));
+
+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');
+      try {
+         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];
+            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);
+            }
+            return {
+               status: 200,
+               headers: {"Content-Type": "application/json; charset=UTF-8"},
+               body: [JSON.stringify(body)]
+            }
+         }
+      } catch (e) {
+         connection.close();
+         connection = null;
+      } finally {
+         if (connection !== null) {
+            connection.close();
+         }
+      }
+   } else if (path === '/fortune') {
+      try {
+         var connection = datasource.getConnection();
+         var fortunes = sql.query(connection, 'select * from Fortune');
+         fortunes.push({
+            id: 0,
+            message: 'Additional fortune added at request time.'
+         });
+         fortunes.sort(sortFortunes);
+         return {
+            status: 200,
+            headers: {"Content-Type": "text/html; charset=UTF-8"},
+            body: [mustache.to_html(fortuneTemplate, {fortunes: fortunes})]
+         }
+      } catch (e) {
+         connection.close();
+         connection = null;
+      } finally {
+         if (connection !== null) {
+            connection.close();
+         }
+      }
+   }
+};
+
+
+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);
+}

+ 25 - 0
ringojs/setup.py

@@ -0,0 +1,25 @@
+
+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.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

+ 20 - 0
ringojs/templates/fortune.mustache

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+{{#fortunes}}
+<tr>
+<td>{{id}}</td>
+<td>{{message}}</td>
+</tr>
+{{/fortunes}}
+</table>
+</body>
+</html>