Are you having slow ColdFusion pages and wondering what may be the cause? There can of course be many root causes, but a common one that I'm finding lately as I help people is due to using CF's image resizing features, such as to create thumbnails after a file is uploaded (or when many files are uploaded).
Such folks may be using the
CFIMAGE action="resize" tag, or the
imageResize() or
ImageScaleToFit() functions to do resizing. The problem (if this is the cause of a slow page) is due to a default setting for all these which may not be the best choice in all cases. The good news is that there's a quick fix, through there are some other things to consider. (If you're currently using CFIMAGE to do resizing, jump to the last section of this entry to see an example of code switching from the "slow" approach to the faster one. But really, you ought to read the rest of this entry to understand what's being proposed.)
While I offer all the info here for your consideration, if you need help implementing the solution, or better understanding how to find and resolve these or other problems affecting your CF server performance, see more on my
CF server troubleshooting consulting services.
Problem: Default "Interpolation" value is "highestquality"
The culprit in this particular problem is a default value in each of these for an "interpolation" level, which presupposes that you want
"highestquality" (that's literally an available value for this setting). That quality seems to come at a significant performance penalty for many (which may vary depending on the type or size of file being processed, and again is multiplied the more files you're processing in a single request.)
Solution: There are alternative values for "interpolation"
So the first "good news" is that there is a range of options one can set for this interpolation value, and the opposite one is
"highestperformance". For many people, changing to that value has no negative impact on quality (again, that may depend on the image, its size, what you're using the result for, etc.) but it offers a GREAT improvement in performance. You need to test for yourself.
Implementation 1: Controlling Interpolation in the CFIMAGE tag
So if you use
CFIMAGE action="resize", what can you do? Well, the "bad news" is that for CF8 and CF9, the CFIMAGE tag has no means for you to affect the interpolation value. It has no
INTERPOLATION attribute.
Some great news is that CF10 adds this attribute (for use specifically with
action="resize"), but note that the default is still
"highestquality", so you will want to consider changing it. See the
docs for CF10 on CFIMAGE for the range of
INTERPOLATION attribute values.
If you're on CF 8 or 9, though, you will need to consider changing your code to use the
imageResize() function instead, which is discussed in the next section.
(Note that, for now, only the action="rewrite" option for CFIMAGE makes any use of interpolation at all.)
Implementation 2: Controlling Interpolation in the imageResize() and imageScaleToFit()functions
In all three releases (CF 8, 9, and 10), the
imageResize() function--and the perhaps less-well-known
imageScaleToFit() function--both have an available (optional) argument for controlling the interpolation value. It's the 4th arg in both imageResize() and imageScaleToFit(). But in all three releases, the value for each again defaults to
"highestquality".
Specifying it as "highestperformance" (or some value between the two) again may have a noticeable effect on improving performance without much loss of image quality. See the docs on these functions (here's a link to the
CF9 CFML reference.) Test things for yourself, and report here if it helps.
(As an interesting aside, the docs suggest that while
imageRotate(),
imageShear(), and
imageTranslate() functions also have an optional interploation argument, theirs each defaults to the fastest of the values they offer. One wonders why Adobe chose for resizing and scaling to opt for the opposite values.)
Changing from CFIMAGE will require reading and writing the file a new way
Finally, if you do have to change from using CFIMAGE to the imageResize() function (not required for CF10), you may also need to deal with how to load the image from disk into memory, and write it out, if you're also doing that in the one tag.
CFIMAGE has both a SOURCE and DESTINATION attribute which can point to a file on disk to be read/written. The imageResize() function's does not support that. Instead, its first ("name") argument instead expects to be passed a variable with an image in it, such as is created by other CFML image-processing tags or functions. imageNew() can read an image from disk into memory.
Similarly, the result of calling imageResize() is a manipulation of that image object in memory. The function has no means to write out the result. That can be done with either imageWrite() or another CFIMAGE action="write".
So to change from using the tag-based resize to function-based, you may need to add a line of code to load the image from disk, such as using imageNew(), and one to write the resulting image to disk, such as using imageWrite().
Consider the following tag-based resize code, which reads, resizes, and writes out an image (available in the CFDOCS directory, if you installed that with ColdFusion):
That could be re-written as either:
or (for those who prefer script to tags):
myImage=ImageNew("../cfdocs/images/artgallery/jeff01.jpg");
ImageResize(myImage,100,100,"highestperformance");
imageWrite(myimage,"jeff02_thumbnail.jpg");
Again, test things for yourself to determine whether changing to highestperformance results in an image quality you (and your users) can find acceptable. See the docs for a range of alternative options to consider. And if you move up to CF10, note that you can solve the problem with CFIMAGE action="rewrite" by just adding the new INTERPOLATION attribute right onto the tag.
For more on the many (many) new features of CF10, check out
my blog entry on the topic.
And again if you need help solving these or such other problems affecting your CF server performance, let me know how I can help, via my
CF server troubleshooting consulting services.
Of course I welcome and encourage followup and feedback here on this particular problem. And for solutions to other such knotty CF troubleshooting challenges, see my
cf911.com site of CF server troubleshooting resources.
Setting up ColdFusion 10 on an Ubuntu Server, and as per usual, the installation option to start up ColdFusion when the server starts does work on Linux.So I wondered how hard it would be to set this up using Upstart, and it was surprisingly easy with a few bit of trial and error.This is what I would eventually came up with:Unfortunately, I would like this to respawn if it somehow does, and it doe...