Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frameworks/Java/vertx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This is the Vert.x portion of a [benchmarking test suite](../) comparing a varie
## Versions

* [Java 17](https://jdk.java.net)
* [vertx 4.3.8](http://vertx.io/)
* [vertx 5.0.0.CR6](http://vertx.io/)

## Test URLs

Expand Down
25 changes: 12 additions & 13 deletions frameworks/Java/vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
<maven.compiler.target>17</maven.compiler.target>
<!-- the main class -->
<main.class>vertx.App</main.class>
<stack.version>4.5.9</stack.version>
<vertx.version>5.0.0.CR6</vertx.version>
<netty.version>4.2.0.Final</netty.version>
<jackson.version>2.16.1</jackson.version>
<netty.version>4.1.111.Final</netty.version>
<netty.io_uring.version>0.0.25.Final</netty.io_uring.version>
</properties>

<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${stack.version}</version>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core-logging</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-pg-client</artifactId>
<version>${stack.version}</version>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>com.dslplatform</groupId>
Expand Down Expand Up @@ -151,14 +155,9 @@
</activation>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-io_uring-incubator</artifactId>
<version>${stack.version}</version>
</dependency>
<dependency>
<groupId>io.netty.incubator</groupId>
<artifactId>netty-incubator-transport-native-io_uring</artifactId>
<version>${netty.io_uring.version}</version>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-io_uring</artifactId>
<version>${netty.version}</version>
<classifier>linux-x86_64</classifier>
</dependency>
</dependencies>
Expand Down
137 changes: 86 additions & 51 deletions frameworks/Java/vertx/src/main/java/vertx/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.fizzed.rocker.ContentType;
import com.fizzed.rocker.RockerOutputFactory;
import io.netty.util.concurrent.MultithreadEventExecutorGroup;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.impl.SysProps;
import io.vertx.core.internal.VertxInternal;
import io.vertx.core.internal.logging.Logger;
import io.vertx.core.internal.logging.LoggerFactory;
import io.vertx.pgclient.*;
import io.vertx.core.*;
import io.vertx.core.buffer.Buffer;
Expand All @@ -13,8 +16,6 @@
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonObject;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.sqlclient.*;
import io.vertx.sqlclient.impl.SqlClientInternal;
import vertx.model.*;
Expand Down Expand Up @@ -73,21 +74,20 @@ static int getQueries(HttpServerRequest request) {
private static final String PATH_FORTUNES = "/fortunes";
private static final String PATH_CACHING = "/cached-queries";

private static final Handler<AsyncResult<Void>> NULL_HANDLER = null;

private static final CharSequence RESPONSE_TYPE_PLAIN = HttpHeaders.createOptimized("text/plain");
private static final CharSequence RESPONSE_TYPE_HTML = HttpHeaders.createOptimized("text/html; charset=UTF-8");
static final CharSequence RESPONSE_TYPE_JSON = HttpHeaders.createOptimized("application/json");
private static final CharSequence RESPONSE_TYPE_JSON = HttpHeaders.createOptimized("application/json");

private static final String HELLO_WORLD = "Hello, world!";
private static final Buffer HELLO_WORLD_BUFFER = Buffer.buffer(HELLO_WORLD, "UTF-8");

private static final CharSequence HEADER_SERVER = HttpHeaders.createOptimized("server");
private static final CharSequence HEADER_DATE = HttpHeaders.createOptimized("date");
private static final CharSequence HEADER_CONTENT_TYPE = HttpHeaders.createOptimized("content-type");
private static final CharSequence HEADER_CONTENT_LENGTH = HttpHeaders.createOptimized("content-length");
private static final CharSequence HEADER_SERVER = HttpHeaders.SERVER;
private static final CharSequence HEADER_DATE = HttpHeaders.DATE;
private static final CharSequence HEADER_CONTENT_TYPE = HttpHeaders.CONTENT_TYPE;
private static final CharSequence HEADER_CONTENT_LENGTH = HttpHeaders.CONTENT_LENGTH;

private static final CharSequence HELLO_WORLD_LENGTH = HttpHeaders.createOptimized("" + HELLO_WORLD.length());
private static final CharSequence JSON_LENGTH = HttpHeaders.createOptimized("" + new Message("Hello, World!").toJson().length());
private static final CharSequence SERVER = HttpHeaders.createOptimized("vert.x");

private static final String SELECT_WORLD = "SELECT id, randomnumber from WORLD where id=$1";
Expand All @@ -114,7 +114,8 @@ static Integer boxedRandomWorldNumber() {
private HttpServer server;
private SqlClientInternal client;
private CharSequence dateString;
private CharSequence[] plaintextHeaders;
private MultiMap plaintextHeaders;
private MultiMap jsonHeaders;

private final RockerOutputFactory<BufferRockerOutput> factory = BufferRockerOutput.factory(ContentType.RAW);

Expand All @@ -125,19 +126,43 @@ static Integer boxedRandomWorldNumber() {
private PreparedQuery<RowSet<Row>>[] AGGREGATED_UPDATE_WORLD_QUERY = new PreparedQuery[500];
private WorldCache WORLD_CACHE;

private MultiMap plaintextHeaders() {
return HttpHeaders
.headers()
.add(HEADER_CONTENT_TYPE, RESPONSE_TYPE_PLAIN)
.add(HEADER_SERVER, SERVER)
.add(HEADER_DATE, dateString)
.add(HEADER_CONTENT_LENGTH, HELLO_WORLD_LENGTH)
.copy(false);
}

private MultiMap jsonHeaders() {
return HttpHeaders
.headers()
.add(HEADER_CONTENT_TYPE, RESPONSE_TYPE_JSON)
.add(HEADER_SERVER, SERVER)
.add(HEADER_DATE, dateString)
.add(HEADER_CONTENT_LENGTH, JSON_LENGTH)
.copy(false);
}

@Override
public void start(Promise<Void> startPromise) throws Exception {
int port = 8080;
server = vertx.createHttpServer(new HttpServerOptions())
server = vertx
.createHttpServer(new HttpServerOptions()
.setHttp2ClearTextEnabled(false)
.setStrictThreadMode(true))
.requestHandler(App.this);
dateString = createDateHeader();
plaintextHeaders = new CharSequence[] {
HEADER_CONTENT_TYPE, RESPONSE_TYPE_PLAIN,
HEADER_SERVER, SERVER,
HEADER_DATE, dateString,
HEADER_CONTENT_LENGTH, HELLO_WORLD_LENGTH };
plaintextHeaders = plaintextHeaders();
jsonHeaders = jsonHeaders();
JsonObject config = config();
vertx.setPeriodic(1000, id -> plaintextHeaders[5] = dateString = createDateHeader());
vertx.setPeriodic(1000, id -> {
dateString = createDateHeader();
plaintextHeaders = plaintextHeaders();
jsonHeaders = jsonHeaders();
});
PgConnectOptions options = new PgConnectOptions();
options.setDatabase(config.getString("database", "hello_world"));
options.setHost(config.getString("host", "tfb-database"));
Expand Down Expand Up @@ -261,26 +286,19 @@ private void sendError(HttpServerRequest req, Throwable cause) {

private void handlePlainText(HttpServerRequest request) {
HttpServerResponse response = request.response();
MultiMap headers = response.headers();
for (int i = 0;i < plaintextHeaders.length; i+= 2) {
headers.add(plaintextHeaders[i], plaintextHeaders[i + 1]);
}
response.end(HELLO_WORLD_BUFFER, NULL_HANDLER);
response.headers().setAll(plaintextHeaders);
response.end(HELLO_WORLD_BUFFER);
}

private void handleJson(HttpServerRequest request) {
HttpServerResponse response = request.response();
MultiMap headers = response.headers();
headers
.add(HEADER_CONTENT_TYPE, RESPONSE_TYPE_JSON)
.add(HEADER_SERVER, SERVER)
.add(HEADER_DATE, dateString);
response.end(new Message("Hello, World!").toJson(), NULL_HANDLER);
response.headers().setAll(jsonHeaders);
response.end(new Message("Hello, World!").toJson());
}

private void handleDb(HttpServerRequest req) {
HttpServerResponse resp = req.response();
SELECT_WORLD_QUERY.execute(Tuple.of(boxedRandomWorldNumber()), res -> {
SELECT_WORLD_QUERY.execute(Tuple.of(boxedRandomWorldNumber())).onComplete(res -> {
if (res.succeeded()) {
RowIterator<Row> resultSet = res.result().iterator();
if (!resultSet.hasNext()) {
Expand All @@ -293,7 +311,7 @@ private void handleDb(HttpServerRequest req) {
headers.add(HttpHeaders.SERVER, SERVER);
headers.add(HttpHeaders.DATE, dateString);
headers.add(HttpHeaders.CONTENT_TYPE, RESPONSE_TYPE_JSON);
resp.end(word.toJson(), NULL_HANDLER);
resp.end(word.toJson());
} else {
sendError(req, res.cause());
}
Expand Down Expand Up @@ -322,7 +340,9 @@ public Queries(HttpServerRequest req) {
private void handle() {
client.group(c -> {
for (int i = 0; i < queries; i++) {
c.preparedQuery(SELECT_WORLD).execute(Tuple.of(boxedRandomWorldNumber()), this);
c.preparedQuery(SELECT_WORLD)
.execute(Tuple.of(boxedRandomWorldNumber()))
.onComplete(this);
}
});
}
Expand All @@ -346,7 +366,7 @@ public void handle(AsyncResult<RowSet<Row>> ar) {
headers.add(HttpHeaders.SERVER, SERVER);
headers.add(HttpHeaders.DATE, dateString);
headers.add(HttpHeaders.CONTENT_TYPE, RESPONSE_TYPE_JSON);
resp.end(World.toJson(worlds), NULL_HANDLER);
resp.end(World.toJson(worlds));
}
}
}
Expand All @@ -370,7 +390,7 @@ public void handle() {
for (int i = 0; i < worldsToUpdate.length; i++) {
final Integer id = boxedRandomWorldNumber();
final int index = i;
preparedQuery.execute(Tuple.of(id), res -> {
preparedQuery.execute(Tuple.of(id)).onComplete(res -> {
if (!failed) {
if (res.failed()) {
failed = true;
Expand All @@ -395,7 +415,9 @@ private void randomWorldsQueryCompleted() {
params.add(world.getId());
params.add(world.getRandomNumber());
}
AGGREGATED_UPDATE_WORLD_QUERY[worldsToUpdate.length - 1].execute(Tuple.wrap(params), updateResult -> {
AGGREGATED_UPDATE_WORLD_QUERY[worldsToUpdate.length - 1]
.execute(Tuple.wrap(params))
.onComplete(updateResult -> {
if (updateResult.failed()) {
sendError(request, updateResult.cause());
return;
Expand All @@ -411,12 +433,14 @@ private void sendResponse() {
headers.add(HttpHeaders.DATE, dateString);
headers.add(HttpHeaders.CONTENT_TYPE, RESPONSE_TYPE_JSON);
Buffer buff = WorldJsonSerializer.toJsonBuffer(worldsToUpdate);
res.end(buff, null);
res.end(buff);
}
}

private void handleFortunes(HttpServerRequest req) {
SELECT_FORTUNE_QUERY.execute(ar -> {
SELECT_FORTUNE_QUERY
.execute()
.onComplete(ar -> {
HttpServerResponse response = req.response();
if (ar.succeeded()) {
SqlResult<List<Fortune>> result = ar.result();
Expand All @@ -432,7 +456,7 @@ private void handleFortunes(HttpServerRequest req) {
headers.add(HttpHeaders.DATE, dateString);
headers.add(HttpHeaders.CONTENT_TYPE, RESPONSE_TYPE_HTML);
FortunesTemplate template = FortunesTemplate.template(fortunes);
response.end(template.render(factory).buffer(), NULL_HANDLER);
response.end(template.render(factory).buffer());
} else {
sendError(req, ar.cause());
}
Expand All @@ -457,7 +481,7 @@ private void handleCaching(HttpServerRequest req) {
.add(HEADER_CONTENT_TYPE, RESPONSE_TYPE_JSON)
.add(HEADER_SERVER, SERVER)
.add(HEADER_DATE, dateString);
response.end(CachedWorld.toJson(worlds), NULL_HANDLER);
response.end(CachedWorld.toJson(worlds));
}

public static void main(String[] args) throws Exception {
Expand All @@ -471,24 +495,30 @@ public static void main(String[] args) throws Exception {
}
}
JsonObject config = new JsonObject(new String(Files.readAllBytes(new File(args[0]).toPath())));
Vertx vertx = Vertx.vertx(new VertxOptions().setEventLoopPoolSize(eventLoopPoolSize).setPreferNativeTransport(true));
Vertx vertx = Vertx.vertx(new VertxOptions()
.setEventLoopPoolSize(eventLoopPoolSize)
.setPreferNativeTransport(true)
.setDisableTCCL(true)
);
vertx.exceptionHandler(err -> {
err.printStackTrace();
});
printConfig(vertx);
vertx.deployVerticle(App.class.getName(),
new DeploymentOptions().setInstances(eventLoopPoolSize).setConfig(config), event -> {
if (event.succeeded()) {
logger.info("Server listening on port " + 8080);
} else {
logger.error("Unable to start your application", event.cause());
}
});
printConfig((VertxInternal) vertx);
vertx.deployVerticle(
App.class.getName(),
new DeploymentOptions().setInstances(eventLoopPoolSize).setConfig(config))
.onComplete(event -> {
if (event.succeeded()) {
logger.info("Server listening on port " + 8080);
} else {
logger.error("Unable to start your application", event.cause());
}
});
}

private static void printConfig(Vertx vertx) {
private static void printConfig(VertxInternal vertx) {
boolean nativeTransport = vertx.isNativeTransportEnabled();
String transport = ((VertxInternal) vertx).transport().getClass().getSimpleName();
String transport = vertx.transport().getClass().getSimpleName();
String version = "unknown";
try {
InputStream in = Vertx.class.getClassLoader().getResourceAsStream("META-INF/vertx/vertx-version.txt");
Expand All @@ -513,5 +543,10 @@ private static void printConfig(Vertx vertx) {
logger.info("Event Loop Size: " + ((MultithreadEventExecutorGroup)vertx.nettyEventLoopGroup()).executorCount());
logger.info("Native transport : " + nativeTransport);
logger.info("Transport : " + transport);
logger.info("Netty buffer bound check : " + System.getProperty("io.netty.buffer.checkBounds"));
logger.info("Netty buffer accessibility check : " + System.getProperty("io.netty.buffer.checkAccessible"));
for (SysProps sysProp : SysProps.values()) {
logger.info(sysProp.name + " : " + sysProp.get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.fizzed.rocker.RockerOutputFactory;
import io.netty.buffer.ByteBuf;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.buffer.impl.PartialPooledByteBufAllocator;
import io.vertx.core.impl.buffer.VertxByteBufAllocator;
import io.vertx.core.internal.buffer.BufferInternal;

import java.io.IOException;
import java.nio.charset.Charset;
Expand All @@ -21,8 +22,8 @@ public static RockerOutputFactory<BufferRockerOutput> factory(ContentType conten
};
}

private final ByteBuf buff = PartialPooledByteBufAllocator.INSTANCE.directBuffer();
private final Buffer buffer = Buffer.buffer(buff);
private final ByteBuf buff = VertxByteBufAllocator.DEFAULT.directBuffer();
private final Buffer buffer = BufferInternal.buffer(buff);
private final ContentType contentType;

BufferRockerOutput(ContentType contentType) {
Expand Down
6 changes: 2 additions & 4 deletions frameworks/Java/vertx/vertx-postgres.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ CMD export DBIP=`getent hosts tfb-database | awk '{ print $1 }'` && \
-XX:+UseParallelGC \
-Djava.lang.Integer.IntegerCache.high=10000 \
-Dvertx.disableMetrics=true \
-Dvertx.disableH2c=true \
-Dvertx.disableWebsockets=true \
-Dvertx.flashPolicyHandler=false \
-Dvertx.threadChecks=false \
-Dvertx.disableContextTimings=true \
-Dvertx.disableTCCL=true \
-Dvertx.disableHttpHeadersValidation=true \
-Dvertx.cacheImmutableHttpResponseHeaders=true \
-Dvertx.internCommonHttpRequestHeadersToLowerCase=true \
-Dvertx.eventLoopPoolSize=$((`grep --count ^processor /proc/cpuinfo`)) \
-Dio.netty.buffer.checkBounds=false \
-Dio.netty.buffer.checkAccessible=false \
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Java/vertx/vertx.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RUN mvn package -q

EXPOSE 8080

CMD ["java", "-Xms2G", "-Xmx2G", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-Djava.lang.Integer.IntegerCache.high=10000", "-Dvertx.disableMetrics=true", "-Dvertx.disableH2c=true", "-Dvertx.disableWebsockets=true", "-Dvertx.flashPolicyHandler=false", "-Dvertx.threadChecks=false", "-Dvertx.disableContextTimings=true", "-Dvertx.disableTCCL=true", "-Dvertx.disableHttpHeadersValidation=true", "-Dio.netty.buffer.checkBounds=false", "-Dio.netty.buffer.checkAccessible=false", "-jar", "target/vertx.benchmark-0.0.1-SNAPSHOT-fat.jar", "src/main/conf/config.json"]
CMD ["java", "-Xms2G", "-Xmx2G", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-Djava.lang.Integer.IntegerCache.high=10000", "-Dvertx.disableMetrics=true", "-Dvertx.disableWebsockets=true", "-Dvertx.disableContextTimings=true", "-Dvertx.disableHttpHeadersValidation=true", "-Dvertx.cacheImmutableHttpResponseHeaders=true", "-Dvertx.internCommonHttpRequestHeadersToLowerCase=true", "-Dio.netty.buffer.checkBounds=false", "-Dio.netty.buffer.checkAccessible=false", "-jar", "target/vertx.benchmark-0.0.1-SNAPSHOT-fat.jar", "src/main/conf/config.json"]
Loading