Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my Amazon S3 images loading slow?

It seems like the images read from amazon s3 load really slow. I had the images on the same server as the website and it loaded super fast. Is it loading slow cause it has to access it from s3 now?

Is there nothing i can really do about it ??

Using this to read the image files:

$secure_link = gs_prepareS3URL("myAmazon."/thumb/thumb_".$id, $bucket);
    readfile($secure_link);

Function is from : http://www.richardpeacock.com/blog/2010/07/amazon-aws-s3-query-string-authentication-php

like image 469
Jason Avatar asked May 18 '12 17:05

Jason


2 Answers

If you're embedding the images, you should serve them through Amazon CloudFront (Amazon's CDN Service). CloudFront loads the image/file from S3 (or a custom origin) then caches it on their edge servers.

CloudFront Tutorial - http://www.hongkiat.com/blog/amazon-cloudfront-how-to-setup-cloudfront-to-work-with-s3/

like image 82
John Himmelman Avatar answered Sep 24 '22 06:09

John Himmelman


S3 is just for Static Storage, by default it does not have the optimized performance, though there are ways to make it better.

Before you configure CloudFront, you should try enabling `Transfer Acceleration' on S3 bucket.

Source: https://docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration.html

Benefits are,

  1. Your customers upload to a centralized bucket from all over the world.
  2. You transfer gigabytes to terabytes of data on a regular basis across continents.
  3. You can't use all of your available bandwidth over the internet when uploading to Amazon S3.

This comes at a price.. (https://aws.amazon.com/about-aws/whats-new/2016/04/transfer-files-into-amazon-s3-up-to-300-percent-faster/)

Pricing for Amazon S3 Transfer Acceleration is simple, with no upfront costs or long-term commitments. You simply pay a low, per-GB rate for data transferred through the service. The pricing is designed to be risk free: if Amazon S3 Transfer Acceleration isn’t likely to make a difference in the speed of an upload (like when you upload data over the short distance from a client in Tokyo to an S3 bucket in Japan), you won’t be charged anything extra for that upload. For more information on pricing, see Amazon S3 pricing.

like image 26
SuperNova Avatar answered Sep 22 '22 06:09

SuperNova