pf » ColdFusion Memory Usage Stats
ColdFusion Memory Usage Stats

Here are some code to find out some info about the memory usage of CFMX or BlueDragon. The Java API provides three methods in the java.lang.Runtime class: freeMemory, totalMemory, and maxMemory. These methods provide information about the JVM's memory usage, and its easy to access them with CFML:
<cfset runtime = CreateObject("java","java.lang.Runtime").getRuntime()>
<cfset freeMemory = runtime.freeMemory() / 1024 / 1024>
<cfset totalMemory = runtime.totalMemory() / 1024 / 1024>
<cfset maxMemory = runtime.maxMemory() / 1024 / 1024>
<cfoutput>
Free Allocated Memory: #Round(freeMemory)#mb<br>
Total Memory Allocated: #Round(totalMemory)#mb<br>
Max Memory Available to JVM: #Round(maxMemory)#mb<br>
</cfoutput>
From these numbers we can also determine the percent of free allocated memory available, and also the percent of avalaible memory allocated
<cfset percentFreeAllocated = Round((freeMemory / totalMemory) * 100)>
<cfset percentAllocated = Round((totalMemory / maxMemory ) * 100)>
<cfoutput>
% of Free Allocated Memory: #percentFreeAllocated#%<br>
% of Available Memory Allocated: #percentAllocated#%<br>
</cfoutput>
Related Entries
- Server Memory Flash Remoting Tool - August 30, 2004
- Robi Sen on Hung Servers, java.lang.OutOfMemory errors and Tuning CF JVM - November 19, 2004
- 1.8GB Heap Limit in ColdFusion MX - June 8, 2004
- ColdFusion Garbage - June 3, 2004
- Have you tuned your JVM on ColdFusion MX yet? - September 25, 2002
Any ideas how we could get even more detailed information, such as the currently running threads or templates?
Tony
CFIF left(system.getproperty("java.version"),3) ge 1.4
This is particularly useful on BlueDragon/.NET, since the underlying Java language support in the .NET framework is about at 1.1 with additional enhancements.
I tried putting an exclusive server lock around it which helped (I could only press it repeatedly about 10 times and it hung before) - at least now you need to hold it down for a short time.
If I was to use this in live code I'd have to restrict the refreshes from a client.. Good snippet though - thanks.
- Dear SQL Server Enterprise Manager Developer
- PostalMethods - Web Service for Snail Mail
- Mastering CFQUERYPARAM
- Google Code Search for ColdFusion
- Speaking at CFUNITED 2008
- Getting ColdFusion SQL Statements from SQL Server Trace
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in










