Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

django - Getting images URL from Amazon S3 is extremely slow on Heroku

I have a Django app deployed on Heroku, where users submit images via Amazon S3.

Though, when serving the image using {{ image.url }} in my Django template, the server seems to request a signed URL from S3 for every single image, and this takes a few seconds for each image, making the site painfully slow (17 seconds to load 9 small images).

I can see the request for each image in the logs:

Sending http request: <AWSPreparedRequest stream_output=True, method=GET, url=https://x.s3.ap-southeast-1.amazonaws.com/x.jpg, ...>

Is there a way of serving the images without waiting for a response from S3? How can I optimize this?

Here is my S3 config in settings.py:

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = "x"
AWS_S3_FILE_OVERWRITE = False

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...