Skip to content
Draft
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
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.51.0</version>
</dependency>

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-hibernate-dialect</artifactId>
<version>3.7.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 @@ -283,7 +300,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 @@ -449,7 +466,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 @@ -538,7 +555,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 @@ -597,7 +614,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 @@ -15,6 +15,7 @@

import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter;
import com.google.cloud.opentelemetry.metric.MetricConfiguration;
import com.google.cloud.pgadapter.tpcc.config.HibernateConfiguration;
import com.google.cloud.pgadapter.tpcc.config.PGAdapterConfiguration;
import com.google.cloud.pgadapter.tpcc.config.SpannerConfiguration;
import com.google.cloud.pgadapter.tpcc.config.TpccConfiguration;
Expand All @@ -41,6 +42,10 @@
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 All @@ -65,13 +70,17 @@ public static void main(String[] args) {

private final TpccConfiguration tpccConfiguration;

private final HibernateConfiguration hibernateConfiguration;

public BenchmarkApplication(
SpannerConfiguration spannerConfiguration,
PGAdapterConfiguration pgAdapterConfiguration,
TpccConfiguration tpccConfiguration) {
TpccConfiguration tpccConfiguration,
HibernateConfiguration hibernateConfiguration) {
this.spannerConfiguration = spannerConfiguration;
this.pgAdapterConfiguration = pgAdapterConfiguration;
this.tpccConfiguration = tpccConfiguration;
this.hibernateConfiguration = hibernateConfiguration;
}

@Override
Expand All @@ -95,6 +104,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 @@ -133,6 +144,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 = buildHibernateConfiguration();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
}
for (int i = 0; i < tpccConfiguration.getBenchmarkThreads(); i++) {
if (tpccConfiguration
.getBenchmarkRunner()
Expand Down Expand Up @@ -186,6 +202,20 @@ 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,
new SessionHelper(sessionFactory),
tpccConfiguration,
pgAdapterConfiguration,
spannerConfiguration,
hibernateConfiguration,
metrics,
Dialect.GOOGLE_STANDARD_SQL));
}
}

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

Expand Down Expand Up @@ -282,4 +316,17 @@ private ProxyServer startPGAdapter() {

return server;
}

private StandardServiceRegistry buildHibernateConfiguration() {
return new StandardServiceRegistryBuilder()
.configure()
.applySetting("hibernate.show_sql", hibernateConfiguration.isShowSql())
.applySetting("hibernate.jdbc.batch_size", hibernateConfiguration.getBatchSize())
.applySetting("hibernate.connection.pool_size", hibernateConfiguration.getPoolSize())
.applySetting("hibernate.order_inserts", hibernateConfiguration.isOrderInserts())
.applySetting("hibernate.order_updates", hibernateConfiguration.isOrderUpdates())
.applySetting(
"hibernate.jdbc.batch_versioned_data", hibernateConfiguration.isBatchVersionedData())
.build();
}
}
Loading
Loading