Abs
Abs

Reputation: 57916

Speeding Up Writes to Amazon S3

I am trying to upload an image to Amazon S3 using C#:

PutObjectRequest titledRequest = null;

S3Response response = null;

using (var memoryStream = new MemoryStream())
{

    image.Save(memoryStream, ImageFormat.Png);

    titledRequest = new PutObjectRequest();

    titledRequest.WithBucketName(bucketName)
                 .WithKey(keyName)
                 .WithCannedACL(S3CannedACL.PublicRead)
                 .WithInputStream(memoryStream);

    response = client.PutObject(titledRequest);
}

As you can see, I am not saving the image file locally but rather streaming it to S3. However, for some reason, this process takes around 50 seconds for a 50kb file!

There is nothing wrong with my upload speed its well over 1mbps.

I'm wondering is it faster to save the file first and upload?

Is there anything I should consider to speed up upload process? Again, no problems on the broadband side of things!

Upvotes: 3

Views: 1435

Answers (1)

Steve Townsend
Steve Townsend

Reputation: 54128

Amazon docs say:

If uploading from an input stream, always specify metadata with the content size set. Otherwise the contents of the input stream have to be buffered in memory before being sent to Amazon S3. This can cause very negative performance impacts.

Hard to believe this could be your problem, but a best practice you should follow.

Other things to consider -

  • do you need to specify other ObjectMetadata to tell S3 how to handle your image?
  • does the bucket exist, or is creation a part of the first object send operation?

Upvotes: 5

Related Questions