17
17
package com .google .cloud .storage .benchmarking ;
18
18
19
19
import com .google .api .core .ApiFuture ;
20
- import com .google .api .core .ApiFutures ;
21
20
import com .google .api .core .ListenableFutureToApiFuture ;
22
21
import com .google .api .gax .retrying .RetrySettings ;
23
- import com .google .api .gax .rpc .ApiExceptions ;
24
22
import com .google .cloud .storage .Storage ;
25
23
import com .google .cloud .storage .StorageOptions ;
26
24
import com .google .common .util .concurrent .ListenableFuture ;
29
27
import java .io .PrintWriter ;
30
28
import java .nio .file .Path ;
31
29
import java .nio .file .Paths ;
32
- import java .util .ArrayList ;
33
- import java .util .List ;
34
30
import java .util .Random ;
31
+ import java .util .concurrent .ExecutionException ;
35
32
import java .util .concurrent .Executors ;
36
33
import java .util .regex .Pattern ;
37
34
import picocli .CommandLine ;
@@ -83,13 +80,28 @@ public final class StorageSharedBenchmarkingCli implements Runnable {
83
80
description = "Specify the path where the temporary directory should be located" )
84
81
String tempDirLocation ;
85
82
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
+
86
93
public static void main (String [] args ) {
87
94
CommandLine cmd = new CommandLine (StorageSharedBenchmarkingCli .class );
88
95
System .exit (cmd .execute (args ));
89
96
}
90
97
91
98
@ Override
92
99
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 );
93
105
switch (testType ) {
94
106
case "w1r3" :
95
107
runWorkload1 ();
@@ -108,35 +120,66 @@ private void runWorkload1() {
108
120
StorageOptions retryStorageOptions =
109
121
StorageOptions .newBuilder ().setProjectId (project ).setRetrySettings (retrySettings ).build ();
110
122
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
+ }
112
128
}
113
129
114
130
private void runWorkload4 () {
115
131
RetrySettings retrySettings = StorageOptions .getDefaultRetrySettings ().toBuilder ().build ();
116
132
StorageOptions retryStorageOptions =
117
133
StorageOptions .grpc ().setRetrySettings (retrySettings ).setAttemptDirectPath (true ).build ();
118
134
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
+ }
120
140
}
121
141
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 {
127
143
ListeningExecutorService executorService =
128
144
MoreExecutors .listeningDecorator (Executors .newFixedThreadPool (workers ));
129
- List <ApiFuture <String >> workloadRuns = new ArrayList <>();
130
- Range objectSizeRange = Range .of (objectSize );
131
145
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 );
132
176
int objectSize = getRandomInt (objectSizeRange .min , objectSizeRange .max );
133
- PrintWriter pw = new PrintWriter (System .out , true );
134
- workloadRuns .add (
135
- convert (
177
+ convert (
136
178
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 ();
138
182
}
139
- ApiExceptions .callAndTranslateApiException (ApiFutures .allAsList (workloadRuns ));
140
183
}
141
184
142
185
public static int getRandomInt (int min , int max ) {
0 commit comments