Skip to content

Commit

Permalink
Add Microbenchmark for Insert rows
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-psaha committed Jun 25, 2024
1 parent 1357e74 commit c89aa5c
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@
<artifactId>objenesis</artifactId>
<version>${objenesis.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.34</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.34</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -537,6 +547,16 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package net.snowflake.ingest.streaming.internal;

import net.snowflake.ingest.streaming.InsertValidationResponse;
import net.snowflake.ingest.streaming.OpenChannelRequest;
import net.snowflake.ingest.streaming.SnowflakeStreamingIngestChannel;
import net.snowflake.ingest.streaming.SnowflakeStreamingIngestClient;
import net.snowflake.ingest.utils.Utils;
import org.junit.Assert;
import org.junit.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static java.time.ZoneOffset.UTC;

@State(Scope.Thread)
public class InsertRowsBenchmarkTest {

private SnowflakeStreamingIngestChannelInternal<?> channel;
private SnowflakeStreamingIngestClientInternal<?> client;

@Param({"1000000"})
private int numRows;

@Setup(Level.Trial)
public void setUpBeforeAll() {
client = new SnowflakeStreamingIngestClientInternal<ParquetChunkData>("client_PARQUET");
channel =
new SnowflakeStreamingIngestChannelInternal<>(
"channel",
"db",
"schema",
"table",
"0",
0L,
0L,
client,
"key",
1234L,
OpenChannelRequest.OnErrorOption.CONTINUE,
UTC);
// Setup column fields and vectors
ColumnMetadata col = new ColumnMetadata();
col.setOrdinal(1);
col.setName("COL");
col.setPhysicalType("SB16");
col.setNullable(false);
col.setLogicalType("FIXED");
col.setPrecision(38);
col.setScale(0);

channel.setupSchema(Collections.singletonList(col));
assert Utils.getProvider() != null;
}

@TearDown(Level.Trial)
public void tearDownAfterAll() throws Exception {
channel.close();
client.close();
}

@Benchmark
public void testInsertRow() {
Map<String, Object> row = new HashMap<>();
row.put("col", 1);

for (int i = 0; i < numRows; i++) {
InsertValidationResponse response = channel.insertRow(row, String.valueOf(i));
Assert.assertFalse(response.hasErrors());
}
}

@Test
public void insertRow () throws Exception {
setUpBeforeAll();
Map<String, Object> row = new HashMap<>();
row.put("col", 1);

for (int i = 0; i < 1000000; i++) {
InsertValidationResponse response = channel.insertRow(row, String.valueOf(i));
Assert.assertFalse(response.hasErrors());
}
tearDownAfterAll();
}

@Test
public void launchBenchmark() throws RunnerException {
Options opt = new OptionsBuilder()
// Specify which benchmarks to run.
// You can be more specific if you'd like to run only one benchmark per test.
.include(this.getClass().getName() + ".*")
// Set the following options as needed
.mode (Mode.AverageTime)
.timeUnit(TimeUnit.MICROSECONDS)
.warmupTime(TimeValue.seconds(1))
.warmupIterations(2)
.measurementTime(TimeValue.seconds(1))
.measurementIterations(5)
.threads(2)
.forks(1)
.shouldFailOnError(true)
.shouldDoGC(true)
//.jvmArgs("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining")
//.addProfiler(WinPerfAsmProfiler.class)
.build();

new Runner(opt).run();
}
}

0 comments on commit c89aa5c

Please sign in to comment.