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>
Tweet
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 26, 2002
Trackbacks
Comments
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.
Post a Comment
Recent Entries
- Firefox Aurora now Supports Content Security Policy 1.0
- Writing Secure CFML cfObjective 2013 Slides
- Upgrading to Java 7 on Linux
- J2EE Sessions in CF10 Uses Secure Cookies
- Learn about ColdFusion Security at cfObjective 2013
- Session Loss and Session Fixation in ColdFusion
- FuseGuard 2.3 Released
- CKEditor Spell Checker Plugin


add to del.icio.us



