Skip to content

Commit f88bcf8

Browse files
chore(benchmarks): Add in optional warmup to benchmarks (#2359)
* chore(benchmarks): Add in 15s warmup to benchmarks * make warmup configurable * fix comment that says 15s warmup * linter * Address PR comments * PR comments * refactor warmup into runW1R3 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent baa9e31 commit f88bcf8

File tree

2 files changed

+100
-35
lines changed

2 files changed

+100
-35
lines changed

Diff for: storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/StorageSharedBenchmarkingCli.java

+61-18
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
package com.google.cloud.storage.benchmarking;
1818

1919
import com.google.api.core.ApiFuture;
20-
import com.google.api.core.ApiFutures;
2120
import com.google.api.core.ListenableFutureToApiFuture;
2221
import com.google.api.gax.retrying.RetrySettings;
23-
import com.google.api.gax.rpc.ApiExceptions;
2422
import com.google.cloud.storage.Storage;
2523
import com.google.cloud.storage.StorageOptions;
2624
import com.google.common.util.concurrent.ListenableFuture;
@@ -29,9 +27,8 @@
2927
import java.io.PrintWriter;
3028
import java.nio.file.Path;
3129
import java.nio.file.Paths;
32-
import java.util.ArrayList;
33-
import java.util.List;
3430
import java.util.Random;
31+
import java.util.concurrent.ExecutionException;
3532
import java.util.concurrent.Executors;
3633
import java.util.regex.Pattern;
3734
import picocli.CommandLine;
@@ -83,13 +80,28 @@ public final class StorageSharedBenchmarkingCli implements Runnable {
8380
description = "Specify the path where the temporary directory should be located")
8481
String tempDirLocation;
8582

83+
@Option(
84+
names = "-warmup",
85+
description = "Number of seconds a W1R3 warmup will run on all available processors",
86+
defaultValue = "0")
87+
int warmup;
88+
89+
Path tempDir;
90+
91+
PrintWriter printWriter;
92+
8693
public static void main(String[] args) {
8794
CommandLine cmd = new CommandLine(StorageSharedBenchmarkingCli.class);
8895
System.exit(cmd.execute(args));
8996
}
9097

9198
@Override
9299
public void run() {
100+
tempDir =
101+
tempDirLocation != null
102+
? Paths.get(tempDirLocation)
103+
: Paths.get(System.getProperty("java.io.tmpdir"));
104+
printWriter = new PrintWriter(System.out, true);
93105
switch (testType) {
94106
case "w1r3":
95107
runWorkload1();
@@ -108,35 +120,66 @@ private void runWorkload1() {
108120
StorageOptions retryStorageOptions =
109121
StorageOptions.newBuilder().setProjectId(project).setRetrySettings(retrySettings).build();
110122
Storage storageClient = retryStorageOptions.getService();
111-
runW1R3(storageClient);
123+
try {
124+
runW1R3(storageClient);
125+
} catch (Exception e) {
126+
System.err.println("Failed to run workload 1: " + e.getMessage());
127+
}
112128
}
113129

114130
private void runWorkload4() {
115131
RetrySettings retrySettings = StorageOptions.getDefaultRetrySettings().toBuilder().build();
116132
StorageOptions retryStorageOptions =
117133
StorageOptions.grpc().setRetrySettings(retrySettings).setAttemptDirectPath(true).build();
118134
Storage storageClient = retryStorageOptions.getService();
119-
runW1R3(storageClient);
135+
try {
136+
runW1R3(storageClient);
137+
} catch (Exception e) {
138+
System.err.println("Failed to run workload 4: " + e.getMessage());
139+
}
120140
}
121141

122-
private void runW1R3(Storage storageClient) {
123-
Path tempDir =
124-
tempDirLocation != null
125-
? Paths.get(tempDirLocation)
126-
: Paths.get(System.getProperty("java.io.tmpdir"));
142+
private void runW1R3(Storage storageClient) throws ExecutionException, InterruptedException {
127143
ListeningExecutorService executorService =
128144
MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(workers));
129-
List<ApiFuture<String>> workloadRuns = new ArrayList<>();
130-
Range objectSizeRange = Range.of(objectSize);
131145
for (int i = 0; i < samples; i++) {
146+
runWarmup(storageClient);
147+
Range objectSizeRange = Range.of(objectSize);
148+
int objectSize = getRandomInt(objectSizeRange.min, objectSizeRange.max);
149+
convert(
150+
executorService.submit(
151+
new W1R3(
152+
storageClient,
153+
workers,
154+
api,
155+
printWriter,
156+
objectSize,
157+
tempDir,
158+
bucket,
159+
false)))
160+
.get();
161+
}
162+
}
163+
164+
private void runWarmup(Storage storageClient) throws ExecutionException, InterruptedException {
165+
if (warmup <= 0) {
166+
return;
167+
}
168+
int numberProcessors = Runtime.getRuntime().availableProcessors();
169+
ListeningExecutorService executorService =
170+
MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numberProcessors));
171+
long startTime = System.currentTimeMillis();
172+
long endTime = startTime + (warmup * 1000);
173+
// Run Warmup
174+
while (System.currentTimeMillis() < endTime) {
175+
Range objectSizeRange = Range.of(objectSize);
132176
int objectSize = getRandomInt(objectSizeRange.min, objectSizeRange.max);
133-
PrintWriter pw = new PrintWriter(System.out, true);
134-
workloadRuns.add(
135-
convert(
177+
convert(
136178
executorService.submit(
137-
new W1R3(storageClient, workers, api, pw, objectSize, tempDir, bucket))));
179+
new W1R3(
180+
storageClient, workers, api, printWriter, objectSize, tempDir, bucket, true)))
181+
.get();
138182
}
139-
ApiExceptions.callAndTranslateApiException(ApiFutures.allAsList(workloadRuns));
140183
}
141184

142185
public static int getRandomInt(int min, int max) {

Diff for: storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/W1R3.java

+39-17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ final class W1R3 implements Callable<String> {
3737
private final int objectSize;
3838
private final Path tempDirectory;
3939
private final String bucketName;
40+
private final boolean isWarmup;
4041

4142
W1R3(
4243
Storage storage,
@@ -45,18 +46,20 @@ final class W1R3 implements Callable<String> {
4546
PrintWriter printWriter,
4647
int objectSize,
4748
Path tempDirectory,
48-
String bucketName) {
49+
String bucketName,
50+
boolean isWarmup) {
4951
this.storage = storage;
5052
this.workers = workers;
5153
this.api = api;
5254
this.printWriter = printWriter;
5355
this.objectSize = objectSize;
5456
this.tempDirectory = tempDirectory;
5557
this.bucketName = bucketName;
58+
this.isWarmup = isWarmup;
5659
}
5760

5861
@Override
59-
public String call() throws Exception {
62+
public String call() {
6063
// Create the file to be uploaded and fill it with data
6164

6265
try (TmpFile file = DataGenerator.base64Characters().tempFile(tempDirectory, objectSize)) {
@@ -67,31 +70,50 @@ public String call() throws Exception {
6770
Blob created = storage.createFrom(blob, file.getPath());
6871
Instant endTime = clock.instant();
6972
Duration elapsedTimeUpload = Duration.between(startTime, endTime);
70-
printWriter.println(
71-
generateCloudMonitoringResult(
72-
"WRITE",
73-
StorageSharedBenchmarkingUtils.calculateThroughput(
74-
created.getSize().doubleValue(), elapsedTimeUpload),
75-
created)
76-
.formatAsCustomMetric());
73+
printResult("WRITE", created, elapsedTimeUpload);
7774
for (int i = 0; i <= StorageSharedBenchmarkingUtils.DEFAULT_NUMBER_OF_READS; i++) {
7875
try (TmpFile dest = TmpFile.of(tempDirectory, "prefix", "bin")) {
7976
startTime = clock.instant();
8077
storage.downloadTo(created.getBlobId(), dest.getPath());
8178
endTime = clock.instant();
8279
Duration elapsedTimeDownload = Duration.between(startTime, endTime);
83-
printWriter.println(
84-
generateCloudMonitoringResult(
85-
"READ[" + i + "]",
86-
StorageSharedBenchmarkingUtils.calculateThroughput(
87-
created.getSize().doubleValue(), elapsedTimeDownload),
88-
created)
89-
.formatAsCustomMetric());
80+
printResult("READ[" + i + "]", created, elapsedTimeDownload);
9081
}
9182
}
9283
StorageSharedBenchmarkingUtils.cleanupObject(storage, created);
84+
return "OK";
85+
} catch (Exception e) {
86+
CloudMonitoringResult result =
87+
CloudMonitoringResult.newBuilder()
88+
.setLibrary("java")
89+
.setApi(api)
90+
.setOp("W1R3")
91+
.setWorkers(workers)
92+
.setObjectSize(-1)
93+
.setChunksize(-1)
94+
.setCrc32cEnabled(false)
95+
.setMd5Enabled(false)
96+
.setCpuTimeUs(-1)
97+
.setBucketName("")
98+
.setStatus("FAIL")
99+
.setTransferSize("")
100+
.setThroughput(-1)
101+
.build();
102+
printWriter.println(result);
103+
return "FAIL";
104+
}
105+
}
106+
107+
private void printResult(String op, Blob created, Duration duration) {
108+
if (!isWarmup) {
109+
printWriter.println(
110+
generateCloudMonitoringResult(
111+
op,
112+
StorageSharedBenchmarkingUtils.calculateThroughput(
113+
created.getSize().doubleValue(), duration),
114+
created)
115+
.formatAsCustomMetric());
93116
}
94-
return "OK";
95117
}
96118

97119
private CloudMonitoringResult generateCloudMonitoringResult(

0 commit comments

Comments
 (0)