Browse Source

Update blocking endpoints. Improve JVM params. (#4275)

noboomu 6 years ago
parent
commit
1bd9933ef2

+ 1 - 1
frameworks/Java/proteus/proteus.dockerfile

@@ -9,4 +9,4 @@ WORKDIR /proteus
 COPY --from=maven /proteus/target/proteus-techempower-1.0.0.jar app.jar
 COPY --from=maven /proteus/target/lib lib
 COPY conf conf
-CMD ["java", "-Dlogback.configurationFile=conf/logback.xml", "-Dconfig.file=conf/application.conf", "-Xms2g", "-Xmx2g", "-XX:+AggressiveOpts", "-server", "-XX:-UseBiasedLocking", "-XX:+UseStringDeduplication", "-Djava.net.preferIPv4Stack=true", "-classpath", "app.jar:lib/*", "io.sinistral.ExampleApplication"]
+CMD ["java", "-Dlogback.configurationFile=conf/logback.xml", "-Dconfig.file=conf/application.conf", "-Xms4g", "-Xmx4g", "-XX:+AggressiveOpts", "-server", "-XX:-UseBiasedLocking", "-XX:+UseStringDeduplication", "-Djava.net.preferIPv4Stack=true", "-XX:+UseNUMA", "-classpath", "app.jar:lib/*", "io.sinistral.ExampleApplication"]

+ 3 - 2
frameworks/Java/proteus/run.sh

@@ -2,12 +2,13 @@
 java \
   -Dlogback.configurationFile="conf/logback.xml" \
   -Dconfig.file="conf/application.conf" \
-  -Xms2g \
-  -Xmx2g \
+  -Xms4g \
+  -Xmx4g \
   -XX:+AggressiveOpts \
   -server \
   -XX:-UseBiasedLocking \
   -XX:+UseStringDeduplication \
   -Djava.net.preferIPv4Stack=true \
+  -XX:+UseNUMA \
   -classpath "/proteus/target/proteus-techempower-1.0.0.jar:/proteus/target/lib/*" \
   io.sinistral.ExampleApplication

+ 2 - 1
frameworks/Java/proteus/src/main/java/io/sinistral/ExampleApplication.java

@@ -48,12 +48,13 @@ public class ExampleApplication extends ProteusApplication
 		
 		Undertow.Builder undertowBuilder = Undertow.builder().addHttpListener(httpPort, config.getString("application.host"))
 				.setBufferSize(16 * 1024)
+				.setDirectBuffers(true)
 				.setIoThreads(Runtime.getRuntime().availableProcessors() * 2)
 				.setSocketOption(org.xnio.Options.BACKLOG, 10000)
 				.setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, false)
 				.setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, false)
 				.setServerOption(UndertowOptions.MAX_ENTITY_SIZE, config.getBytes("undertow.server.maxEntitySize"))
-				.setWorkerThreads(200)
+				.setWorkerThreads(Runtime.getRuntime().availableProcessors() * 8)
 				.setHandler(rootHandler);
 		
 		this.undertow = undertowBuilder.build();

+ 93 - 109
frameworks/Java/proteus/src/main/java/io/sinistral/proteus/controllers/handlers/BenchmarksRouteSupplier.java

@@ -5,6 +5,7 @@ import static io.sinistral.proteus.server.Extractors.*;
 import com.google.inject.Inject;
 import com.google.inject.name.Named;
 import io.sinistral.controllers.Benchmarks;
+import io.undertow.server.DefaultResponseListener;
 import io.undertow.server.HandlerWrapper;
 import io.undertow.server.HttpHandler;
 import io.undertow.server.RoutingHandler;
@@ -15,116 +16,99 @@ import java.util.Map;
 import java.util.function.Supplier;
 
 /**
- * 
  * This would normally be generated by the ProteusApplication.
  * @author noboomu
- *
  */
-public class BenchmarksRouteSupplier implements Supplier<HttpHandler> {
-  protected final Benchmarks benchmarksController;
-
-  protected final Map<String, HandlerWrapper> registeredHandlerWrappers;
-
-  @Inject
-  public BenchmarksRouteSupplier(Benchmarks benchmarksController,
-      @Named("registeredHandlerWrappers") Map<String, HandlerWrapper> registeredHandlerWrappers) {
-    this.benchmarksController = benchmarksController;
-    this.registeredHandlerWrappers = registeredHandlerWrappers;
-  }
-
-  public HttpHandler get() {
-	  
-    final PathHandler router = new PathHandler();
-
-    final io.undertow.server.HttpHandler benchmarksDbPostgresHandler = new io.undertow.server.HttpHandler() {
-      @java.lang.Override
-      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
-          java.lang.Exception {
-
-            exchange.dispatch(() ->
-            {
-              try
-              {
-                benchmarksController.dbPostgres(exchange);
-              } catch (Exception e)
-              {
-                exchange.putAttachment(io.sinistral.proteus.server.handlers.ServerDefaultResponseListener.EXCEPTION, e);
-                exchange.endExchange();
-              }
-            });
-      }
-    };
-
-    router.addExactPath("/db",new io.undertow.server.handlers.BlockingHandler(benchmarksDbPostgresHandler));
-    
-
-
-    final io.undertow.server.HttpHandler benchmarksDbMySqlHandler = new io.undertow.server.HttpHandler() {
-      @java.lang.Override
-      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
-          java.lang.Exception {
-
-        benchmarksController.dbMySql(exchange);
-      }
-    };
-
-    router.addExactPath("/db/mysql",new io.undertow.server.handlers.BlockingHandler(benchmarksDbMySqlHandler));
-
-    final io.undertow.server.HttpHandler benchmarksFortunesMysqlHandler = new io.undertow.server.HttpHandler() {
-      @java.lang.Override
-      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
-          java.lang.Exception {
-
-        benchmarksController.fortunesMysql(exchange);
-      }
-    };
-
-    router.addExactPath("/fortunes/mysql",new io.undertow.server.handlers.BlockingHandler(benchmarksFortunesMysqlHandler));
-
-    final io.undertow.server.HttpHandler benchmarksFortunesPostgresHandler = new io.undertow.server.HttpHandler() {
-      @java.lang.Override
-      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
-          java.lang.Exception {
-
-            exchange.dispatch(() ->
-            {
-              try
-              {
-                benchmarksController.fortunesPostgres(exchange);
-              } catch (Exception e)
-              {
-                exchange.putAttachment(io.sinistral.proteus.server.handlers.ServerDefaultResponseListener.EXCEPTION, e);
-                exchange.endExchange();
-              }
-            });
-      }
-    };
-
-    router.addExactPath("/fortunes",new io.undertow.server.handlers.BlockingHandler(benchmarksFortunesPostgresHandler));
-
-    final io.undertow.server.HttpHandler benchmarksPlaintextHandler = new io.undertow.server.HttpHandler() {
-      @java.lang.Override
-      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
-          java.lang.Exception {
-
-        benchmarksController.plaintext(exchange);
-      }
-    };
-
-    router.addExactPath("/plaintext",benchmarksPlaintextHandler);
-
-    final io.undertow.server.HttpHandler benchmarksJsonHandler = new io.undertow.server.HttpHandler() {
-      @java.lang.Override
-      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
-          java.lang.Exception {
-
-        benchmarksController.json(exchange);
-      }
-    };
-
-    router.addExactPath("/json",benchmarksJsonHandler);
-
-
-    return router;
-  }
+public class BenchmarksRouteSupplier implements Supplier<HttpHandler>
+{
+	protected final Benchmarks benchmarksController;
+
+	protected final Map<String, HandlerWrapper> registeredHandlerWrappers;
+
+	@Inject
+	public BenchmarksRouteSupplier(Benchmarks benchmarksController, @Named("registeredHandlerWrappers") Map<String, HandlerWrapper> registeredHandlerWrappers)
+	{
+		this.benchmarksController = benchmarksController;
+		this.registeredHandlerWrappers = registeredHandlerWrappers;
+	}
+
+	public HttpHandler get()
+	{
+
+		final PathHandler router = new PathHandler();
+ 
+		final io.undertow.server.HttpHandler benchmarksDbPostgresHandler = new io.undertow.server.HttpHandler()
+		{
+				@java.lang.Override
+				public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception
+				{ 
+					benchmarksController.dbPostgres(exchange); 
+				}
+		};
+
+		router.addExactPath("/db", benchmarksDbPostgresHandler);
+
+		
+		final io.undertow.server.HttpHandler benchmarksDbMySqlHandler = new io.undertow.server.HttpHandler()
+		{
+			@java.lang.Override
+			public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception
+			{
+				benchmarksController.dbMySql(exchange);
+			}
+		};
+
+		router.addExactPath("/db/mysql", benchmarksDbMySqlHandler);
+
+
+		final io.undertow.server.HttpHandler benchmarksFortunesMysqlHandler = new io.undertow.server.HttpHandler()
+		{
+			@java.lang.Override
+			public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception
+			{ 
+				benchmarksController.fortunesMysql(exchange);
+			}
+		};
+
+		router.addExactPath("/fortunes/mysql", benchmarksFortunesMysqlHandler);
+
+		final io.undertow.server.HttpHandler benchmarksFortunesPostgresDispatchHandler = new io.undertow.server.HttpHandler()
+		{
+			@java.lang.Override
+			public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception
+			{ 
+				benchmarksController.fortunesPostgres(exchange);
+			}
+		};
+
+		router.addExactPath("/fortunes", benchmarksFortunesPostgresDispatchHandler);
+
+
+		final io.undertow.server.HttpHandler benchmarksPlaintextHandler = new io.undertow.server.HttpHandler()
+		{
+			@java.lang.Override
+			public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception
+			{ 
+				benchmarksController.plaintext(exchange);
+			}
+		};
+
+		router.addExactPath("/plaintext", benchmarksPlaintextHandler);
+ 
+
+		final io.undertow.server.HttpHandler benchmarksJsonHandler = new io.undertow.server.HttpHandler()
+		{
+			@java.lang.Override
+			public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception
+			{
+
+				benchmarksController.json(exchange);
+			}
+		};
+
+		router.addExactPath("/json", benchmarksJsonHandler);
+
+		return router;
+	}
 }
+