Skip to content

Commit b6495b4

Browse files
DeviceInfracopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 894384926
1 parent 953b7dd commit b6495b4

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/java/com/google/devtools/mobileharness/shared/util/file/remote/ApiaryBasedGcsUtil.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.google.api.client.http.HttpResponseException;
2828
import com.google.api.client.http.HttpStatusCodes;
2929
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;
3131
import com.google.api.client.json.gson.GsonFactory;
3232
import com.google.api.services.storage.Storage;
3333
import com.google.api.services.storage.model.ComposeRequest;
@@ -53,6 +53,7 @@
5353
import java.nio.file.Path;
5454
import java.security.GeneralSecurityException;
5555
import java.time.Duration;
56+
import java.time.Instant;
5657
import java.util.ArrayList;
5758
import java.util.List;
5859
import java.util.Optional;
@@ -108,7 +109,14 @@ public ApiaryBasedGcsUtil(GcsParams storageParams) throws MobileHarnessException
108109
private static Storage getClient(GcsParams storageParams) throws MobileHarnessException {
109110
// Get credential
110111
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)
112120
.setHttpRequestInitializer(
113121
request -> {
114122
// 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,
181189
"file gs://%s/%s [%s, %s) to %s",
182190
storageParams.bucketName, gcsFile, from, from + size, localFile);
183191

192+
Instant startTime = currentTime();
193+
184194
retryIfMeetQuotaOrNetworkIssue(
185195
() -> {
186196
try (BufferedOutputStream bufferedOutputStream = getOutputStream(localFile)) {
@@ -224,8 +234,13 @@ protected void copyFileToLocal(GcsApiObject gcsFile, Path localFile, long from,
224234
"copy " + fileInfo);
225235

226236
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());
229244
}
230245

231246
@Override

src/java/com/google/devtools/mobileharness/shared/util/file/remote/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ java_library(
5858
"@maven//:com_google_errorprone_error_prone_annotations",
5959
"@maven//:com_google_guava_guava",
6060
"@maven//:com_google_http_client_google_http_client",
61+
"@maven//:com_google_http_client_google_http_client_apache_v2",
6162
"@maven//:com_google_http_client_google_http_client_gson",
6263
"@protobuf//:protobuf_java",
6364
],

0 commit comments

Comments
 (0)