Skip to content

Commit

Permalink
Merge branch 'master' of github.com:TechEmpower/FrameworkBenchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
msmith-techempower committed Dec 8, 2013
2 parents 85d1aa8 + 2eb0251 commit 52668dc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
2 changes: 1 addition & 1 deletion grizzly-bm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>2.3.8-beta1</version>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.glassfish.grizzly.bm;

import com.fasterxml.jackson.databind.*;
import java.io.IOException;
import org.glassfish.grizzly.http.server.HttpHandler;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.RequestExecutorProvider;
import org.glassfish.grizzly.http.server.Response;
import org.glassfish.grizzly.http.util.ContentType;
import org.glassfish.grizzly.http.util.Header;

/**
* Json usecase
*/
public class JsonHttpHandler extends HttpHandler {

private static final ObjectMapper MAPPER = new ObjectMapper();

private static final ContentType CONTENT_TYPE =
ContentType.newContentType("application/json", "utf-8").prepare();

// Response message class.
public static class HelloMessage {
public final String message = "Hello, World!";
Expand All @@ -23,7 +25,7 @@ public static class HelloMessage {
@Override
public void service(final Request request, final Response response)
throws Exception {
response.setContentType("application/json");
response.setContentType(CONTENT_TYPE);
response.setHeader(Header.Server, Server.SERVER_VERSION);

// Write JSON encoded message to the response.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.glassfish.grizzly.bm;

import org.glassfish.grizzly.http.server.HttpHandler;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.RequestExecutorProvider;
import org.glassfish.grizzly.http.server.Response;
import org.glassfish.grizzly.http.util.ContentType;
import org.glassfish.grizzly.http.util.Header;
import org.glassfish.grizzly.utils.Charsets;

/**
* Binary version of plain text usecase
*
* @see PlainTextHttpHandler
*/
public class PlainText2HttpHandler extends HttpHandler {
private static final ContentType CONTENT_TYPE =
ContentType.newContentType("text/plain", "utf-8").prepare();
private static final byte[] HELLO_WORLD_BYTES = "Hello, World!".getBytes(Charsets.UTF8_CHARSET);

@Override
public void service(final Request request, final Response response)
throws Exception {
response.setContentType(CONTENT_TYPE);
response.setHeader(Header.Server, Server.SERVER_VERSION);
response.getOutputStream().write(HELLO_WORLD_BYTES);
}

@Override
public RequestExecutorProvider getRequestExecutorProvider() {
return Server.EXECUTOR_PROVIDER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.RequestExecutorProvider;
import org.glassfish.grizzly.http.server.Response;
import org.glassfish.grizzly.http.util.ContentType;
import org.glassfish.grizzly.http.util.Header;

/**
* Plain text usecase
*/
public class PlainTextHttpHandler extends HttpHandler {
private static final ContentType CONTENT_TYPE =
ContentType.newContentType("text/plain", "utf-8").prepare();

@Override
public void service(final Request request, final Response response)
throws Exception {
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.setContentType(CONTENT_TYPE);
response.setHeader(Header.Server, Server.SERVER_VERSION);
response.getWriter().write("Hello, World!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
* Root {@link HttpHandler} to be used to avoid mapping overhead
*/
public class RootHttpHandler extends HttpHandler {
private final HttpHandler plainTextHandler = new PlainTextHttpHandler();
// Uncomment for real text benchmark
// private final HttpHandler plainTextHandler = new PlainTextHttpHandler();

// Binary PlainText handler
private final HttpHandler plainTextHandler = new PlainText2HttpHandler();
private final HttpHandler jsonHandler = new JsonHttpHandler();

@Override
Expand Down
10 changes: 8 additions & 2 deletions grizzly-bm/src/main/java/org/glassfish/grizzly/bm/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.NetworkListener;
import org.glassfish.grizzly.http.server.RequestExecutorProvider;
import org.glassfish.grizzly.http.util.HeaderValue;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;

/**
* HttpServer
*/
public class Server {
public static final String SERVER_VERSION = "Grizzly/" + Grizzly.getDotedVersion();
public static final HeaderValue SERVER_VERSION =
HeaderValue.newHeaderValue("GRZLY").prepare();

// The RequestExecutorProvider, which will run HTTP request processing
// in the same thread
Expand All @@ -28,11 +30,15 @@ public static void main(String[] args) throws Exception {

// force to not initialize worker thread pool
transport.setWorkerThreadPoolConfig(null);
transport.setSelectorRunnersCount(Runtime.getRuntime().availableProcessors());
transport.setSelectorRunnersCount(Runtime.getRuntime().availableProcessors() * 2);

// always keep-alive
networkListener.getKeepAlive().setIdleTimeoutInSeconds(-1);
networkListener.getKeepAlive().setMaxRequestsCount(-1);

// disable file-cache
networkListener.getFileCache().setEnabled(false);

httpServer.addListener(networkListener);

httpServer.getServerConfiguration().addHttpHandler(
Expand Down

0 comments on commit 52668dc

Please sign in to comment.