Skip to content
Open
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
Binary file modified frameworks/Java/tadx/build/libs/tadx-benchmark-0.0.1-SNAPSHOT.jar
Binary file not shown.
178 changes: 0 additions & 178 deletions frameworks/Java/tadx/src/main/java/io/tadx/benchmark/Application.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
package io.tadx.benchmark;

/*import io.netty.util.concurrent.MultithreadEventExecutorGroup;
import io.tadx.core.logging.LogFactory;
import io.vertx.core.*;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.*;
import io.vertx.core.impl.SysProps;
import io.vertx.core.internal.VertxInternal;
import io.vertx.core.json.JsonObject;*/
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/*import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;*/


/**
* The main program loads the configuration and starts the server by `tadx-web` <br/>
Expand All @@ -28,170 +14,6 @@
public class Application { // extends VerticleBase implements Handler<HttpServerRequest>

public static void main(String[] args) {

SpringApplication.run(Application.class, args);


/*Vertx vertx = Vertx.vertx(new VertxOptions()
.setEventLoopPoolSize(Runtime.getRuntime().availableProcessors())
.setPreferNativeTransport(true)
.setDisableTCCL(true)
);
vertx.exceptionHandler(err -> {
LogFactory.frameworkLogger().warn("Uncaught exception: " + err);
});
vertx.deployVerticle(Application.class.getName(), new DeploymentOptions().setInstances(Runtime.getRuntime().availableProcessors()))
.onComplete(event -> {
if (event.succeeded()) {
LogFactory.frameworkLogger().warn("Server listening on port " + 8080);
} else {
LogFactory.frameworkLogger().warn("Unable to start your application "+event.cause());
}
});*/
}

/*

private HttpServer server;
private CharSequence dateString;
private MultiMap plaintextHeaders;
private MultiMap jsonHeaders;private static final String PATH_PLAINTEXT = "/plaintext";
private static final String PATH_JSON = "/json";
private static final String PATH_DB = "/db";
private static final String PATH_QUERIES = "/queries";
private static final String PATH_UPDATES = "/updates";
private static final String PATH_FORTUNES = "/fortunes";
private static final String PATH_CACHING = "/cached-queries";

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");
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.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("" + JsonObject.of("message", "Hello, World!").toString().length());
private static final CharSequence SERVER = HttpHeaders.createOptimized("vert.x");
@Override
public Future<?> start() throws Exception {
int port = 8000;
printConfig((VertxInternal) vertx);
server = vertx.createHttpServer(new HttpServerOptions()
.setHttp2ClearTextEnabled(false)
.setStrictThreadMode(true))
.requestHandler(Application.this);
dateString = createDateHeader();
plaintextHeaders = plaintextHeaders();
jsonHeaders = jsonHeaders();
JsonObject config = config();
vertx.setPeriodic(1000, id -> {
dateString = createDateHeader();
plaintextHeaders = plaintextHeaders();
jsonHeaders = jsonHeaders();
});
return server.listen(port);
}

@Override
public Future<?> stop() throws Exception {
return super.stop();
}

@Override
public void handle(HttpServerRequest request) {
try {
switch (request.path()) {
case PATH_PLAINTEXT:
handlePlainText(request);
break;
case PATH_JSON:
handleJson(request);
break;
default:
request.response()
.setStatusCode(404)
.end();
break;
}
} catch (Exception e) {
LogFactory.frameworkLogger().warn("Error: " + e);
request.response().setStatusCode(500).end();
}
}

private void handlePlainText(HttpServerRequest request) {
HttpServerResponse response = request.response();
response.headers().setAll(plaintextHeaders);
response.end(HELLO_WORLD_BUFFER);
}

private void handleJson(HttpServerRequest request) {
HttpServerResponse response = request.response();
response.headers().setAll(jsonHeaders);
response.end(JsonObject.of("message", "Hello, World!").toString());
}

public static CharSequence createDateHeader() {
return HttpHeaders.createOptimized(DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now()));
}

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);
}

private static void printConfig(VertxInternal vertx) {
boolean nativeTransport = vertx.isNativeTransportEnabled();
String transport = vertx.transport().getClass().getSimpleName();
String version = "unknown";
try {
InputStream in = Vertx.class.getClassLoader().getResourceAsStream("META-INF/vertx/vertx-version.txt");
if (in == null) {
in = Vertx.class.getClassLoader().getResourceAsStream("vertx-version.txt");
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[256];
while (true) {
int amount = in.read(buffer);
if (amount == -1) {
break;
}
out.write(buffer, 0, amount);
}
version = out.toString();
} catch (IOException e) {
LogFactory.frameworkLogger().warn("Could not read Vertx version" + e);;
}
LogFactory.frameworkLogger().warn("Vertx: " + version);
LogFactory.frameworkLogger().warn("Processors: " + Runtime.getRuntime().availableProcessors());
LogFactory.frameworkLogger().warn("Event Loop Size: " + ((MultithreadEventExecutorGroup)vertx.nettyEventLoopGroup()).executorCount());
LogFactory.frameworkLogger().warn("Native transport : " + nativeTransport);
LogFactory.frameworkLogger().warn("Transport : " + transport);
LogFactory.frameworkLogger().warn("Netty buffer bound check : " + System.getProperty("io.netty.buffer.checkBounds"));
LogFactory.frameworkLogger().warn("Netty buffer accessibility check : " + System.getProperty("io.netty.buffer.checkAccessible"));
for (SysProps sysProp : SysProps.values()) {
LogFactory.frameworkLogger().warn(sysProp.name + " : " + sysProp.get());
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private static synchronized void createClient() {
setPassword("benchmarkdbpass").
setCachePreparedStatements(true).
setPreparedStatementCacheMaxSize(1024).
setPipeliningLimit(100000);
PoolOptions poolOptions = new PoolOptions().setMaxSize(1900);
setPipeliningLimit(256);
PoolOptions poolOptions = new PoolOptions().setMaxSize(190);
// Create the client pool
client = (SqlClientInternal) PgBuilder.client().with(poolOptions).connectingTo(connectOptions).using(TadxApplication.vertx()).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.tadx.web.TadxWebApplication;
import io.tadx.web.WebContext;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.impl.SqlClientInternal;
Expand Down Expand Up @@ -65,11 +65,8 @@ public void run(WebContext webContext) {
int id = randomWorld();
worlds.add(cache.get(id));
}
webContext.routingContext().response()
.putHeader("Content-Type", "application/json;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString)
.end(Json.stringify(worlds));
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.routingContext().response().end(Json.stringify(worlds));
}

static int randomWorld() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.tadx.web.TadxWebApplication;
import io.tadx.web.WebContext;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.impl.SqlClientInternal;
Expand Down Expand Up @@ -66,11 +66,8 @@ public void run(WebContext webContext) {
int id = randomWorld();
worlds.add(cache.get(id));
}
webContext.routingContext().response()
.putHeader("Content-Type", "application/json;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString)
.end(Json.stringify(worlds));
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.routingContext().response().end(Json.stringify(worlds));
}

static int randomWorld() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.tadx.web.TadxWebApplication;
import io.tadx.web.WebContext;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.impl.SqlClientInternal;
Expand Down Expand Up @@ -67,11 +67,8 @@ public void run(WebContext webContext) {
for (int i = 0; i < count; i++) {
worlds.add(cache.getIfPresent(current.nextInt(1000)));
}
webContext.routingContext().response()
.putHeader("Content-Type", "application/json;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString)
.end(Json.stringify(worlds));
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.routingContext().response().end(Json.stringify(worlds));
}

static int randomWorld() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.tadx.web.TadxWebApplication;
import io.tadx.web.WebContext;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.sqlclient.Tuple;

import java.util.SplittableRandom;
Expand All @@ -31,11 +31,8 @@ public void run(WebContext webContext) {
//World world = dbStorage.findEntity(World.class, randomWorld());
DataMap row = dbStorage.queryRow("SELECT id, randomnumber FROM world WHERE id = ?", Tuple.of(randomWorld()));

webContext.routingContext().response()
.putHeader("Content-Type", "application/json;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString)
.end(row.toString());
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.routingContext().response().end(row.toString());
//.end(world.toJsonString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.tadx.web.WebContext;
import io.tadx.web.WebResult;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.*;
Expand Down Expand Up @@ -43,11 +43,8 @@ public void run(WebContext webContext) {
pool.preparedQuery(SELECT_WORLD).execute(Tuple.of(randomWorld())).onComplete(ar -> {
if (ar.succeeded()) {
RowSet<Row> rows = ar.result();
webContext.routingContext().response()
.putHeader("Content-Type", "application/json;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString)
.end(rows.iterator().next().toJson().toString());
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.routingContext().response().end(rows.iterator().next().toJson().toString());
} else {
webContext.exception(WebResult.errorResult(ar.cause().getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.tadx.web.WebContext;
import io.tadx.web.WebResult;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.sqlclient.*;

import java.util.SplittableRandom;
Expand Down Expand Up @@ -33,11 +33,8 @@ public void run(WebContext webContext) {
//client.preparedQuery(SELECT_WORLD)的性能高于SELECT_WORLD_QUERY.execute,但整体差异不大
client.preparedQuery(SELECT_WORLD).execute(Tuple.of(randomWorld())).onComplete(ar -> {
if (ar.succeeded()) {
webContext.routingContext().response()
.putHeader("Content-Type", "application/json;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString)
.end(ar.result().iterator().next().toJson().toString());
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.routingContext().response().end(ar.result().iterator().next().toJson().toString());
} else {
webContext.exception(WebResult.errorResult(ar.cause().getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.tadx.web.WebResult;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.template.FreemarkerEngine;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.Tuple;
import io.vertx.sqlclient.impl.SqlClientInternal;
Expand Down Expand Up @@ -47,10 +47,7 @@ public void run(WebContext webContext) {
fortunes.addFirst(new Fortune(0, "Additional fortune added at request time."));
Collections.sort(fortunes);

webContext.routingContext().response()
.putHeader("Content-Type", "application/json;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString);
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.complete(WebResult.pageResult(FreemarkerEngine.class).put("fortunes", fortunes).templateContent("""
<!DOCTYPE html>
<html lang="en-US">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.tadx.web.TadxWebApplication;
import io.tadx.web.WebContext;
import io.tadx.web.annotation.RouteMapping;
import io.tadx.web.route.RouteMapper;
import io.tadx.web.route_mapper.RouteMapper;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.Tuple;
import io.vertx.sqlclient.impl.SqlClientInternal;
Expand Down Expand Up @@ -51,10 +51,8 @@ public void run(WebContext webContext) {
}
sb.append("</table></body></html>");

webContext.routingContext().response()
.putHeader("Content-Type", "text/html;charset=UTF-8")
.putHeader("Server", "Tad.x")
.putHeader("Date", TadxWebApplication.currentDateString).end(sb.toString());
webContext.routingContext().response().headers().addAll(JsonRouteMapper.jsonHeaders);
webContext.routingContext().response().end(sb.toString());
}
});
}
Expand Down
Loading
Loading