views:

66

answers:

3

So my application allows for users to upload video, convert it using FFMPEG and then transfer it over to the Flash Media Server. Lately, I've run into an issue.

If ever there is an error when converting video, I automatically generate cfcatch report PDF. This time I came across a "Cannot allocate memory" error. This massively concerns me because I'm about to promote my system out and I can't afford for the scripts to stop running within the first few hours.

Is there a way to clean up the memory issues with ColdFusion? I mean, once the job has been done, can I essentially "reset" the memory that the server was using?

If you understand the potential disaster, I'm sure you'll understand why I've got to find out how to make sure my scripts are executing properly. The physical fix is to restart the server, but I obviously cannot be restarting the server every single time a user uploads a video...

A: 

Hi,

I have come across some instances where it's helpful to actually manually run JVM garbage collection from within CF, usually when there is a long running thread doing long-term queue management and the request is very long running.

It might be worth a shot in your case.

To run the garbage collector from within CF you call the following:

<cfset runtime = CreateObject("java", "java.lang.Runtime").getRuntime()>
<cfset runtime.gc()>

Hope it helps!

Ciaran Archer
A: 

If you are on windows, I recommend calling a batch file to do the conversion and file transfer. You can execute the Batch file from CF. This will prevent CF from consuming the entire memory for the conversion and the task can continue running in the background. If you want to wait to get the status, add a "timer" using a CF Java object instantiation to check the status after X seconds.

or you can call a cmd window to run it - http://www.forta.com/blog/index.cfm/2006/7/31/Using-CFEXECUTE-To-Execute-Command-Line-Utilities

eapen
The webserver is linux.
dcolumbus
+1  A: 

I remember reading that some server versions don't properly dispose of COM objects and the like when a page request is finished. If any of this is being done via a CFC or Java class that's being set to a variable, you can put this in OnRequestEnd.cfm:

<cfset StructDelete(variables)>
<cfset StructDelete(request)>

This will get rid of any variables set on the page which are no longer needed. Shouldn't have any negative side effects, and should clear up any memory that might be still lurking in one of the variables set during the processing of that page.

You might also look into using something other than <cfexecute> to process the videos. Maybe have a background process that routinely checks a folder for videos and then converts them in the background? ColdFusion isn't necessarily efficient when it comes to batch processing.

Jordan Reiter
Jordan... I'm using cfexecute because I don't know how else to run the FFMPEG script. Upon upload, I create a record in the DB and then periodically run CRON jobs that run the various .cfm to take care of converting and moving the videos.
dcolumbus