Browse Source

Add Undertow JSON serialization benchmark

Undertow is a new Java web server, that is targetted to be the
next web server in the the WildFly (formerly JBoss) application
server.
Stuart Douglas 12 năm trước cách đây
mục cha
commit
659c0c24d2

+ 15 - 0
undertow/README.md

@@ -0,0 +1,15 @@
+# Undertow Benchmarking Test
+
+This is the undertow portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+* [JSON test source](src/main/java/hello/HelloServerHandler.java)
+
+## Versions
+Undertow 1.0.0.Alpha15 (https://github.com/undertow-io/)
+
+## Test URLs
+
+### JSON Encoding Test
+
+    http://localhost:8080

+ 0 - 0
undertow/__init__.py


+ 11 - 0
undertow/benchmark_config

@@ -0,0 +1,11 @@
+{
+  "framework": "undertow",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/",
+      "port": 8080,
+      "sort": 30
+    }
+  }]
+}

+ 93 - 0
undertow/pom.xml

@@ -0,0 +1,93 @@
+<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>undertow-example</artifactId>
+  <version>0.1</version>
+
+  <packaging>jar</packaging>
+
+  <dependencies>
+    <dependency>
+    	<groupId>io.undertow</groupId>
+    	<artifactId>undertow-core</artifactId>
+    	<version>1.0.0.Alpha15</version>
+    </dependency>
+	 <dependency>
+		<groupId>com.fasterxml.jackson.core</groupId>
+		<artifactId>jackson-databind</artifactId>
+		<version>2.1.1</version>
+	</dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+			<plugin>
+				<inherited>true</inherited>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+					<optimize>true</optimize>
+					<debug>false</debug>
+				</configuration>
+			</plugin>
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>hello.HelloWebServer</mainClass>
+            </manifest>
+          </archive>
+          <descriptorRefs>
+            <descriptorRef>jar-with-dependencies</descriptorRef>
+          </descriptorRefs>
+        </configuration>
+        <executions>
+          <execution>
+            <id>make-assembly</id> <!-- this is used for inheritance merges -->
+            <phase>package</phase> <!-- bind to the packaging phase -->
+            <goals>
+              <goal>single</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+       </plugins>
+  </build>
+
+    <repositories>
+        <repository>
+            <id>jboss-public-repository-group</id>
+            <name>JBoss Public Maven Repository Group</name>
+            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
+            <layout>default</layout>
+            <releases>
+                <enabled>true</enabled>
+                <updatePolicy>never</updatePolicy>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>never</updatePolicy>
+            </snapshots>
+        </repository>
+        <repository>
+            <id>jboss-developer-repository-group</id>
+            <name>JBoss Public Maven Repository Group</name>
+            <url>https://repository.jboss.org/nexus/content/groups/developer/</url>
+            <layout>default</layout>
+            <releases>
+                <enabled>true</enabled>
+                <updatePolicy>never</updatePolicy>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>never</updatePolicy>
+            </snapshots>
+        </repository>
+    </repositories>
+</project>

+ 20 - 0
undertow/setup.py

@@ -0,0 +1,20 @@
+import subprocess
+import sys
+import setup_util
+import os
+
+def start(args):
+  try:
+    subprocess.check_call("mvn clean compile assembly:single", shell=True, cwd="undertow")
+    subprocess.Popen("java -jar undertow-example-0.1-jar-with-dependencies.jar".rsplit(" "), cwd="undertow/target")
+    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 'undertow-example' in line:
+      pid = int(line.split(None, 2)[1])
+      os.kill(pid, 9)
+  return 0

+ 86 - 0
undertow/src/main/java/hello/HelloWebServer.java

@@ -0,0 +1,86 @@
+package hello;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.undertow.UndertowOptions;
+import io.undertow.io.IoCallback;
+import io.undertow.server.HttpHandler;
+import io.undertow.server.HttpOpenListener;
+import io.undertow.server.HttpServerExchange;
+import io.undertow.util.Headers;
+import org.xnio.BufferAllocator;
+import org.xnio.ByteBufferSlicePool;
+import org.xnio.ChannelListener;
+import org.xnio.ChannelListeners;
+import org.xnio.OptionMap;
+import org.xnio.Options;
+import org.xnio.Pool;
+import org.xnio.StreamConnection;
+import org.xnio.Xnio;
+import org.xnio.XnioWorker;
+import org.xnio.channels.AcceptingChannel;
+
+public class HelloWebServer {
+
+    private static final ObjectMapper mapper = new ObjectMapper();
+
+    private final int port;
+
+    public HelloWebServer(int port) {
+        this.port = port;
+    }
+
+    public void run() throws Exception {
+
+        Xnio xnio = Xnio.getInstance("nio", HelloWebServer.class.getClassLoader());
+        XnioWorker worker = xnio.createWorker(OptionMap.builder()
+                .set(Options.WORKER_IO_THREADS, Runtime.getRuntime().availableProcessors() * 2)
+                .set(Options.CONNECTION_HIGH_WATER, 1000000)
+                .set(Options.CONNECTION_LOW_WATER, 1000000)
+                .set(Options.TCP_NODELAY, true)
+                .set(Options.CORK, true)
+                .getMap());
+
+        OptionMap serverOptions = OptionMap.builder()
+                .set(Options.TCP_NODELAY, true)
+                .set(Options.REUSE_ADDRESSES, true)
+                .getMap();
+
+        Pool<ByteBuffer> buffers = new ByteBufferSlicePool(BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR, 2048, 2048 * 2048);
+
+        HttpHandler rootHandler = new HttpHandler() {
+            @Override
+            public void handleRequest(final HttpServerExchange exchange) throws Exception {
+                exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");
+                Map<String, String> data = new HashMap<String, String>();
+                data.put("message", "Hello, world");
+                String response = mapper.writeValueAsString(data);
+                exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, response.length());
+                exchange.getResponseSender().send(response, IoCallback.END_EXCHANGE);
+            }
+        };
+
+        HttpOpenListener openListener = new HttpOpenListener(buffers, OptionMap.create(UndertowOptions.BUFFER_PIPELINED_DATA, true), 2048);
+        openListener.setRootHandler(rootHandler);
+        ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener);
+        AcceptingChannel<? extends StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(InetAddress.getByAddress(new byte[]{0, 0, 0, 0}), port), acceptListener, serverOptions);
+        server.resumeAccepts();
+
+
+    }
+
+    public static void main(String[] args) throws Exception {
+        int port;
+        if (args.length > 0) {
+            port = Integer.parseInt(args[0]);
+        } else {
+            port = 8080;
+        }
+        new HelloWebServer(port).run();
+    }
+}