Reputation: 523
I am working on a news aggregator and use django-imagekit to create news article thumbnails.
The application is hosted on Heroku. Over time, I noticed the application consumes more and more memory. Currently, there are about 8000 images in the database and the application consumes about 3 times more memory in comparison to a staging application which has about 100 images in the database.
I believe the problem has to do with django-imagekit. If I call the original images in the templates, instead of images processed by django-imagekit, the memory drops down to a normal level.
The models:
class Article(models.Model):
title = models.CharField(max_length=255)
…
photo = models.ForeignKey(Photo, blank=True, null=True, related_name='+', on_delete=models.SET_NULL)
…
class Photo(models.Model):
name = models.TextField()
…
photo = models.ImageField(upload_to='user/photos/%Y/%m/%d', max_length=255)
…
thumb = ImageSpecField(source='photo',
processors=[resize.ResizeToFit(131, 131),],
options={'quality': 90})
thumbnail_image = ImageSpecField(source='photo',
processors=[resize.ResizeToFill(100, 100),],
options={'quality': 90})
news_small = ImageSpecField(source='photo',
processors=[resize.ResizeToFill(125, 94),],
format='JPEG',
options={'quality': 90})
…
Template example:
<a href="{{ item.get_absolute_url }}"><img src="{{ item.photo.news_small.url }}" alt=""></a>
Settings.py
redis_url = urlparse(os.environ.get('REDIS_URL'))
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': '%s:%s' % (redis_url.hostname, redis_url.port),
'OPTIONS': {
'DB': 0,
'PARSER_CLASS': 'redis.connection.HiredisParser',
'PASSWORD': redis_url.password
}
}
}
On the homepage, about 25 thumbnails are shown. But the memory jumps also on a page where only one image is shown.
Current versions: Django==1.8.17 django-imagekit==4.0.2
Is such high memory consumption expected with django-imagekit, or did I implement it wrong? I would appreciate any advice.
Upvotes: 2
Views: 342