Browse Source

Add JLHTTP benchmark

Amichai Rothman 9 years ago
parent
commit
d78dfdb604

+ 1 - 0
.travis.yml

@@ -85,6 +85,7 @@ env:
     - "TESTDIR=Java/jawn"
     - "TESTDIR=Java/jetty-servlet"
     - "TESTDIR=Java/jetty"
+    - "TESTDIR=Java/jlhttp"
     - "TESTDIR=Java/jooby"
     - "TESTDIR=Java/netty"
     - "TESTDIR=Java/ninja-standalone"

+ 31 - 0
frameworks/Java/jlhttp/README.md

@@ -0,0 +1,31 @@
+# JLHTTP Benchmarking Test
+
+This is the JLHTTP portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+The main goal of [JLHTTP - the Java Lightweight HTTP Server](http://www.freeutils.net/source/jlhttp/)
+is to be truly lightweight, i.e. as small as a fully functional and RFC-compliant Java HTTP server can be.
+With all else being equal, it does strive for high performance - but usually all else is not equal,
+and a trade-off must be made between size (complexity) and performance.
+JLHTTP usually sides with the smaller size.
+
+
+### Plaintext Test
+
+* [Plaintext test source](src/main/java/hello/HelloWebServer.java)
+
+### JSON Encoding Test
+
+The JSON encoding is performed using Jackson.
+
+* [JSON test source](src/main/java/hello/HelloWebServer.java)
+
+
+## Test URLs
+
+### Plaintext Test
+
+http://localhost:8080/plaintext
+
+### JSON Encoding Test
+
+http://localhost:8080/json

+ 24 - 0
frameworks/Java/jlhttp/benchmark_config.json

@@ -0,0 +1,24 @@
+{
+  "framework": "jlhttp",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "None",
+      "framework": "JLHTTP",
+      "language": "Java",
+      "orm": "Raw",
+      "platform": "JLHTTP",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "JLHTTP",
+      "notes": "",
+      "versus": "jlhttp"
+    }
+  }]
+}

+ 72 - 0
frameworks/Java/jlhttp/pom.xml

@@ -0,0 +1,72 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.techempower</groupId>
+    <artifactId>jlhttp</artifactId>
+    <version>1.0</version>
+    <packaging>jar</packaging>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>net.freeutils</groupId>
+            <artifactId>jlhttp</artifactId>
+            <version>2.2</version>
+        </dependency>
+    <dependency>
+        <groupId>com.fasterxml.jackson.core</groupId>
+        <artifactId>jackson-databind</artifactId>
+        <version>2.7.4</version>
+    </dependency>
+    <dependency>
+        <groupId>com.fasterxml.jackson.module</groupId>
+        <artifactId>jackson-module-afterburner</artifactId>
+        <version>2.7.4</version>
+    </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <inherited>true</inherited>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <configuration>
+                    <source>1.7</source>
+                    <target>1.7</target>
+                    <optimize>true</optimize>
+                    <debug>false</debug>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>2.5.4</version>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <mainClass>hello.HelloWebServer</mainClass>
+                        </manifest>
+                    </archive>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 11 - 0
frameworks/Java/jlhttp/setup.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# specify build requirements
+fw_depends java maven
+
+# build project
+mvn clean compile assembly:single
+
+# run server
+cd target
+java -server -Xss256k -XX:+UseNUMA -XX:+UseParallelGC -XX:+AggressiveOpts -jar jlhttp-1.0-jar-with-dependencies.jar &

+ 2 - 0
frameworks/Java/jlhttp/source_code

@@ -0,0 +1,2 @@
+./jlhttp/src/main/java/hello/HelloWebServer.java
+./jlhttp/src/main/java/hello/Message.java

+ 66 - 0
frameworks/Java/jlhttp/src/main/java/hello/HelloWebServer.java

@@ -0,0 +1,66 @@
+package hello;
+
+import java.io.IOException;
+import java.util.concurrent.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
+import net.freeutils.httpserver.HTTPServer;
+import net.freeutils.httpserver.HTTPServer.*;
+
+public class HelloWebServer {
+
+    private static final String HELLO_TEXT = "Hello, World!";
+    private static final byte[] HELLO_BYTES = HELLO_TEXT.getBytes();
+    private static final String HELLO_LENGTH = Long.toString(HELLO_BYTES.length);
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+
+    static {
+        MAPPER.registerModule(new AfterburnerModule());
+    }
+
+    public static void main(String[] args) throws Exception {
+        // parse arguments
+        int port = args.length > 0 ? Integer.parseInt(args[0]) : 8080;
+
+        // create server
+        HTTPServer server = new HTTPServer(port);
+        server.setExecutor(new ThreadPoolExecutor(
+            8, Integer.MAX_VALUE, 300, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));
+        VirtualHost host = server.getVirtualHost(null); // default virtual host
+
+        // add plaintext test handler
+        host.addContext("/plaintext", new ContextHandler() {
+            @Override
+            public int serve(Request req, Response resp) throws IOException {
+                resp.getHeaders().add("Content-Type", "text/plain");
+                resp.getHeaders().add("Content-Length", HELLO_LENGTH);
+                resp.sendHeaders(200);
+                resp.getOutputStream().write(HELLO_BYTES);
+                return 0;
+            }
+        });
+
+        // add json test handler
+        host.addContext("/json", new ContextHandler() {
+            @Override
+            public int serve(Request req, Response resp) throws IOException {
+                Message msg = new Message(HELLO_TEXT);
+                byte[] bytes;
+                try {
+                    bytes = MAPPER.writeValueAsBytes(msg);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+
+                resp.getHeaders().add("Content-Type", "application/json");
+                resp.getHeaders().add("Content-Length", Long.toString(bytes.length));
+                resp.sendHeaders(200);
+                resp.getOutputStream().write(bytes);
+                return 0;
+            }
+        });
+
+        // start server
+        server.start();
+    }
+}

+ 15 - 0
frameworks/Java/jlhttp/src/main/java/hello/Message.java

@@ -0,0 +1,15 @@
+package hello;
+
+public class Message {
+
+    private final String message;
+
+    public Message(String message) {
+        this.message = message;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+}