java Amazon S3 有连接池吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16354966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Amazon S3 have a connection pool?
提问by Mark_H
I ever used the code
我曾经使用过代码
public static AmazonS3Client s3 = null;
...
BasicAWSCredentials c = new BasicAWSCredentials("absadgwslkjlsdjgflwa");
s3 = new AmazonS3Client(c);
Only one instance s3 is created while dozens of threads will upload images by s3.putObject(). In the dump info, I could see that one thread would lock the only instance s3 while the others were waiting.
只创建一个实例 s3,而数十个线程将通过 s3.putObject() 上传图像。在转储信息中,我可以看到一个线程将锁定唯一的实例 s3,而其他线程正在等待。
So I think maybe it will be faster if I use the code below:
所以我想如果我使用下面的代码可能会更快:
BasicAWSCredentials c = new BasicAWSCredentials("absadgwslkjlsdjgflwa");
for(int i = 0; i < 10; i++)
amazonS3[i] = new AmazonS3Client(c);
Everytime the system will get a random s3 instance and then upload the image.
每次系统都会随机获取一个s3实例然后上传图片。
private static AmazonS3 getS3(){
int i = (int)(Math.random() * 10);
return amazonS3[i];
}
But it seems that the system slow down. Why that happened? Maybe the only instance s3 has already used connection pool? I am confused.
但似乎系统变慢了。为什么会这样?也许唯一的实例 s3 已经使用了连接池?我很迷惑。
回答by Jason Fulghum
Each client in the AWS SDK for Java (including the Amazon S3 client) currently maintains it's own HTTP connection pool. You can tune the maximum size of the HTTP connection pool through the ClientConfiguration classthat can be passed into client object constructors.
AWS SDK for Java 中的每个客户端(包括 Amazon S3 客户端)当前都维护着自己的 HTTP 连接池。您可以通过可以传递给客户端对象构造函数的 ClientConfiguration 类来调整 HTTP 连接池的最大大小。
We recommend sharing client objects, because of the expense and overhead of having too many HTTP connection pools that aren't being utilized effectively. You should see better performance when you share client objects across threads like this.
我们建议共享客户端对象,因为有太多未被有效利用的 HTTP 连接池会产生费用和开销。当您像这样跨线程共享客户端对象时,您应该会看到更好的性能。