Skip to content

Commit

Permalink
feat: add gc stats
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Jan 1, 2024
1 parent 684ab08 commit 1a77e0e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface BenchmarkMethod {
this.name = name;
this.statistics = statistics;
this.benchmarkConfiguration = benchmarkConfiguration;
this.benchmarks.put("SelectOneValueAutoCommit", this::benchmarkSelectOneValueAutoCommit);
this.benchmarks.put("SelectOneRowAutoCommit", this::benchmarkSelectOneRowAutoCommit);
this.benchmarks.put("Select100RowsAutoCommit", this::benchmarkSelect100RowsRowAutoCommit);
this.benchmarks.put("SelectOneRowTransaction", this::benchmarkSelectOneRowTransaction);
Expand Down Expand Up @@ -86,6 +87,14 @@ public void run() {

abstract String getParameterName(int index);

void benchmarkSelectOneValueAutoCommit(String name, int parallelism) throws Exception {
benchmarkSelect(
name,
parallelism,
"select col_varchar from benchmark_all_types where id=" + getParameterName(1),
true);
}

void benchmarkSelectOneRowAutoCommit(String name, int parallelism) throws Exception {
benchmarkSelect(
name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.google.cloud.pgadapter.benchmark;

import com.google.cloud.pgadapter.benchmark.config.BenchmarkConfiguration;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -36,7 +38,9 @@ void print(Duration totalRuntime) {
\rNum iterations: %d\t
\rTotal runtime: %s\t
\rParallelism: %d\t
\r
\rNum GCs: %d\t
\rGC time: %s\t
\rRuntime: %s\t
\rOperations: %d/%d (%.2f/s)\t
""",
Expand All @@ -45,6 +49,8 @@ void print(Duration totalRuntime) {
tpccConfiguration.getIterations(),
totalRuntime,
getParallelism(),
getGarbageCollections(),
getGarbageCollectionTime(),
runtime,
getOperations(),
getTotalOperations(),
Expand Down Expand Up @@ -107,4 +113,19 @@ long getOperations() {
void incOperations() {
operations.incrementAndGet();
}

long getGarbageCollections() {
return ManagementFactory.getGarbageCollectorMXBeans().stream()
.map(GarbageCollectorMXBean::getCollectionCount)
.reduce(Long::sum)
.orElse(0L);
}

Duration getGarbageCollectionTime() {
return ManagementFactory.getGarbageCollectorMXBeans().stream()
.map(GarbageCollectorMXBean::getCollectionTime)
.reduce(Long::sum)
.map(Duration::ofMillis)
.orElse(Duration.ZERO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ benchmark.max-random-wait=PT0S
# The number of parallel clients to use for benchmarks.
benchmark.parallelism=4
# The benchmarks to run
benchmark.benchmarks=SelectOneRowAutoCommit,Select100RowsAutoCommit,SelectOneRowTransaction,Select100RowsTransaction
benchmark.benchmarks=SelectOneValueAutoCommit,SelectOneRowAutoCommit,Select100RowsAutoCommit,SelectOneRowTransaction,Select100RowsTransaction

# --- Possible optimizations for TPC-C --- #
benchmark.use-read-only-transactions=false
Expand Down

0 comments on commit 1a77e0e

Please sign in to comment.