Coldfusion/Railo: What's the most efficient way to output file contents - fileRead or include?

StackOverflow https://stackoverflow.com/questions/23281420

  •  09-07-2023
  •  | 
  •  

Question

While I've always cached database calls and placed commonly used data into memory for faster access, I've been finding of late that simple processing and output of data can add a significant amount of time to page load and thus I've been working on a template caching component that will save parsed HTML to either a file, or in memory, for quicker inclusion on pages.

This is all working very well, reducing some page loads down to 10% of the uncached equivalent - however I find myself wondering what would be the most efficient way to output the content.

Currently I'm using fileRead to pull in the parsed HTML and save to a variable, which is output on the page. This seems very fast, but I'm noticing the memory used by the Tomcat service gradually increasing - presumably because the fileRead operation is reading the contents into memory, and quite possibly, Tomcat isn't removing that data when its finished.

(Side question: Anyone know a way that I can interrogate the JVM memory and find details/stack traces of the objects that CF has created??)

Alternatively, I could use cfinclude to simply include the parsed HTML file. From all the information I can find it seems that the speed would be about the same - so would this method be more memory efficient? I've had issues on the server before with memory usage crashing Tomcat, so keeping it down is quite important.

Is there anyone doing something similar that can give me the benefit of their experience?

Was it helpful?

Solution 3

It turns out that CFInclude actually compiles the (already rendered in this case) content into a class, which itself has overhead. The classes aren't unloaded (according to CFTracker) and as such, too many of these can cause permgen errors. FileRead() seems to be orders of magnitude more efficient, as all we're doing is inserting content into the output buffer.

OTHER TIPS

cfinclude just includes the template into the one being compiled, whereas fileread has to read it into memory first and then output, so technically is going to consume more memory. I don;t expect the speed difference is much, but you can see the difference by just turning on debugging and checking the execution times.

The most efficient way would be to cached it with cachePut() and serve it from cacheGet(). What can be faster than fetching from RAM? Don't fetch it at all with proper Expire headers if it's the whole page, or smartly return 304 for Not Modified.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top