|
27 | 27 | import com.google.api.client.http.HttpResponseException; |
28 | 28 | import com.google.api.client.http.HttpStatusCodes; |
29 | 29 | import com.google.api.client.http.InputStreamContent; |
30 | | -import com.google.api.client.http.javanet.NetHttpTransport; |
| 30 | +import com.google.api.client.http.apache.v2.ApacheHttpTransport; |
31 | 31 | import com.google.api.client.json.gson.GsonFactory; |
32 | 32 | import com.google.api.services.storage.Storage; |
33 | 33 | import com.google.api.services.storage.model.ComposeRequest; |
|
53 | 53 | import java.nio.file.Path; |
54 | 54 | import java.security.GeneralSecurityException; |
55 | 55 | import java.time.Duration; |
| 56 | +import java.time.Instant; |
56 | 57 | import java.util.ArrayList; |
57 | 58 | import java.util.List; |
58 | 59 | import java.util.Optional; |
@@ -108,7 +109,14 @@ public ApiaryBasedGcsUtil(GcsParams storageParams) throws MobileHarnessException |
108 | 109 | private static Storage getClient(GcsParams storageParams) throws MobileHarnessException { |
109 | 110 | // Get credential |
110 | 111 | HttpRequestInitializer credential = getCredential(storageParams); |
111 | | - return new Storage.Builder(new NetHttpTransport(), GsonFactory.getDefaultInstance(), credential) |
| 112 | + return new Storage.Builder( |
| 113 | + new ApacheHttpTransport( |
| 114 | + ApacheHttpTransport.newDefaultHttpClientBuilder() |
| 115 | + // Set to 100 to support up to 50 upload and 50 download threads. |
| 116 | + .setMaxConnPerRoute(100) |
| 117 | + .build()), |
| 118 | + GsonFactory.getDefaultInstance(), |
| 119 | + credential) |
112 | 120 | .setHttpRequestInitializer( |
113 | 121 | request -> { |
114 | 122 | // Timeout should be large enough to fit bad network conditions. b/79751793, |
@@ -181,6 +189,8 @@ protected void copyFileToLocal(GcsApiObject gcsFile, Path localFile, long from, |
181 | 189 | "file gs://%s/%s [%s, %s) to %s", |
182 | 190 | storageParams.bucketName, gcsFile, from, from + size, localFile); |
183 | 191 |
|
| 192 | + Instant startTime = currentTime(); |
| 193 | + |
184 | 194 | retryIfMeetQuotaOrNetworkIssue( |
185 | 195 | () -> { |
186 | 196 | try (BufferedOutputStream bufferedOutputStream = getOutputStream(localFile)) { |
@@ -224,8 +234,13 @@ protected void copyFileToLocal(GcsApiObject gcsFile, Path localFile, long from, |
224 | 234 | "copy " + fileInfo); |
225 | 235 |
|
226 | 236 | logger.atInfo().log( |
227 | | - "Copied file gs://%s/%s [%s, %s) to %s", |
228 | | - storageParams.bucketName, gcsFile, from, from + size, localFile); |
| 237 | + "Copied file gs://%s/%s [%s, %s) to %s, took %d ms", |
| 238 | + storageParams.bucketName, |
| 239 | + gcsFile, |
| 240 | + from, |
| 241 | + from + size, |
| 242 | + localFile, |
| 243 | + Duration.between(startTime, currentTime()).toMillis()); |
229 | 244 | } |
230 | 245 |
|
231 | 246 | @Override |
|
0 commit comments