阅读背景:

用imagekit保存到AWS S3上的Django速度很慢

来源:互联网 

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?

我的django应用程序在heroku(与gunicorn一起运行)上,它使用一个简单的共享DB并将图像保存到s3。问题是,一旦页面上有超过几张图片,它的响应速度就会非常慢(30-60秒)。在这种情况下,你有什么建议吗?

settings:

设置:

#AWS login details etc
from S3 import CallingFormat
AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN

Basic model looks like this:

基本模型如下:

models.py

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

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

1 个解决方案

#1


1  

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.

这应该在工人中进行。


分享到: