guardian/frontend — pull request #7464 by johnduffell (2014-12-05 17:32:53+00:00)
Title: speed up png resizer

The PNG resizer was only handling 2 requests per second to the healthcheck URL on our big AWS boxes, before maxing their CPUs.

I have done a bit of investigation and it seems it was spending time putting the PNG on the disk for imagemagic to read back in, plus it was doing some conversion to BufferedImages which was also slow. So I have taken these out and I will see how this helps the performance.

The healthcheck is quick partly because it scales the images to a tiny size, so pngquant doesn't have much data to deal with. When using a more realistic size, PngQuant uses the lion's share of the CPU time.

Other avenues to explore might be:
to use the JNI imagemagic library rather than calling out to a process.
chain imagemagic together with pngquant using the shell instead of scala.
use streams instead of reading into a byte array might improve the latency but probably not the throughput.
use some other png resizing library or tool
don't resize them ourselves after all