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
1 change: 1 addition & 0 deletions frameworks/Java/helidon/helidon-nima.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ COPY --from=maven /helidon/target/benchmark-nima.jar app.jar
EXPOSE 8080

CMD java -XX:+UseNUMA \
-server \
-XX:+UseParallelGC \
-jar app.jar
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@

package io.helidon.benchmark.nima.models;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import io.vertx.pgclient.PgConnection;
import io.vertx.sqlclient.PreparedQuery;
import io.vertx.sqlclient.PreparedStatement;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;

Expand All @@ -11,9 +15,9 @@ public class PgClientConnection implements AutoCloseable {
private static String SELECT_WORLD = "SELECT id, randomnumber from WORLD where id=$1";
private static String SELECT_FORTUNE = "SELECT * from FORTUNE";

private PreparedQuery<RowSet<Row>> worldQuery;
private PreparedQuery<RowSet<Row>> fortuneQuery;
private PreparedQuery<RowSet<Row>>[] updateQuery;
private CompletableFuture<PreparedStatement> worldQuery;
private CompletableFuture<PreparedStatement> fortuneQuery;
private CompletableFuture<PreparedStatement>[] updateQuery;

private final PgConnection conn;

Expand All @@ -30,30 +34,28 @@ public void close() {
conn.close();
}

public PreparedQuery<RowSet<Row>> worldQuery() {
return worldQuery;
public PreparedQuery<RowSet<Row>> worldQuery() throws ExecutionException, InterruptedException {
return worldQuery.get().query();
}

public PreparedQuery<RowSet<Row>> fortuneQuery() {
return fortuneQuery;
public PreparedQuery<RowSet<Row>> fortuneQuery() throws ExecutionException, InterruptedException {
return fortuneQuery.get().query();
}

public PreparedQuery<RowSet<Row>> updateQuery(int queryCount) {
return updateQuery[queryCount - 1];
public PreparedQuery<RowSet<Row>> updateQuery(int queryCount) throws ExecutionException, InterruptedException {
return updateQuery[queryCount - 1].get().query();
}

@SuppressWarnings("unchecked")
void prepare() {
try {
worldQuery = conn.prepare(SELECT_WORLD)
.toCompletionStage().toCompletableFuture().get().query();
fortuneQuery = conn.prepare(SELECT_FORTUNE)
.toCompletionStage().toCompletableFuture().get().query();
updateQuery = (PreparedQuery<RowSet<Row>>[]) new PreparedQuery<?>[UPDATE_QUERIES];
worldQuery = conn.prepare(SELECT_WORLD).toCompletionStage().toCompletableFuture();
fortuneQuery = conn.prepare(SELECT_FORTUNE).toCompletionStage().toCompletableFuture();
updateQuery = (CompletableFuture<PreparedStatement>[]) new CompletableFuture<?>[UPDATE_QUERIES];
for (int i = 0; i < UPDATE_QUERIES; i++) {
updateQuery[i] = conn.prepare(singleUpdate(i + 1))
.toCompletionStage().toCompletableFuture().get().query();
}
.toCompletionStage().toCompletableFuture();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

package io.helidon.benchmark.nima.models;

import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;

import io.helidon.config.Config;
Expand All @@ -13,7 +14,7 @@ class PgClientConnectionPoolArray extends PgClientConnectionPool {

private final int connections;
private final PgClientConnection[] connectionArray;
private final ReentrantLock lock = new ReentrantLock();
private final ReadWriteLock lock = new ReentrantReadWriteLock();

PgClientConnectionPoolArray(Vertx vertx, PgConnectOptions options, Config config) {
super(vertx, options, config);
Expand All @@ -29,20 +30,23 @@ class PgClientConnectionPoolArray extends PgClientConnectionPool {
@Override
public PgClientConnection clientConnection() {
int index = Thread.currentThread().hashCode() % connections;
PgClientConnection connection = connectionArray[index];
if (connection == null) {
try {
lock.lock();
connection = connectionArray[index];
if (connection == null) {
connection = newConnection();
connectionArray[index] = connection;
if (connectionArray[index] == null) {
lock.readLock().lock();
if (connectionArray[index] == null) {
lock.readLock().unlock();
lock.writeLock().lock();
try {
if (connectionArray[index] == null) {
connectionArray[index] = newConnection();
}
} finally {
lock.writeLock().unlock();
}
} finally {
lock.unlock();
} else {
lock.readLock().unlock();
}
}
return connection;
return connectionArray[index];
}

@Override
Expand Down
Loading