-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Default Replication Worker Performance Test Harness (#20956)
Introduce a performance test harness for the default replication worker to make it easy for devs to test effect of changes on platform throughput. The current set up is designed to be run manually. In the future, we can look into integrating this report into our build pipelines. For now, this is good enough as I wanted to start somewhere. The general idea is to use JMH to run the test n number of times (currently 4 times). The dev can then look at logs to see throughput and how it varies. As of this PR, we see general platform throughput of ~ 20 - 25 MB/s.
- Loading branch information
Showing
8 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
airbyte-commons-worker/src/test/java/io/airbyte/workers/general/EmptyAirbyteDestination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.general; | ||
|
||
import io.airbyte.config.WorkerDestinationConfig; | ||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.workers.internal.AirbyteDestination; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Empty Airbyte Destination. Does nothing with messages. Intended for performance testing. | ||
*/ | ||
public class EmptyAirbyteDestination implements AirbyteDestination { | ||
|
||
@Override | ||
public void start(WorkerDestinationConfig destinationConfig, Path jobRoot) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void accept(AirbyteMessage message) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void notifyEndOfInput() throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getExitValue() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Optional<AirbyteMessage> attemptRead() { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception {} | ||
|
||
@Override | ||
public void cancel() throws Exception { | ||
|
||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
airbyte-commons-worker/src/test/java/io/airbyte/workers/general/LimitedAirbyteSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.general; | ||
|
||
import io.airbyte.config.WorkerSourceConfig; | ||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.workers.internal.AirbyteSource; | ||
import io.airbyte.workers.test_utils.AirbyteMessageUtils; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Basic Airbyte Source that emits {@link LimitedAirbyteSource#TOTAL_RECORDS} before finishing. | ||
* Intended for performance testing. | ||
*/ | ||
public class LimitedAirbyteSource implements AirbyteSource { | ||
|
||
private static final int TOTAL_RECORDS = 1_000_000; | ||
|
||
private int currentRecords = 0; | ||
|
||
@Override | ||
public void start(WorkerSourceConfig sourceConfig, Path jobRoot) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return currentRecords == TOTAL_RECORDS; | ||
} | ||
|
||
@Override | ||
public int getExitValue() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Optional<AirbyteMessage> attemptRead() { | ||
currentRecords++; | ||
return Optional.of(AirbyteMessageUtils.createRecordMessage("s1", "data", | ||
"This is a fairly long sentence to provide some bytes here. More bytes is better as it helps us measure performance." | ||
+ "Random append to prevent dead code generation: " + currentRecords)); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void cancel() throws Exception { | ||
|
||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
...ons-worker/src/test/java/io/airbyte/workers/general/ReplicationWorkerPerformanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.general; | ||
|
||
import io.airbyte.config.JobSyncConfig.NamespaceDefinitionType; | ||
import io.airbyte.config.ReplicationOutput; | ||
import io.airbyte.config.StandardSyncInput; | ||
import io.airbyte.metrics.lib.NotImplementedMetricClient; | ||
import io.airbyte.protocol.models.AirbyteStream; | ||
import io.airbyte.protocol.models.AirbyteStreamNameNamespacePair; | ||
import io.airbyte.protocol.models.CatalogHelpers; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteStream; | ||
import io.airbyte.protocol.models.JsonSchemaType; | ||
import io.airbyte.protocol.models.SyncMode; | ||
import io.airbyte.workers.RecordSchemaValidator; | ||
import io.airbyte.workers.WorkerMetricReporter; | ||
import io.airbyte.workers.exception.WorkerException; | ||
import io.airbyte.workers.internal.NamespacingMapper; | ||
import io.airbyte.workers.internal.book_keeping.AirbyteMessageTracker; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
@Slf4j | ||
public class ReplicationWorkerPerformanceTest { | ||
|
||
/** | ||
* Hook up the DefaultReplicationWorker to a test harness with an insanely quick Source | ||
* {@link LimitedAirbyteSource} and Destination {@link EmptyAirbyteDestination}. | ||
* <p> | ||
* Harness uses Java Micro Benchmark to run the E2E sync a configured number of times. It then | ||
* reports a time distribution for the time taken to run the E2E sync. | ||
* <p> | ||
* Because the reported time does not explicitly include throughput numbers, throughput logging has | ||
* been added. This class is intended to help devs understand the impact of changes on throughput. | ||
* <p> | ||
* To use this, simply run the main method, make yourself a cup of coffee for 5 mins, then look the | ||
* logs. | ||
*/ | ||
@Benchmark | ||
// SampleTime = the time taken to run the benchmarked method. Use this because we only care about | ||
// the time taken to sync the entire dataset. | ||
@BenchmarkMode(Mode.SampleTime) | ||
// Warming up the JVM stabilises results however takes longer. Skip this for now since we don't need | ||
// that fine a result. | ||
@Warmup(iterations = 0) | ||
// How many runs to do. | ||
@Fork(1) | ||
// Within each run, how many iterations to do. | ||
@Measurement(iterations = 2) | ||
public void executeOneSync() throws InterruptedException { | ||
final var perSource = new LimitedAirbyteSource(); | ||
final var perDestination = new EmptyAirbyteDestination(); | ||
final var messageTracker = new AirbyteMessageTracker(); | ||
final var metricReporter = new WorkerMetricReporter(new NotImplementedMetricClient(), "test-image:0.01"); | ||
final var dstNamespaceMapper = new NamespacingMapper(NamespaceDefinitionType.DESTINATION, "", ""); | ||
final var validator = new RecordSchemaValidator(Map.of( | ||
new AirbyteStreamNameNamespacePair("s1", null), | ||
CatalogHelpers.fieldsToJsonSchema(io.airbyte.protocol.models.Field.of("data", JsonSchemaType.STRING)))); | ||
|
||
final var worker = new DefaultReplicationWorker("1", 0, | ||
perSource, | ||
dstNamespaceMapper, | ||
perDestination, | ||
messageTracker, | ||
validator, | ||
metricReporter, | ||
false); | ||
final AtomicReference<ReplicationOutput> output = new AtomicReference<>(); | ||
final Thread workerThread = new Thread(() -> { | ||
try { | ||
output.set(worker.run(new StandardSyncInput().withCatalog(new ConfiguredAirbyteCatalog() | ||
.withStreams(List.of(new ConfiguredAirbyteStream().withSyncMode(SyncMode.FULL_REFRESH).withStream(new AirbyteStream().withName("s1"))))), | ||
Path.of("/"))); | ||
} catch (final WorkerException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
workerThread.start(); | ||
workerThread.join(); | ||
final var summary = output.get().getReplicationAttemptSummary(); | ||
final var mbRead = summary.getBytesSynced() / 1_000_000; | ||
final var timeTakenSec = (summary.getEndTime() - summary.getStartTime()) / 1000.0; | ||
log.info("MBs read: {}, Time taken sec: {}, MB/s: {}", mbRead, timeTakenSec, mbRead / timeTakenSec); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
// Run this main class to start benchmarking. | ||
org.openjdk.jmh.Main.main(args); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
airbyte-commons-worker/src/test/java/io/airbyte/workers/general/StubAirbyteMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.general; | ||
|
||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; | ||
import io.airbyte.workers.internal.AirbyteMapper; | ||
|
||
/** | ||
* Stub mapper testing what happens without any mapping. | ||
*/ | ||
public class StubAirbyteMapper implements AirbyteMapper { | ||
|
||
@Override | ||
public ConfiguredAirbyteCatalog mapCatalog(ConfiguredAirbyteCatalog catalog) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public AirbyteMessage mapMessage(AirbyteMessage message) { | ||
return message; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters