[Django]-Serving many on-the-fly generated images with Django

1👍

All this works fine when the tiles are statically served. Now I added
the option to generate those tiles on the fly — different images are
merged, color corrected, …. This works, but is some heavy load for the
web server as one image takes about 0.1s to be generated.

You need a load balancer, with image requests being sent to a front-end server (e.g. NginX) that will multiplex (and cache!) as many requests as needed, provided you supply enough backend servers to do the heavy lifting.

This looks like a classic case for Amazon distributed computing: you could store the tiles in S3 storage (or maybe NFS over EBS). All the image manipulation servers get the data from a single image repository.

At the beginning, you can have both the Web application and one instance of the image manipulation server on the same machine. But basically your processes are three:

  • Web serving that calculates image URLs (you’ll need some way to encode the manipulation as parameters in the URLs, otherwise you’ll have to use cookies and session storage, which is ickier)
  • image server that receives the “image formula” and provides the JPEG tile
  • file server that allows access to the large images or single original tiles

I have worked at several such architectures, wherein our image layers were stored in a single image file (e.g. five zoom levels, each fifteen channels from FIR to UV, for a total of 75 “images” up to 100K pixels on a side, and the client could request ‘Zoom level 2, red channel plus double of difference between UV-1 channel and green, tiles from X=157, Y=195 to X=167,Y=205’).

👤LSerni

0👍

If one user is all you need to bring your webserver down then the problem is not apache or mod_wsgi.

First you should optimize your tiling routines and check if you really only deliver the data a user actually sees.

After that a faster cpu, more ram, a ssd and aggressive caching will give you more performance.

At last you may get some extra points for using another webserver, but dont expect too much from that.

0👍

I’m in a similar situation right now, and this is the approach I’m implementing right now. Have you considered pushing the image manipulation off to the client? I see that you use PIL to manipulate the images, but if the PIL commands are not too involved, could you recreate the functionality in Javascript? There are a lot of things that are possible using canvas and in my situation I was able to generate the needed images in Javascript on the canvas toDataURL to load it into the required locations.

👤Bob

Leave a comment