Browse Source

Merge branch 'master' of te.github.com:TechEmpower/FrameworkBenchmarks

Patrick Falls 12 years ago
parent
commit
77f676c4e0

+ 2 - 2
README.md

@@ -172,7 +172,7 @@ This test will:
 * Set the response Content-Type to application/json.
 * Serialize the row to JSON and send the resulting string as the response.
 
-By convnetion, if the test does not use an ORM, and instead uses the raw database connectivity provided by the platform (e.g., JDBC), we append a "-raw" to the test name in the [benchmark_config](#the-benchmark_config-file) file.  For example, "php-raw".
+By convention, if the test does not use an ORM, and instead uses the raw database connectivity provided by the platform (e.g., JDBC), we append a "-raw" to the test name in the [benchmark_config](#the-benchmark_config-file) file.  For example, "php-raw".
 
 Pseudo-code:
 
@@ -279,4 +279,4 @@ The setup file is a python file that contains a start() and a stop() function. H
       subprocess.check_call("$RESIN_HOME/bin/resinctl shutdown", shell=True)
       return 0
     except subprocess.CalledProcessError:
-      return 1
+      return 1

+ 4 - 3
compojure/hello/project.clj

@@ -1,10 +1,11 @@
 (defproject hello "compojure"
   :description "JSON/Database tests"
   :url "http://example.com/FIXME"
-  :dependencies [[org.clojure/clojure "1.4.0"]
+  :dependencies [[org.clojure/clojure "1.5.1"]
                  [compojure "1.1.5"]
-                 [ring/ring-json "0.1.2"]
-                 [korma "0.3.0-RC2"]
+                 [ring/ring-json "0.2.0"]
+                 [korma "0.3.0-RC5"]
+                 [log4j "1.2.15" :exclusions [javax.mail/mail javax.jms/jms com.sun.jdmk/jmxtools com.sun.jmx/jmxri]]
                  [mysql/mysql-connector-java "5.1.6"]
                  ]
   :plugins [[lein-ring "0.8.2"]]

+ 7 - 7
compojure/hello/src/hello/handler.clj

@@ -9,13 +9,13 @@
 
 ; Database connection
 (defdb db (mysql {:db "hello_world"
-                       :user "benchmarkdbuser"
-                       :password "benchmarkdbpass"
-                       ;;OPTIONAL KEYS
-                       :host "localhost"
-                       :port "3306"
-                       :delimiters "" ;; remove delimiters
-                       :maximum-pool-size 256
+                  :user "benchmarkdbuser"
+                  :password "benchmarkdbpass"
+                  ;;OPTIONAL KEYS
+                  :host "localhost"
+                  :port "3306"
+                  :delimiters "" ;; remove delimiters
+                  :maximum-pool-size 256
                   }))
 
 ; Set up entity World and the database representation

+ 7 - 0
compojure/hello/src/log4j.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+  <logger name="com.mchange">
+    <level value="WARN"/>
+  </logger>
+</log4j:configuration>

+ 11 - 12
go/hello.go

@@ -1,24 +1,23 @@
 package main
 
 import (
-  "net/http";
-  "encoding/json";
-  "runtime";
-  "fmt";
+	"encoding/json"
+	"net/http"
+	"runtime"
 )
 
 type MessageStruct struct {
-    Message string
+	Message string
 }
 
 func hello(w http.ResponseWriter, r *http.Request) {
-  m := MessageStruct{"Hello, world"}
-  j, _ := json.Marshal(m)
-  fmt.Fprintf(w, string(j))
+	m := MessageStruct{"Hello, world"}
+	enc := json.NewEncoder(w)
+	enc.Encode(m)
 }
 
 func main() {
-  runtime.GOMAXPROCS(runtime.NumCPU())
-  http.HandleFunc("/json", hello)
-  http.ListenAndServe(":8080", nil)
-}
+	runtime.GOMAXPROCS(runtime.NumCPU())
+	http.HandleFunc("/json", hello)
+	http.ListenAndServe(":8080", nil)
+}

+ 2 - 2
grails/hello/grails-app/controllers/hello/HelloController.groovy

@@ -13,8 +13,8 @@ class HelloController {
     }
 
     def db() {
-      def queries = params.queries ? params.int('queries') : 1
-      def worlds = []
+      int queries = params.queries ? params.int('queries') : 1
+      def worlds = new ArrayList(queries)
       def random = ThreadLocalRandom.current();
 
       for (int i = 0; i < queries; i++) {

+ 1 - 1
netty/README.md

@@ -11,7 +11,7 @@ This is the netty portion of a [benchmarking test suite](../) comparing a variet
 * [Netty 4.0.0.Beta2](http://netty.io/)
 
 ## References
-* shttps://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/http/snoop
+* https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/http/snoop
 
 ## Test URLs
 

+ 1 - 1
netty/pom.xml

@@ -12,7 +12,7 @@
     <dependency>
     	<groupId>io.netty</groupId>
     	<artifactId>netty-codec-http</artifactId>
-    	<version>4.0.0.Beta2</version>
+    	<version>4.0.0.CR1</version>
     </dependency>
 	 <dependency>
 		<groupId>com.fasterxml.jackson.core</groupId>

+ 23 - 11
netty/src/main/java/hello/HelloServerHandler.java

@@ -1,6 +1,6 @@
 package hello;
 
-import io.netty.buffer.ByteBuf;
+import io.netty.buffer.MessageBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelHandlerContext;
@@ -17,14 +17,11 @@ import io.netty.handler.codec.http.HttpObject;
 import io.netty.handler.codec.http.HttpRequest;
 import io.netty.handler.codec.http.HttpResponse;
 import io.netty.handler.codec.http.LastHttpContent;
-import io.netty.handler.codec.http.QueryStringDecoder;
 import io.netty.handler.codec.http.ServerCookieEncoder;
 import io.netty.util.CharsetUtil;
 
-import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
-import java.util.Map.Entry;
 import java.util.Set;
 
 import java.io.*;
@@ -43,13 +40,22 @@ public class HelloServerHandler extends ChannelInboundMessageHandlerAdapter<Obje
     private final StringBuilder buf = new StringBuilder();
     private static final ObjectMapper mapper = new ObjectMapper();
 
+    private boolean flush;
+
+    @Override
+    protected boolean beginMessageReceived(ChannelHandlerContext ctx) throws Exception {
+        flush = false;
+        return super.beginMessageReceived(ctx);
+    }
+
     @Override
     public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
+        MessageBuf<Object> out = ctx.nextOutboundMessageBuffer();
         if (msg instanceof HttpRequest) {
             HttpRequest request = this.request = (HttpRequest) msg;
 
             if (is100ContinueExpected(request)) {
-                send100Continue(ctx);
+                send100Continue(out);
             }
             
             Map<String, String> data = new HashMap<String, String>();
@@ -71,7 +77,7 @@ public class HelloServerHandler extends ChannelInboundMessageHandlerAdapter<Obje
         if (msg instanceof HttpContent) {
             if (msg instanceof LastHttpContent) {
               LastHttpContent trailer = (LastHttpContent) msg;
-              writeResponse(ctx, trailer);
+              writeResponse(ctx, out, trailer);
             }
         }
     }
@@ -87,7 +93,7 @@ public class HelloServerHandler extends ChannelInboundMessageHandlerAdapter<Obje
         buf.append("\r\n");
     }
 
-    private void writeResponse(ChannelHandlerContext ctx, HttpObject currentObj) {
+    private void writeResponse(ChannelHandlerContext ctx, MessageBuf<Object> out, HttpObject currentObj) {
         // Decide whether to close the connection or not.
         boolean keepAlive = isKeepAlive(request);
         // Build the response object.
@@ -122,22 +128,28 @@ public class HelloServerHandler extends ChannelInboundMessageHandlerAdapter<Obje
         }
 
         // Write the response.
-        ctx.nextOutboundMessageBuffer().add(response);
+        out.add(response);
 
         // Close the non-keep-alive connection after the write operation is done.
         if (!keepAlive) {
+            flush = false;
             ctx.flush().addListener(ChannelFutureListener.CLOSE);
+        } else {
+            flush = true;
         }
     }
 
-    private static void send100Continue(ChannelHandlerContext ctx) {
+    private void send100Continue(MessageBuf<Object> out) {
         HttpResponse response = new DefaultHttpResponse(HTTP_1_1, CONTINUE);
-        ctx.nextOutboundMessageBuffer().add(response);
+        out.add(response);
+        flush = true;
     }
 
     @Override
     public void endMessageReceived(ChannelHandlerContext ctx) throws Exception {
-        ctx.flush();
+        if (flush) {
+            ctx.flush();
+        }
     }
 
     @Override

+ 3 - 4
rails/app/controllers/hello_world_controller.rb

@@ -4,13 +4,12 @@ class HelloWorldController < ApplicationController
   end
 
   def db
-    queries = params[:queries] || 1
+    queries = (params[:queries] || 1).to_i
 
-    results = []
-    (1..queries.to_i).each do
+    results = (1..queries).map do
       # get a random row from the database, which we know has 10000
       # rows with ids 1 - 10000
-      results << World.find(Random.rand(10000) + 1)
+      World.find(Random.rand(10000) + 1)
     end
     render :json => results
   end

+ 3 - 4
sinatra/hello_world.rb

@@ -21,11 +21,10 @@ get '/json' do
 end
 
 get '/db' do
-  queries = params[:queries] || 1
+  queries = (params[:queries] || 1).to_i
 
-  results = []
-  (1..queries.to_i).each do
-    results << World.find(Random.rand(10000) + 1)
+  results = (1..queries).map do
+    World.find(Random.rand(10000) + 1)
   end
   
   results.to_json