Firing up the Shark, my new favorite tool, I found that the cycles were being spent about 60% in the JPEG decompression and 30% in the Mapserver average re-sampling. Decompressing the files did make things faster, but at a 10x file size penalty – unacceptable. Removing the average re-sampling did make things faster, but with very visible aesthetic penalty – unacceptable.
Using two tools from Intel, I have been able to cut about 40% off of the render time, without changing any code at all!
First, Intel publishes the “Integrated Performance Primitives”, basically a big catch-all library of multi-media and mathematics routines, built to take maximum advantage of the extended instruction sets in modern CPUs. Things like SSE, SSE2, SSE3, SSE4 and so on.Ordinarily, this would only be of use if I had a couple weeks to examine the code and fit the primitives into the existing code base. Fortunately for me, one of the example programs Intel ships with IPP is "ijg", a port of the Independent JPEG Group reference library that uses IPP acceleration wherever possible. So I could simply compile the "ijg" library and slip it into place instead of the standard "libjpeg".
Second, Intel also publishes their own C/C++ compiler, "icc", which uses a deep understanding of the x86 architecture and the extensions referenced above to produced optimized code. I used "icc" to compile both Mapserver and GDAL, and saw performance improve noticeably.
So, amazingly, between simply re-compiling the software with "icc" and using the "ijg" replacement library to speed up the JPEG decompression, I've managed to extract about 40% in performance, without touching the code of Mapserver, GDAL, or LibJPEG at all.

8 comments:
Interesting. I've been having similar issues with one client mapserver install. I've been dealing with a lot of MrSID files in conjunction with Mapserver. You have any thoughts on whether this would achieve same benefits for that.
Actually I have yet to do a benchmark between MrSID and internally-tiled TIFF usage in Mapserver. You wouldn't happen to know which is more efficient. I'm guessing the TIFF.
MrSID offers impressive storage savings at considerable performance penalty. It takes a good deal of CPU to extract using the fancy wavelet math. The fastest thing is uncompressed TIFF, if you can afford the disk space. I'm pretty impressed with the internally tiled JPEG compressed TIFF, which is giving about 10:1 compression, at about a 100% performance penalty however (and that's *after* the impressive optimization).
(For what it's worth, in a previous life I was part of the Intel compiler team and was in part responsible for some of the SSE stuff... I was later hired by LizardTech precisely to make MrSID run faster, but I've spent eight years here now doing almost everything *except* that...)
-mpg
Compared to MrSID, JPEG 2000 will give equivalent image quality and is often considerably faster too (both encode and decode).
YMMV, might depends on whose codec you're using and what switches and knobs you've got set.
-mpg
Impressive indeed. Would you have some benchmark of the overall gain of Intel compiler on standard MapServer operations (not specifically linked to jpeg stuff), like PostGIS layer rendering with AGG ?
Regards,
@guilaume, compiling just Mapserver with ICC and leaving everything else alone, yielded about 5% improvement. The biggest gain was definitely on the CPU-intensive image-decoding side. Possibly compiling AGG with ICC would yield improvements. I've also been wondering if using CUDA on the graphics libraries like AGG/GD would provide any substantial improvement.
Everything in performance work depends on workload. My example had no labeling. It had no vector graphics. It had no database access. Performance work is like playing whack-a-mole, each use case yields a new bottleneck point to work on.
Hi Paul. I am trying to compile MapServer with ICC for Linux, as you explained in your post. If i change the compiler in the Makefile generated by configure script, obviously, it does not work. Could you tell me how did you generate the Makefile including icc as compiler? I would be very grateful for your help. Thenk you very much
export CC=icc
export CXX=icpc
export CFLAGS=-O3 -axTP
export CXXFLAGS=-O3 -axTP
./configure --your-options-here
make
Post a Comment