Retrieving ColdFusion memory usage
Retrieving ColdFusion memory usage

How much memory is ColdFusion actually using? Well you could look at the jrun.exe process in task manager but it won’t really give you a clear picture and tell you the true tale. You might also install something like FusionReactor or use the ColdFusion Server monitor, but maybe you just want the numbers, don’t have CF enterprise or haven’t the money for FusionReactor.

To gain access to this information we’ll delve into the Java runtime CreateObject('java', 'java.lang.Runtime').getRuntime().

.maxMemory()

This is the maximum amount of memory that can be used, once this is hit your server is going struggle more than myself trying to remember a shopping list.

.totalMemory()

This is the amount of allocated memory (.totalMemory()) that isn’t being used right now. While a useful number to know, it’d probably be easier to work around the free memory in relation to the maximum allowed (.maxMemory()).

.freeMemory()

Out of the maximum memory, this is how much we’re got reserved for usage. All of this won’t be used as the runtime always reserves a little more than it needs, just in case.

<cfscript>

  jRuntime = CreateObject("java","java.lang.Runtime").getRuntime();

  memory = StructNew();

  memory.freeAllocated = jRuntime.freeMemory() / 1024^2;

  memory.allocated = jRuntime.totalMemory() / 1024^2;

  memory.max = jRuntime.maxMemory() / 1024^2;

  memory.used = memory.allocated - memory.freeAllocated;

  memory.freeTotal = memory.max - memory.allocated + memory.freeAllocated;

  memory.percentFreeAllocated = (memory.freeAllocated / memory.allocated) * 100;

  memory.percentAllocated = (memory.allocated / memory.max) * 100;

  memory.percentUsedMax = (memory.used / memory.max) * 100;

  memory.percentUsedAllo = (memory.used / memory.allocated) * 100;

  memory.percentFreeTotal = (memory.freeTotal / memory.max) * 100;

  </cfscript>

  <cfdump var="#memory#">

 

 

[+] View other articles

Small fish in the sea

A ColdFusion programer since 2006 which have developed various web based applications using Adobe ColdFusion (from version 4.5 to 9).

manoj_kothari9@yahoo.com
+91 9711601778

Join me on:

more about me

Video times

Here are some videos related to ColdFusion, Database tutorials. Hopefully it will be helpful for you.

view videos

Tip for the day

Use ListAppend() instead of string concatenate

Suppose we have a list i.e "one,two,three" and want to add another text "four", you can use ListAppend() of coldFusion.

view detail

Guest book
Adobe ColdFusion 9