Permalink
Browse files

Configurable grizzly io strategies.

  • Loading branch information...
1 parent f01cfd9 commit 7852d256c4667dae85623f1734856e864359ad9a @spmallette spmallette committed Oct 13, 2012
@@ -17,6 +17,7 @@
<max-size>4</max-size>
</kernal>
</thread-pool>
+ <io-strategy>worker</io-strategy>
</http>
<rexpro>
<server-port>8184</server-port>
@@ -33,6 +34,7 @@
<max-size>4</max-size>
</kernal>
</thread-pool>
+ <io-strategy>worker</io-strategy>
</rexpro>
<shutdown-port>8183</shutdown-port>
<shutdown-host>127.0.0.1</shutdown-host>
@@ -17,6 +17,7 @@
<max-size>4</max-size>
</kernal>
</thread-pool>
+ <io-strategy>worker</io-strategy>
</http>
<rexpro>
<server-port>8184</server-port>
@@ -33,6 +34,7 @@
<max-size>4</max-size>
</kernal>
</thread-pool>
+ <io-strategy>worker</io-strategy>
</rexpro>
<shutdown-port>8183</shutdown-port>
<shutdown-host>127.0.0.1</shutdown-host>
@@ -0,0 +1,39 @@
+package com.tinkerpop.rexster.server;
+
+import org.glassfish.grizzly.IOStrategy;
+import org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy;
+import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
+import org.glassfish.grizzly.strategies.SimpleDynamicNIOStrategy;
+import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy;
+
+/**
+ * Creates various IOStrategy implementations for Grizzly.
+ *
+ * http://grizzly.java.net/nonav/docs/docbkx2.0/html/iostrategies.html
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GrizzlyIoStrategyFactory {
+
+ private static final String WORKER = "worker";
+ private static final String SAME = "same";
+ private static final String DYNAMIC = "dynamic";
+ private static final String LEADER_FOLLOWER = "leader-follower";
+
+ public static IOStrategy createIoStrategy(final String strategy) {
+ final IOStrategy ioStrategy;
+ if (strategy.equals(WORKER)) {
+ ioStrategy = WorkerThreadIOStrategy.getInstance();
+ } else if (strategy.equals(SAME)) {
+ ioStrategy = SameThreadIOStrategy.getInstance();
+ } else if (strategy.equals(DYNAMIC)) {
+ ioStrategy = SimpleDynamicNIOStrategy.getInstance();
+ } else if (strategy.equals(LEADER_FOLLOWER)) {
+ ioStrategy = LeaderFollowerNIOStrategy.getInstance();
+ } else {
+ ioStrategy = WorkerThreadIOStrategy.getInstance();
+ }
+
+ return ioStrategy;
+ }
+}
@@ -21,6 +21,7 @@
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger;
+import org.glassfish.grizzly.IOStrategy;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.NetworkListener;
import org.glassfish.grizzly.http.server.ServerConfiguration;
@@ -49,6 +50,7 @@
private final int maxKernalThreadPoolSize;
private final int coreKernalThreadPoolSize;
private final boolean enableJmx;
+ private final String ioStrategy;
private final HttpServer httpServer;
public HttpRexsterServer(final XMLConfiguration properties) {
@@ -62,6 +64,8 @@ public HttpRexsterServer(final XMLConfiguration properties) {
coreKernalThreadPoolSize = properties.getInt("http.thread-pool.kernal.core-size", 4);
maxKernalThreadPoolSize = properties.getInt("http.thread-pool.kernal.max-size", 4);
enableJmx = properties.getBoolean("http.enable-jmx", false);
+ this.ioStrategy = properties.getString("http.io-strategy", "worker");
+
this.httpServer = new HttpServer();
}
@@ -77,6 +81,11 @@ public void start(final RexsterApplication application) throws Exception {
deployDogHouse(application);
final NetworkListener listener = configureNetworkListener();
+ final IOStrategy strategy = GrizzlyIoStrategyFactory.createIoStrategy(this.ioStrategy);
+
+ logger.info(String.format("Using %s IOStrategy for HTTP/REST.", strategy.getClass().getName()));
+
+ configureNetworkListener().getTransport().setIOStrategy(strategy);
this.httpServer.addListener(listener);
this.httpServer.getServerConfiguration().setJmxEnabled(enableJmx);
this.httpServer.start();
@@ -9,10 +9,12 @@
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger;
+import org.glassfish.grizzly.IOStrategy;
import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;
+import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy;
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
@@ -33,6 +35,7 @@
private final int coreWorkerThreadPoolSize;
private final int maxKernalThreadPoolSize;
private final int coreKernalThreadPoolSize;
+ private final String ioStrategy;
public RexProRexsterServer(final XMLConfiguration properties) {
this(properties, true);
@@ -47,6 +50,7 @@ public RexProRexsterServer(final XMLConfiguration properties, final boolean allo
this.maxWorkerThreadPoolSize = properties.getInt("rexpro.thread-pool.worker.max-size", 8);
this.coreKernalThreadPoolSize = properties.getInt("rexpro.thread-pool.kernal.core-size", 4);
this.maxKernalThreadPoolSize = properties.getInt("rexpro.thread-pool.kernal.max-size", 4);
+ this.ioStrategy = properties.getString("rexpro.io-strategy", "worker");
this.tcpTransport = configureTransport();
}
@@ -87,7 +91,11 @@ public void start(final RexsterApplication application) throws Exception {
filterChainBuilder.add(new ScriptFilter(application));
- this.tcpTransport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
+ final IOStrategy strategy = GrizzlyIoStrategyFactory.createIoStrategy(this.ioStrategy);
+
+ logger.info(String.format("Using %s IOStrategy for RexPro.", strategy.getClass().getName()));
+
+ this.tcpTransport.setIOStrategy(strategy);
this.tcpTransport.setProcessor(filterChainBuilder.build());
this.tcpTransport.bind(rexproServerHost, rexproServerPort);
@@ -17,6 +17,7 @@
<max-size>4</max-size>
</kernal>
</thread-pool>
+ <io-strategy>worker</io-strategy>
</http>
<rexpro>
<server-port>8184</server-port>
@@ -33,6 +34,7 @@
<max-size>4</max-size>
</kernal>
</thread-pool>
+ <io-strategy>worker</io-strategy>
</rexpro>
<shutdown-port>8183</shutdown-port>
<shutdown-host>127.0.0.1</shutdown-host>

0 comments on commit 7852d25

Please sign in to comment.