Niels Kristian
Niels Kristian

Reputation: 8845

Setup a high performing dynamic banner image generator on EC2

I currently have a rails app running on some dedicated servers, where I need to dynamically (per request) generate some banner images by fetching product images from s3 and generate some custom formatting on top of each image (combining with a logo, product price, some texts etc.). After the image has been generated, the image can be cached in a CDN.

There are many, many product images and the data/texts/prices that needs to go into each image often change, hence I don't want to rely on pre-generating all the image combinations and store them in S3. In the current setup I have, where I use imagemagick under the hood to generate the images, a request takes around 750ms where 2/3 are time spend in ruby/imagemagick and 1/3 is network.

I'm considering moving the job of generating the actual banner images onto Amazon (EC2 probably). This way I can make the network to s3 shorter and I can better scale up and down as requests come in. I can then fetch the data/texts needed to generate each image via an API from my current app. However I'm unsure if there are libraries fit for this exact task of the actual image generation, what will be high performing? And is there a better way than spawning some EC2 servers (e.g. lambda)?

Upvotes: 0

Views: 135

Answers (2)

jcupitt
jcupitt

Reputation: 11210

You could look at ruby-vips. It's typically 3x to 4x faster than imagemagick, and needs a lot less memory. If you open an issue on the ruby-vips github repo I could help set up a benchmark.

It's part of rails6, so it might to be simple to experiment with, depending on which rails you are using.

Upvotes: 1

nmarchini
nmarchini

Reputation: 141

You could deploy your app to ElasticBeanStalk and then let Amazon take care of the infra needed to scale when you see high load.

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html

Or as you pointed out you could go serverless with Lambda

Upvotes: 0

Related Questions