Reputation: 1523
My django app is on heroku (running with gunicorn) with a simple shared DB and the images being saved to s3. The problem being once the page has more than a few images it becomes very slow to respond (30-60 seconds). Any tips on best practice in this situation?
settings:
#AWS login details etc
from S3 import CallingFormat
AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN
Basic model looks like this:
models.py
class TestModel(models.Model):
original_image = models.ImageField(storage=s3_storage, upload_to='uploads/%Y/%m/%d')
thumb_image = ImageSpec([resize.Fit(402)], image_field='original_image', storage=s3_storage, format='JPEG', options={'quality': 90})
formatted_image = ImageSpec([resize.Fit(800)], image_field='original_image', storage=s3_storage, format='JPEG', options={'quality': 90})
and simplified view:
views.py
def home(request):
images = TestModel.objects.filter(published=True)
ctxt = {}
ctxt['image'] = images
return render_to_response('home.html', ctxt, RequestContext(request))
Template:
{% for image in images %}
<img src="{{ image.thumb_image.url }}" alt="">
{% endfor %}
Upvotes: 2
Views: 973
Reputation: 1656
I guess this is because you resize your images right in the web dyno, isn't it?
It should be done in a worker dyno.
Upvotes: 1