【发布时间】:2018-11-29 12:36:30
【问题描述】:
我正在尝试从 7 台机器上传大量文件。 在每台机器上,我运行 6 个线程上传到 S3 。 当我从一台机器上运行上传时它运行良好,但是当我在 7 台机器上运行时它开始失败。
我在其他机器上遇到错误。
错误 - AmazonClientException com.amazonaws.SdkClientException:无法执行 HTTP 请求:等待来自池的连接超时
我上传到 S3 的小文件总数 = 1659328
每个线程中的记录数 = 276554
所以我必须关闭 TransferManager 吗?如果是,那么我应该如何关闭它?我的应用程序多线程。当我调用tm.shutdownNow(); 时,其他线程将无法使用它。
这是我要上传到 S3 的代码。
AWSCredentials credential = new ProfileCredentialsProvider("skjfffkjg-Prod-ServiceUser").getCredentials();
AmazonS3Client s3Client = (AmazonS3Client) AmazonS3ClientBuilder.standard().withRegion("us-east-1")
.withCredentials(new AWSStaticCredentialsProvider(credential)).withForceGlobalBucketAccessEnabled(true)
.build();
s3Client.getClientConfiguration().setMaxConnections(100);
上传到S3方法
public void uploadToToS3() {
_logger.info("Number of record to be processed in current thread: : " + records.size());
TransferManager tm = new TransferManager(s3Client);
MultipleFileUpload upload = tm.uploadFileList(bucketName, "", new File(fileLocation), records);
if (upload.isDone() == false) {
System.out.println("Transfer: " + upload.getDescription());
System.out.println(" - State: " + upload.getState());
System.out.println(" - Progress: " + upload.getProgress().getBytesTransferred());
}
try {
upload.waitForCompletion();
} catch (AmazonServiceException e1) {
_logger.error("AmazonServiceException " + e1.toString());
} catch (AmazonClientException e1) {
_logger.error("AmazonClientException " + e1.toString());
} catch (InterruptedException e1) {
_logger.error("InterruptedException " + e1.toString());
}
System.out.println("Is Upload completed Successfully ="+upload.isDone());
for (File file : records) {
try {
Files.delete(FileSystems.getDefault().getPath(file.getAbsolutePath()));
} catch (IOException e) {
_logger.error("IOException in file delete: " + e.toString());
System.exit(1);
_logger.error("IOException: " + e.toString());
}
}
_logger.info("Calling Transfer manager shutdown");
// tm.shutdownNow();
}
我必须关闭任何东西才能顺利上传吗?
【问题讨论】:
-
您是否验证了是否可以使用具有相同凭据的 CLI 上传?另外,请粘贴完整的堆栈跟踪。
-
@titogeo 是的凭据是正确的..我检查过..它在一台机器上工作..
-
@titogeo 只是一个问题..在我的情况下,我有关闭 Transfer Manger 吗..
-
你好。你找到解决办法了吗?
-
注意:我在从 AWS 检索单个文件时收到此消息。文件也不是很大。
标签: java amazon-web-services amazon-s3