Browse Source

Improved Vert.x test server and upgraded to 2.0.2-final

purplefox 12 years ago
parent
commit
5c9dde0136

+ 1 - 1
config/benchmark_profile

@@ -1,7 +1,7 @@
 export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
 export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
 export RESIN_HOME=~/FrameworkBenchmarks/installs/resin-4.0.36
 export RESIN_HOME=~/FrameworkBenchmarks/installs/resin-4.0.36
 export GRAILS_HOME=~/FrameworkBenchmarks/installs/grails-2.1.1
 export GRAILS_HOME=~/FrameworkBenchmarks/installs/grails-2.1.1
-export VERTX_HOME=~/FrameworkBenchmarks/installs/vert.x-1.3.1.final
+export VERTX_HOME=~/FrameworkBenchmarks/installs/vert.x-2.0.2-final
 export GOROOT=~/FrameworkBenchmarks/installs/go
 export GOROOT=~/FrameworkBenchmarks/installs/go
 export GOPATH=~/FrameworkBenchmarks/go:~/FrameworkBenchmarks/webgo:~/FrameworkBenchmarks/revel
 export GOPATH=~/FrameworkBenchmarks/go:~/FrameworkBenchmarks/webgo:~/FrameworkBenchmarks/revel
 export TOMCAT_HOME=~/FrameworkBenchmarks/installs/apache-tomcat-7.0.35
 export TOMCAT_HOME=~/FrameworkBenchmarks/installs/apache-tomcat-7.0.35

+ 2 - 2
toolset/setup/linux/installer.py

@@ -283,8 +283,8 @@ class Installer:
     #
     #
     # Vert.x
     # Vert.x
     #
     #
-    self.__download("http://vertx.io/vertx-downloads/downloads/vert.x-1.3.1.final.tar.gz")
-    self.__run_command("tar xzf vert.x-1.3.1.final.tar.gz")
+    self.__download("http://dl.bintray.com/vertx/downloads/vert.x-2.0.2-final.tar.gz?direct=true")
+    self.__run_command("tar xzf vert.x-2.0.2-final.tar.gz")
 
 
     #
     #
     # Yesod
     # Yesod

+ 0 - 32
vertx/App.groovy

@@ -1,32 +0,0 @@
-// Our application config
-
-def persistorConf = [
-  address: 'hello.persistor',
-  db_name: 'hello_world',
-  host: '127.0.0.1'
-]
-
-def permitted =
-[
-  // Allow calls to get static album data from the persistor
-  //[
-  //  'address' : 'hello.persistor',
-  //  'match' : [
-  //    'action' : 'find',
-  //    'collection' : 'users'
-  //  ]
-  //]
-  [
-    'address' : 'hello.persistor'
-  ]
-]
-
-container.with {
-
-  // Deploy the busmods
-  // deployModule('vertx.mongo-persistor-v1.2.1', persistorConf, 8)
-
-  // Start the web server
-
-  deployVerticle('WebServer', ['permitted': permitted], 8)
-}

+ 63 - 91
vertx/WebServer.java

@@ -1,143 +1,115 @@
-import java.io.IOException;
 import java.nio.charset.*;
 import java.nio.charset.*;
+
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
 import java.util.Random;
 import java.util.Random;
-import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.vertx.java.core.Handler;
 import org.vertx.java.core.Handler;
 import org.vertx.java.core.buffer.Buffer;
 import org.vertx.java.core.buffer.Buffer;
 import org.vertx.java.core.eventbus.Message;
 import org.vertx.java.core.eventbus.Message;
 import org.vertx.java.core.http.HttpServerRequest;
 import org.vertx.java.core.http.HttpServerRequest;
-import org.vertx.java.core.json.JsonArray;
 import org.vertx.java.core.json.JsonObject;
 import org.vertx.java.core.json.JsonObject;
+import org.vertx.java.core.json.impl.Json;
 import org.vertx.java.platform.Verticle;
 import org.vertx.java.platform.Verticle;
 
 
-public class WebServer
-	extends    Verticle
-	implements Handler<HttpServerRequest>
-{
-  private final ObjectMapper mapper = new ObjectMapper();
+public class WebServer extends Verticle implements Handler<HttpServerRequest> {
+
+  private static String helloWorld = "Hello, World!";
+  private static Buffer helloWorldBuffer = new Buffer(helloWorld);
+  private static String helloWorldContentLength = String.valueOf(helloWorldBuffer.length());
 
 
   @Override
   @Override
-  public void start()
-  {
-    this.getVertx().createHttpServer().requestHandler(this).listen(8080);
+  public void start() {
+    vertx.createHttpServer().requestHandler(WebServer.this).listen(8080);
   }
   }
 
 
   @Override
   @Override
-  public void handle(HttpServerRequest req)
-  {
-    if (req.path().equals("/json"))
-    {
-      handleJson(req);
-    }
-    else if (req.path().equals("/db"))
-    {
-      handleDb(req);
-    }
-    else
-    {
-      req.response().setStatusCode(404);
-      req.response().end();
+  public void handle(HttpServerRequest req) {
+    String path = req.path();
+    switch (path.charAt(1)) {
+      case 'p':
+        handlePlainText(req);
+        break;
+      case 'j':
+        handleJson(req);
+        break;
+      case 'd':
+        handleDbMongo(req);
+        break;
+      default:
+        req.response().setStatusCode(404);
+        req.response().end();
     }
     }
+
   }
   }
 
 
+  private void handlePlainText(HttpServerRequest req) {
+    req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
+    req.response().putHeader("Content-Length", helloWorldContentLength);
+    req.response().write(helloWorldBuffer);
+    req.response().end();
+  }
 
 
-  private void handleJson(HttpServerRequest req)
-  {
-    Buffer buffer;
-    try
-    {
-      Map<String, String> data = new HashMap<String, String>();
-      data.put("message", "Hello, world");
-      buffer = new Buffer(mapper.writeValueAsBytes(data));
-    }
-    catch (IOException e)
-    {
-      req.response().setStatusCode(500);
-      req.response().end();
-      return;
-    }
-    
+  private void handleJson(HttpServerRequest req) {
+    String result = Json.encode(Collections.singletonMap("message", "Hello, world!"));
 
 
+    int contentLength = result.getBytes(StandardCharsets.UTF_8).length;
     req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
     req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
-    req.response().putHeader("Content-Length", Integer.toString(buffer.length()));
-    req.response().write(buffer);
+    req.response().putHeader("Content-Length", String.valueOf(contentLength));
+    req.response().write(result);
     req.response().end();
     req.response().end();
   }
   }
 
 
-  private void handleDb(final HttpServerRequest req)
-  {
+  private void handleDbMongo(final HttpServerRequest req) {
     int queriesParam = 1;
     int queriesParam = 1;
-    try 
-    {
+    try {
       queriesParam = Integer.parseInt(req.params().get("queries"));
       queriesParam = Integer.parseInt(req.params().get("queries"));
-    }
-    catch (NumberFormatException e)
-    {
+    } catch (NumberFormatException e) {
       // do nothing
       // do nothing
     }
     }
 
 
-    final DbHandler dbh = new DbHandler(req, queriesParam);
+    final MongoHandler dbh = new MongoHandler(req, queriesParam);
     final Random random = ThreadLocalRandom.current();
     final Random random = ThreadLocalRandom.current();
 
 
-    for (int i = 0; i < queriesParam; i++)
-    {
-      this.getVertx().eventBus().send(
-        "hello.persistor",
-        new JsonObject()
-            .putString("action", "findone")
-            .putString("collection", "world")
-            .putObject("matcher", new JsonObject().putNumber("id", (random.nextInt(10000) + 1))),
-        dbh);
+    for (int i = 0; i < queriesParam; i++) {
+      vertx.eventBus().send(
+          "hello.persistor",
+          new JsonObject()
+              .putString("action", "findone")
+              .putString("collection", "world")
+              .putObject("matcher", new JsonObject().putNumber("id", (random.nextInt(10000) + 1))),
+          dbh);
     }
     }
   }
   }
 
 
-  class DbHandler implements Handler<Message<JsonObject>>
-  {
+  private static class MongoHandler implements Handler<Message<JsonObject>> {
     private final HttpServerRequest req;
     private final HttpServerRequest req;
     private final int queries;
     private final int queries;
-    private final List<Object> worlds = new CopyOnWriteArrayList<>();
+    private final List<Object> worlds = new ArrayList<>();
 
 
-    public DbHandler(HttpServerRequest request, int queriesParam)
-    {
-   	  this.req = request;
+    public MongoHandler(HttpServerRequest request, int queriesParam) {
+      this.req = request;
       this.queries = queriesParam;
       this.queries = queriesParam;
     }
     }
 
 
     @Override
     @Override
-    public void handle(Message<JsonObject> reply)
-    {
+    public void handle(Message<JsonObject> reply) {
       final JsonObject body = reply.body();
       final JsonObject body = reply.body();
 
 
-      if ("ok".equals(body.getString("status")))
-      {
-      	this.worlds.add(body.getObject("result"));
-      }
-
-      if (this.worlds.size() == this.queries)
-      {
-        // All queries have completed; send the response.
-        // final JsonArray arr = new JsonArray(worlds);
-        try
-        {
-          final String result = mapper.writeValueAsString(worlds);
+      if ("ok".equals(body.getString("status"))) {
+        this.worlds.add(body.getObject("result"));
+        if (this.worlds.size() == this.queries) {
+          // All queries have completed; send the response.
+          final String result = Json.encode(worlds);
           final int contentLength = result.getBytes(StandardCharsets.UTF_8).length;
           final int contentLength = result.getBytes(StandardCharsets.UTF_8).length;
           this.req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
           this.req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
-          this.req.response().putHeader("Content-Length", Integer.toString(contentLength));
+          this.req.response().putHeader("Content-Length", String.valueOf(contentLength));
           this.req.response().write(result);
           this.req.response().write(result);
           this.req.response().end();
           this.req.response().end();
         }
         }
-        catch (IOException e)
-        {
-          req.response().setStatusCode(500);
-          req.response().end();
-        }
+      } else {
+        System.err.println("Failed to execute query");
       }
       }
     }
     }
   }
   }

+ 15 - 0
vertx/app.js

@@ -0,0 +1,15 @@
+var container = require('vertx/container')
+
+var persistorConf = {
+  address: 'hello.persistor',
+  db_name: 'hello_world',
+  host: 'localhost'
+}
+
+container.deployModule('io.vertx~mod-mongo-persistor~2.0.0-final', persistorConf, function (err, dep_id) {
+  if (!err) {
+    container.deployVerticle('WebServer.java', 8);
+  } else {
+    err.printStackTrace();
+  }
+});

+ 5 - 4
vertx/benchmark_config

@@ -3,9 +3,10 @@
   "tests": [{
   "tests": [{
     "default": {
     "default": {
       "setup_file": "setup",
       "setup_file": "setup",
-      "json_url": "/json",
-      "db_url": "/db",
-      "query_url": "/db?queries=",
+      "json_url": "/j",
+      "db_url": "/d",
+      "plaintext_url": "/p",
+      "query_url": "/d?queries=",
       "port": 8080,
       "port": 8080,
       "approach": "Realistic",
       "approach": "Realistic",
       "classification": "Platform",
       "classification": "Platform",
@@ -22,4 +23,4 @@
       "versus": "netty"
       "versus": "netty"
     }
     }
   }]
   }]
-}
+}

BIN
vertx/extra-jars-for-vertx-home/guava-11.0.2.jar


BIN
vertx/extra-jars-for-vertx-home/mustache.jar


+ 4 - 5
vertx/setup.py

@@ -5,10 +5,9 @@ import setup_util
 import os
 import os
 
 
 def start(args):
 def start(args):
-  setup_util.replace_text("vertx/App.groovy", "host: '.*'", "host: '" + args.database_host + "'")
-
-  try:    
-    subprocess.Popen("vertx run WebServer.java", shell=True, cwd="vertx")
+  setup_util.replace_text("vertx/app.js", "host: '.*'", "host: '" + args.database_host + "'")
+  try:
+    subprocess.Popen("vertx run app.js", shell=True, cwd="vertx")
     return 0
     return 0
   except subprocess.CalledProcessError:
   except subprocess.CalledProcessError:
     return 1
     return 1
@@ -16,7 +15,7 @@ def stop():
   p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
   p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
   out, err = p.communicate()
   out, err = p.communicate()
   for line in out.splitlines():
   for line in out.splitlines():
-    if 'App.groovy' in line:
+    if 'app.js' in line:
       pid = int(line.split(None, 2)[1])
       pid = int(line.split(None, 2)[1])
       os.kill(pid, 9)
       os.kill(pid, 9)