ColdFusion Muse - Coldfusion Optimizationhttps://www.coldfusionmuse.com/index.cfm
Musings and Other Things from CF Guru Mark Krugeren-usMon, 19 Mar 2018 11:34:49 -0500Fri, 27 Apr 2012 17:49:00 -0500BlogCFChttp://blogs.law.harvard.edu/tech/rssmkruger@cfwebtools.commkruger@cfwebtools.commkruger@cfwebtools.comColdFusion Musehttps://www.coldfusionmuse.com/index.cfm
noA Whole Heaping Helping of Normalhttps://www.coldfusionmuse.com/index.cfm/2012/4/27/knowning-a-normal-jvm-heap
<p>
When I'm called into a data center or large application to look at a ColdFusion performance problem I often find myself in a "war room" with highly skilled technicians and admins who may or may not know much about the JVM runtime. One of the things that require experience is knowing what <em>normal memory patterns</em> look like for a typical production heap. Windows admins will often go directly to the task manager or resource monitor to examine memory usage. If they are uninitiated the first thing they say is "Wow... Jrun is using a lot of memory." This often doesn't sit right to them, particularly if the site is idle. So this post is to help those windows folks (and Linux as well) to an understanding of what <em>normal</em> heap activity looks like.
</p> [More]
Coldfusion OptimizationFri, 27 Apr 2012 17:49:00 -0500https://www.coldfusionmuse.com/index.cfm/2012/4/27/knowning-a-normal-jvm-heapDynamic Compression on ColdFusion 9 and IIS7https://www.coldfusionmuse.com/index.cfm/2010/9/24/coldfusion-IIS7-Compression-Issue
<p>
Maybe your already know that web servers can compress outgoing content. Compressed content arrives at the browser which decompresses it and is able to render it. This is all generally seamless to the user and results in a more effective use of bandwidth. Now, compressing static files (like .html files) is a no brainer for web servers. They simply pre-compress the files and store them in a file cache somewhere. When the original file is called for the web server serves up the compressed file instead.
</p>
<p>
Dynamic files are more problematic. There's no correlation between the file name and the buffered output of a ColdFusion page for example. Consider search results. One user might receive 10 results and another user might receive 10 completely different results. Still another user might receive 100 results. How is the <em>web server</em> supposed to compress that data? Like your app server it does it "on the fly". It waits for ColdFusion to return the response buffer, compresses the file <em>in memory</em> (as I understand it) and then outputs the buffer to the browser. At least that's the way it works in theory. In practice you might find that ColdFusion 9 and IIS 7 don't quite have this figured out yet.
</p>
<p>
Before I give you the blow-by-blow (and thankfully a solution) I want to make it clear that this problem and solution come to me by way of my good friend and colleague Vlad Friedman of <a href="http://www.edgewebhosting.net">Edgeweb Hosting</a>. EdgeWeb consistently receives the highest possible reviews from its customers and Vlad is one of the brightest folks I know in our corner of the IT world. Now let's talk about our little problem shall we?
</p> [More]
Coldfusion OptimizationHosting and NetworkingFri, 24 Sep 2010 16:32:00 -0500https://www.coldfusionmuse.com/index.cfm/2010/9/24/coldfusion-IIS7-Compression-IssueQuery Caching Run Amuck: Know Your FIFO Bufferhttps://www.coldfusionmuse.com/index.cfm/2010/9/20/caching.FIFO
<p>
Query caching is one of those underutilized features of ColdFusion that can exponentially speed up your application. It is also one of those misunderstood features that, when used <em>incorrectly</em> can be very disappointing. Let me say at the start that the Muse believes you <em>should use query caching</em>. If you don't believe I'm a fan then check out my post titled, <a href="http://www.coldfusionmuse.com/index.cfm/2005/10/13/safe.caching">Good Developers Practice Safe Query Caching</a>. It's not a panacea, but it definitely has it's uses. Almost every application has some queries that can be cached - and saving round trips to the database is the holy grail of application tuning. But in this post we want to talk about naughty developers who cache irresponsibly... developers who do not understand the nature of the FIFO buffer.
</p> [More]
Coldfusion OptimizationColdfusion &amp; DatabasesMon, 20 Sep 2010 11:08:00 -0500https://www.coldfusionmuse.com/index.cfm/2010/9/20/caching.FIFOWebmaniacs Live - Mike Brunt and CF Server Tuninghttps://www.coldfusionmuse.com/index.cfm/2008/5/20/optimization-mike-brunt
<p>
CF Optimization Guru Mike Brunt gave an awesome presentation on tuning ColdFusion. In a short 50 minutes he covered such topics as JVM configuration, multi-server install and load testing. It was an excellent overview. One recommendation (that he made in is lyric British access) was to install See Fusion or Fusion Reactor instead relying on the built in monitor. His take was that, because the monitor is running under ColdFusion, it is too easily become affect itself by performance - or perhaps could become part of the problem instead of being part of the solution.
</p>
<p>
I had thought, based on a presentation by Adam Lehman on CF 8 a year ago, that the monitor ran in a different JVM space than CF. One of the things I have noticed with the monitor always shows a Flex gateway thread in the request monitoring. That thread is the monitor itself. So I'm thinking Mike might be right. Perhaps the server monitor does exist "inside" of ColdFusion. I like the new server monitor and I've found it useful. But I <em>really</em> like SeeFusion's default view which shows requests and visuals of the heap on one page. I think it is a better aggregate of the things I want to know immediately when I'm looking at a performance problem.
</p>
<h4>Verbose Garbage Collection</h4>
<p>
Another excellent tip is a "how to" on enabling verbose garbage collection. This is easy to do. You simply add the following arguments to the JVM.config file and restart ColdFusion.
<code>
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintHeapAtGC -verbose:gc
-Xloggc:mylogname.log
</code>
<p>
The information is going to be stored in a log file in the default logs directory (like /runtime logs). How would you use this? One of the best ways to use it is to figure out when new generation collection is going on, when tenure (old "stop the world") collection is going on, and how much data is going from new to old. You can get a good picture of what is going on by examining this log information and using your imagination. Check out Mike's blog on <a href="http://www.alagad.com/go/blog-entry/the-heart-of-the-matter-the-jvm">GC tuning</a> for a good outline of the process.
<p>
Coldfusion OptimizationConferencesTue, 20 May 2008 10:49:00 -0500https://www.coldfusionmuse.com/index.cfm/2008/5/20/optimization-mike-bruntScheduled Task Performancehttps://www.coldfusionmuse.com/index.cfm/2008/3/19/scheduled.tasks
<p>
So you have a template that runs fine when you are loading it into a browser but runs like a water buffalo on Percodan when it's run as a Coldfusion scheduled task? Here's a tip I saw on <a href="http://www.houseoffusion.com">CF-Talk</a> that serves as a good reminder. Take a look at the debug settings. By default, debugging includes the address 127.0.0.1 (often called the "loopback" or "local" address). Coincidentally this is the very IP address that the Coldfusion Scheduler will report as the <em>calling</em> address (cgi.remote_addr) - meaning the template in question will generate all of that lovely debug information. This can result in an otherwise acceptable level of performance turning painfully slow. Muse rule of thumb - <em>disable debugging in production environments</em>. Ok... so sometimes I enable it briefly to get some information when I'm troubleshooting a specific process, but it should always be <em>off</em> during normal operations.
</p>
<p>
Let me add as an anti-thesis, <em>turn on</em> debugging in a development environment. It's surprising how many developers work without it. Personally, I spend more time looking at the debug info than the actual output. One of the first things you <em>should</em> do when writing a new query for example, is check it out in the debug. How many records returned? How long did it take? Can I make it better? One of Coldfusion's big advantages (in my view) is the copious amount of debug information provided for you with each request. Use it!
</p>
Coldfusion OptimizationColdfusion TroubleshootingWed, 19 Mar 2008 11:16:00 -0500https://www.coldfusionmuse.com/index.cfm/2008/3/19/scheduled.tasksColdfusion Optimization and the Windows Legacyhttps://www.coldfusionmuse.com/index.cfm/2008/3/9/default.configuration.woes
<p>
Coldfusion has been navigating the Internet waters in the good ship Java for some time now (6 or 7 years I think). If you are old enough in Internet years to remember Coldfusion 5 you probably know that Coldfusion was originally written for windows in C++ and ported over to Linux, Solaris and UNIX. These ports were not reputed to be particularly good and Coldfusion was largely considered to be a windows server application (and probably justifiably so). In 2002 with "CFMX" Coldfusion offered the Web world an application that was <em>not</em> just a windows application with a port to other platforms. Instead it was a <em>truly</em> cross-platform effort. Since that time Coldfusion has found it's way onto Linux in increasing numbers. In fact we are seeing more Coldfusion on Linux than ever before - particularly users who need Coldfusion Enterprise.
</p>
<p>
And why not? Coldfusion runs splendidly on Linux. We use CentOS at CF Webtools and it sings along happily with very few issues. In fact, it is possible to allocate about 50 percent more memory to the heap on a Linux machine (using the 32 bit JVM). That is a significant advantage that CF on Linux has over CF on windows. Here's a <a href="http://www.stillnetstudios.com/2008/03/08/3gb-of-memory-for-coldfusion-on-linux/">blog post</a> by CF Webtools own Linux guru Ryan Stille on that topic. Meanwhile, here's a take on the server optimization from the good old days to today:
</p> [More]
Coldfusion OptimizationSun, 09 Mar 2008 20:35:00 -0500https://www.coldfusionmuse.com/index.cfm/2008/3/9/default.configuration.woesMaking String Comparisons Faster Using Javacasthttps://www.coldfusionmuse.com/index.cfm/2007/11/30/javacast.comparto
<p>
In my <a href="http://www.coldfusionmuse.com/index.cfm/2007/11/26/javacast.iterations">Previous Post</a> on the subject of variable comparison I tried to use JavaCast() to influece the comparison operator being used. I was attempting to keep Coldfusion from having to ask "Is it a float" or "Is it a string" or "why doesn't Ray Camden ever win People's 'sexiest man alive'". I thought that if I could pre-cast variables into Java objects, Coldfusion could use that information to cut to the chase and <em>know</em> exactly which operator to use without testing. Alas, that proved to be false hope. If you read the post you will already know that the difference between comparing typless and typed data in Coldfusion is not worth the effort.
</p>
<p>
Well as usual, smarter people than I (than me?) read this blog. The amazing <a href="http://www.mkville.com/blog/">Mark Mazelin</a> (who's payment gateway API looks very interesting) suggested that I try to use the comparison operator directly, as in "object.compareTo()". I sometimes forget about all the nifty methods and properties attached to these objects when they are created. I set about testing his idea.
</p> [More]
Coldfusion OptimizationFri, 30 Nov 2007 16:28:00 -0500https://www.coldfusionmuse.com/index.cfm/2007/11/30/javacast.compartoMultiple Garbage Collectors: Can Two Sanitation Engineers be Better Than One?https://www.coldfusionmuse.com/index.cfm/2007/11/29/Coldfusion.Multiple.Garbage.Collection
<p>
I ran across this JVM configuration on a server recently. I should note that the server in question was having some issues, so this is <em>not an endorsement</em> of this approach. I simply had not seen this sort of configuration on a Coldfusion server before. Here are the JVM arguments:
</p>
<code>
java.args=-server -Xms512m -Xmx768m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:PermSize=64m -XX:NewSize=48m -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseConcMarkSweepGC ...
</code>
What seemed unusual to me is that this particular set of arguments allows for 2 garbage collectors to be specified. Both the "UseParNewGC" switch and the "UseConcMarkSweepGC" switch are set. I did not know that multiple GCs could be specified. I set about finding out how this was possible.
</p> [More]
Coldfusion OptimizationColdfusion TroubleshootingThu, 29 Nov 2007 13:48:00 -0500https://www.coldfusionmuse.com/index.cfm/2007/11/29/Coldfusion.Multiple.Garbage.CollectionIterations, Comparisons and JavaCast (Oh My)https://www.coldfusionmuse.com/index.cfm/2007/11/26/javacast.iterations
<p>
Testing Gurus like Dave Watts and Robi Sen will tell you that iterative tests are only interesting in a passing academic sort of way. Indeed if you are testing a real world application don't bother setting up a fancy-pants loop with 50,000 iterations to see if you should use "IS" or "EQ". If you are going to test then take the time to test real world operations in your application. But while we are on the subject of iterative tests I got to pondering what goes on under the hood. For example, what happens when you do "var1 IS var2" in a CFIF.
</p> [More]
Coldfusion OptimizationColdfusion 8Mon, 26 Nov 2007 15:13:00 -0500https://www.coldfusionmuse.com/index.cfm/2007/11/26/javacast.iterationsAsk-A-Muse: How Do I Use Client Variables?https://www.coldfusionmuse.com/index.cfm/2007/1/23/client.variables
<div style="margin-left: 20px; border-left: 3px solid #CCCCCC; padding-left: 4px;">
<p><em>Muse Reader Asks:</em><br>
We have a client variables database that is currently storing over 1.5 million records. In the Coldfusion Administrator, client variables are set to purge every 90 days. I was thinking of purging every 7 to 30 days to reduce the number of database entries and hopefully improve performance. What are my options?
</p>
</div>
<p style="padding-top: 15px;">
It's a good question. Performance depends on many thing including hardware, traffic, tuning, and capacity. Still, 1.5 million rows is a large table and as you might imagine it will perform less ably than a table with just a few hundred thousand rows. Let’s talk about these variables and how they are used.
</p> [More]
Coldfusion OptimizationColdfusion Tips and TechniquesTue, 23 Jan 2007 13:22:00 -0500https://www.coldfusionmuse.com/index.cfm/2007/1/23/client.variablesLooking for Bottlenecks? Watch Out for Cfdirectoryhttps://www.coldfusionmuse.com/index.cfm/2006/10/25/cfdirectory.bottleneck
<p>
I have a client with a file intensive application. It allows users to upload images and manage galleries. It's very slick and uses the flash uploader to accomplish multiple file uploads. He was having performance problems with the uploader. The flash uploader is a nifty way to upload a wheel-barrow full of files in a single operation. You can even check for things like file size and type <em>in advance</em> instead of waiting for the whole file to arrive on the server.
</p>
<p>
What we began to notice is that some requests took longer than others, <em>a lot longer</em>. I, being the expert troubleshooter that I am, naturally thought it was file sizes. I assumed that requests for a 2 meg file upload naturally took longer than requests that handled files of 200k. When we looked closer, however, it turns out that was <em>not</em> the case. A much more sinister culprit was lurking.
</p> [More]
Coldfusion OptimizationColdfusion TroubleshootingWed, 25 Oct 2006 19:36:00 -0500https://www.coldfusionmuse.com/index.cfm/2006/10/25/cfdirectory.bottleneckVariables Scope Memory Leak (say it ain't so)https://www.coldfusionmuse.com/index.cfm/2006/10/25/variables.memory.leak
<p>
I just read this fabulous post from Mike Schierberl's blog on <a href="http://www.schierberl.com/cfblog/index.cfm/2006/10/16/memoryLeak_variablesScope">Variables Scope Leaking</a> and I thought I would pass it on as a good read. To summarize, it is a common practice to create a component into the application scope and include an "init()" type function in it that returns an instance of itself. For example you might have an "employee" component who's "init()" function takes an employee id as an argument and returns an instance of "employee" populated with user data. That's pretty standard. If you return this new populated instance into the variables scope you would expect the variable to be discarded at the end of the request. Mike's post shows that this does not happen as expected. Because the variables returned are referenced (as apposed to "by value") they persist beyond the request termination.
</p>
<p>
As a fix you can add structClear(variables) to the end of your request - in the onRequestEnd() function for example. I can't explain it better than Mike. He includes a sample and a flash movie of how he came to his conclusions. It's very thorough.
</p>
<h4>New Information From Robi Sen</h4>
<p>
Robi Sen ran his own tests against the SUN JVM. He contests the assertion that this is a Coldfusion issue and he's focused on the JVM. His results may be found <a href="http://www.therobisen.com/blog/>here</a>.
</p>
<p><em>(NOTE: Robi's blog has changed)</em></p>
Coldfusion OptimizationColdfusion Tips and TechniquesWed, 25 Oct 2006 12:29:00 -0500https://www.coldfusionmuse.com/index.cfm/2006/10/25/variables.memory.leakSuperfluous Data Binding Can be Good for Youhttps://www.coldfusionmuse.com/index.cfm/2006/8/23/superfluous.data.binding
<p>
If you have read my previous posts on <a href="http://mkruger.cfwebtools.com/index.cfm?mode=entry&entry=C34E6F75-F938-F821-0813D1AAB006B26E">"Execution Plans"</a> and <a href="http://mkruger.cfwebtools.com/index.cfm?mode=alias&alias=no_cfqueryparam">Data Binding</a> you know I am a big believer in using Cfqueryparam for performance as well as security. Today I picked up a tip on this topic from <a href="http://www.harelmalka.com/?m=200608">harelmalka.com</a> (a blog I had never read before). I had never considered it before, but a query with no "WHERE" clause does not using binding because it lacks the opportunity. Therefore, a statement like:
<div class="code"><FONT COLOR=MAROON>&lt;CFQUERY ...&gt;</FONT><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SELECT * FROM Users&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<FONT COLOR=MAROON>&lt;/CFQUERY&gt;</FONT></div>
Would not include a prepare statement and not hit the execution plan. Hmmm.... The solution (originally detailed by <a href="http://www.barny.org.uk/">Barny</a>) is to add a superfluous binding merely for the purpose of kicking off the "prepare statement" method. Like so:
<div class="code"><FONT COLOR=MAROON>&lt;CFQUERY ...&gt;</FONT><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SELECT * FROM Users&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE 1 = <FONT COLOR=MAROON>&lt;cfqueryparam cfsqltype=<FONT COLOR=BLUE>"CF_SQL_INTEGER"</FONT> value=<FONT COLOR=BLUE>"1"</FONT>&gt;</FONT><br>
&nbsp;&nbsp;&nbsp;<FONT COLOR=MAROON>&lt;/CFQUERY&gt;</FONT></div>
That get's the job done nicely.
</p>
Coldfusion OptimizationColdfusion MX 7Wed, 23 Aug 2006 09:51:00 -0500https://www.coldfusionmuse.com/index.cfm/2006/8/23/superfluous.data.bindingInnovative Multi-Server Configuration Useshttps://www.coldfusionmuse.com/index.cfm/2006/7/5/multiserver.task.instances
<p>
Ben Forta posted <a href="http://www.houseoffusion.com/cf_lists/message.cfm/forumid:4/messageid:245407">this item</a> on CF-Talk while discussing the nuances of moving to a multi-server instance. I thought it was a great illustration of some of the uses of CF Multi-server.
</p>
<div style="margin-left: 20px; border-left: 3px solid #CCCCCC; padding-left: 4px;">
<p><em>Ben Forta wrote:</em><br>
It sounds like you are considering dedicated specialized instances, and I am a big fan of this. There is one customer I work with who has several sites in a single instance, like you do, but they have also created specific instances for specific needs. They have one that just does mailing, it receives requests from other instances, and process them. They have another which executes report requests on scheduled intervals. And another that builds Verity indexes when needed. These specialized instances require fewer threads, fewer data sources, no RDS and debugging (which you'd never want enabled on production servers anyway), and so on. That works very well. Of course, you may also want separate instances for specific apps, but that is a separate discussion.
</p>
</div>
<p>
I especially love the idea of a specialized instance for verity indexes. Re-indexing Verity collections is a huge resource hog, and larger collections can cause problems. I don't know why I never considered this approach before - very ingenious.
</p>
Coldfusion OptimizationColdfusion MX 7Wed, 05 Jul 2006 14:01:00 -0500https://www.coldfusionmuse.com/index.cfm/2006/7/5/multiserver.task.instancesYou CAN Use the File System With Cfdocument (Who Knew)https://www.coldfusionmuse.com/index.cfm/2006/5/30/cfdocument.file
<p> In regard to my previous post on <a href="http://mkruger.cfwebtools.com/index.cfm/2006/5/29/cfdocument.ssl">Cfdocument and SSL</a>
I stand corrected. It <em>is definitely possible</em> to use a "file:" protocol identifier in the image path when using Cfdocument. My problem was with the syntax. As is often the case, a helpful reader put me on the right path. Thanks to Julian Halliwell for pointing out that my problem was syntax. I was trying 2 slashes as in:
<div class="code"><FONT COLOR=NAVY><FONT COLOR=PURPLE>&lt;img src=<FONT COLOR=BLUE>"file://<A TARGET="_blank" HREF="d:\mysite">d:\mysite</A>\images\myimage.jpg"</FONT> width=<FONT COLOR=BLUE>"50"</FONT> height=<FONT COLOR=BLUE>"60"</FONT>&gt;</FONT></FONT></div>
Julian noted that it should actually be 3 leading slashes after the "file:" protocol identifier.
<div class="code"><FONT COLOR=NAVY><FONT COLOR=PURPLE>&lt;img src=<FONT COLOR=BLUE>"<A TARGET="_blank" HREF="file:///d:\mysite">file:///d:\mysite</A>\images\myimage.jpg"</FONT> width=<FONT COLOR=BLUE>"50"</FONT> height=<FONT COLOR=BLUE>"60"</FONT>&gt;</FONT></FONT></div>
</p>
<p> Not only is this a rock solid fix for the SSL issue (see the previous post) but it has the potential to dramatically impact the speed of your cfdocument call, especially if you using large images. We have an application that embeds fairly large photographic images. I'm guessing this will greatly increase the speed of rendering. I'll post a follow up and let you know.
</p>
Coldfusion OptimizationColdfusion Tips and TechniquesTue, 30 May 2006 10:21:00 -0500https://www.coldfusionmuse.com/index.cfm/2006/5/30/cfdocument.file