Amazon S3 PutObject is very slow

I place files in the S3 repository using the code below. I find it extremely slow. The stopwatch indicated 18 seconds +. Any suggestions or other impressions?

// upload the file to S3 AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretAccessKey); PutObjectRequest request = new PutObjectRequest(); FileStream fs = new FileStream(sourceFileName, FileMode.Open); request.WithInputStream(fs); request.WithBucketName(bucketName); request.WithKey(keyName); Stopwatch stp1 = new Stopwatch(); stp1.Start(); client.PutObject(request); stp1.Stop(); fs.Close(); 

This code is C #. I am using amazon.net sdk.

The file size is only 56 KB, and the download bandwidth is 1.87 Mbit / s.

+6
source share
2 answers

It sounds very similar to a problem I recently encountered that was caused by the automatic proxy detection settings in Internet Properties on Windows.

The Amazon SDK uses WebRequest to make it HTTP requests, and by default WebRequest adheres to the Internet option of computers to detect local proxies. Fortunately, WebRequest has the static property WebRequest.DefaultWebProxy , which when set to null removes automatic proxy detection.

All you have to do is set it to null before you start using AmazonS3 :

 WebRequest.DefaultWebProxy = null; // here AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretAccessKey); [...] 

It is worth noting that this static property needs to be set only once for the application domain, and not every time you want to create an AmazonS3 object.

Alternative approach:

If you do not mind reconfiguring the machine, go to:

 Windows Control Panel > Internet Options > Connections > Lan Settings 

and uncheck "Automatically detect settings." If you use this approach, you do not need to set the DefaultWebProxy property DefaultWebProxy all.

Additional Information:

When I ran into a problem, I asked the following question about SO:

How to disable automatic proxy detection in the `AmazonS3` object?

He has more details than my answer here if you are interested.

+8
source

You need to change BufferSize to AmazonS3Config

 var config = new AmazonS3Config { BufferSize = 65536 // 64KB Use a larger buffer size, normally 8K default. }; 
+3
source

Source: https://habr.com/ru/post/893457/


All Articles