Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] TPC-C Hibernate runner #2544

Draft
wants to merge 22 commits into
base: postgresql-dialect
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 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
7 changes: 7 additions & 0 deletions benchmarks/tpcc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
<artifactId>google-cloud-spanner-pgadapter</artifactId>
<version>0.39.0</version>
</dependency>

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-hibernate-dialect</artifactId>
<version>3.4.1</version>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
import com.google.cloud.pgadapter.tpcc.config.PGAdapterConfiguration;
import com.google.cloud.pgadapter.tpcc.config.SpannerConfiguration;
import com.google.cloud.pgadapter.tpcc.config.TpccConfiguration;
import com.google.cloud.spanner.AbortedException;
import com.google.cloud.spanner.Dialect;
import com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.JdbcAbortedException;
import com.google.common.base.Stopwatch;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
Expand All @@ -38,7 +41,7 @@ abstract class AbstractBenchmarkRunner implements Runnable {

private final Statistics statistics;

private final TpccConfiguration tpccConfiguration;
final TpccConfiguration tpccConfiguration;

// We have to define the following configuration in the abstract class.
// If we define them in inherited classes, they will be null in threads.
Expand Down Expand Up @@ -91,20 +94,31 @@ private void runTransactions() throws SQLException, InterruptedException {
while (!Thread.interrupted()) {
try {
int transaction = random.nextInt(23);
Stopwatch stopwatch = Stopwatch.createStarted();
if (transaction < 10) {
newOrder();
Duration executionDuration = stopwatch.elapsed();
metrics.recordNewOrderLatency(executionDuration.toMillis());
statistics.incNewOrder();
} else if (transaction < 20) {
payment();
Duration executionDuration = stopwatch.elapsed();
metrics.recordPaymentLatency(executionDuration.toMillis());
statistics.incPayment();
} else if (transaction < 21) {
orderStatus();
Duration executionDuration = stopwatch.elapsed();
metrics.recordOrderStatusLatency(executionDuration.toMillis());
statistics.incOrderStatus();
} else if (transaction < 22) {
delivery();
Duration executionDuration = stopwatch.elapsed();
metrics.recordDeliveryLatency(executionDuration.toMillis());
statistics.incDelivery();
} else if (transaction < 23) {
stockLevel();
Duration executionDuration = stopwatch.elapsed();
metrics.recordStockLevelLatency(executionDuration.toMillis());
statistics.incStockLevel();
} else {
LOG.info("No transaction");
Expand All @@ -122,6 +136,9 @@ private void runTransactions() throws SQLException, InterruptedException {
} else if (exception instanceof JdbcAbortedException) {
LOG.debug("Transaction aborted by Cloud Spanner via Spanner JDBC");
statistics.incAborted();
} else if (exception instanceof AbortedException) {
LOG.debug("Transaction aborted by Cloud Spanner via Spanner client");
statistics.incAborted();
} else {
LOG.warn("Transaction failed", exception);
statistics.incFailed();
Expand All @@ -135,7 +152,7 @@ private void runTransactions() throws SQLException, InterruptedException {
}
}

private long getOtherWarehouseId(long currentId) {
long getOtherWarehouseId(long currentId) {
if (tpccConfiguration.getWarehouses() == 1) {
return currentId;
}
Expand All @@ -147,7 +164,7 @@ private long getOtherWarehouseId(long currentId) {
}
}

private void newOrder() throws SQLException {
public void newOrder() throws SQLException {
LOG.debug("Executing new_order");

long warehouseId = Long.reverse(random.nextInt(tpccConfiguration.getWarehouses()));
Expand Down Expand Up @@ -288,7 +305,7 @@ private void newOrder() throws SQLException {
executeStatement("commit");
}

private void payment() throws SQLException {
public void payment() throws SQLException {
LOG.debug("Executing payment");

long warehouseId = Long.reverse(random.nextInt(tpccConfiguration.getWarehouses()));
Expand Down Expand Up @@ -455,7 +472,7 @@ private void payment() throws SQLException {
executeStatement("commit");
}

private void orderStatus() throws SQLException {
public void orderStatus() throws SQLException {
LOG.debug("Executing order_status");

long warehouseId = Long.reverse(random.nextInt(tpccConfiguration.getWarehouses()));
Expand Down Expand Up @@ -544,7 +561,7 @@ private void orderStatus() throws SQLException {
executeStatement("commit");
}

private void delivery() throws SQLException {
public void delivery() throws SQLException {
LOG.debug("Executing delivery");

long warehouseId = Long.reverse(random.nextInt(tpccConfiguration.getWarehouses()));
Expand Down Expand Up @@ -606,7 +623,7 @@ private void delivery() throws SQLException {
executeStatement("commit");
}

private void stockLevel() throws SQLException {
public void stockLevel() throws SQLException {
LOG.debug("Executing stock_level");

long warehouseId = Long.reverse(random.nextInt(tpccConfiguration.getWarehouses()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
Expand Down Expand Up @@ -96,6 +99,8 @@ public void run(String... args) throws Exception {
pgAdapterConfiguration.getMinSessions(), tpccConfiguration.getBenchmarkThreads()),
Math.max(
pgAdapterConfiguration.getMaxSessions(), tpccConfiguration.getBenchmarkThreads()));
StandardServiceRegistry registry = null;
SessionFactory sessionFactory = null;
try {
if (tpccConfiguration.isLoadData()) {
boolean isClientLibGSQLRunner =
Expand Down Expand Up @@ -134,6 +139,11 @@ public void run(String... args) throws Exception {
Statistics statistics = new Statistics(tpccConfiguration);
ExecutorService executor =
Executors.newFixedThreadPool(tpccConfiguration.getBenchmarkThreads());

if (tpccConfiguration.getBenchmarkRunner().equals(TpccConfiguration.HIBERNATE_RUNNER)) {
registry = new StandardServiceRegistryBuilder().configure().build();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
}
for (int i = 0; i < tpccConfiguration.getBenchmarkThreads(); i++) {
if (tpccConfiguration
.getBenchmarkRunner()
Expand Down Expand Up @@ -187,6 +197,19 @@ public void run(String... args) throws Exception {
spannerConfiguration,
metrics,
Dialect.GOOGLE_STANDARD_SQL));
} else if (tpccConfiguration
.getBenchmarkRunner()
.equals(TpccConfiguration.HIBERNATE_RUNNER)) {
statistics.setRunnerName("Hibernate benchmark");
executor.submit(
new HibernateBenchmarkRunner(
statistics,
sessionFactory,
tpccConfiguration,
pgAdapterConfiguration,
spannerConfiguration,
metrics,
Dialect.GOOGLE_STANDARD_SQL));
}
}

Expand All @@ -211,6 +234,10 @@ public void run(String... args) throws Exception {
server.stopServer();
server.awaitTerminated();
}
if (sessionFactory != null) {
sessionFactory.close();
registry.close();
}
}
}

Expand Down
Loading
Loading