Search code examples
djangoherokuamazon-s3amazon-web-servicesdjango-imagekit

Django on heroku with imagekit saving to AWS S3 is very slow


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 %}

Solution

  • 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.