I have a scheduled task that runs once a day that builds an XML file that I pass off to another group. Recently the amount of data has greatly increased and is now causing the task to time out (I think). I have tried to optimize my script as much as possible but with no luck. It times out long before an hour and I don’t get any kind of ColdFusion error. Instead I get a “This page cannot be found” after it runs.
- Could this be a timeout someplace other than Coldfusion?
- Is there a more efficient way to build this XML file?
file:
<cfsetting requesttimeout="7200">
<cftry>
<cfquery datasource="datasource" name="getPeople">
select PersonID, FirstName, LastName
from People
</cfquery>
<cfquery datasource="datasource" name="getDepartments">
select d.DepartmentID, DepartmentName, pd.PersonID
from Department d inner join PersonDepartment pd on d.DepartmentID = pd.DepartmentID
</cfquery>
<cfquery datasource="datasource" name="getPapers">
select PaperID, PaperTitle, PaperDescription, pp.PersonID
from Paper p inner join PersonPaper pp on p.PaperID = pp.PaperID
</cfquery>
<cfsavecontent variable="theXML"><?xml version="1.0" encoding="utf-8" ?><people>
<cfoutput query="getPeople"><cfsilent>
<cfquery dbtype="query" name="getPersonDepartments">
select DepartmentID, DepartmentName
from getDepartments
where PersonID = #getPeople.PersonID#
</cfquery>
<cfquery dbtype="query" name="getPersonPapers">
select PaperID, PaperDescription
from getpapers
where PersonID = #getPeople.PersonID#
</cfquery>
</cfsilent> <person>
<person_id>
#getPeople.PersonID#
</faculty_id>
<person_first_name>
#getPeople.Firstname#
</person_first_name>
<person_last_name>
#getPeople.LastName#
</person_last_name><cfif getPersonDepartments.recordcount gt 0>
<departments><cfloop query="getPersonDepartments">
<department>
<department_id>
#getPersonDepartments.DepartmentID#
</department_id>
<department_name>
#getPersonDepartments.DepartmentName#
</department_name>
</department></cfloop>
</departments></cfif><cfif getPersonPapers.recordcount gt 0>
<papers><cfloop query="getPersonPapers">
<paper>
<paper_id>
#getPersonPapers.PaperID#
</paper_id>
<paper_description>
#getPersonPapers.PaperDescription#
</paper_description>
</paper></cfloop>
</papers></cfif>
</person>
</cfoutput></faculty>
</cfsavecontent>
<!--- Generate the file that contains the RSS --->
<cffile action="write" file="#application.serverroot#/People.xml" output="#theXml#" nameconflict="overwrite">
<cfcatch>
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
Done!
To me, it sounds like problem with memory. Could happen that your page fills up whole heap space dedicated to Coldfusion and then “lives” in couple of megabytes which are cleaned with garbage collector until timeuot.
I worked with 1GB+ XML files so I had real nightmare until I figured out everything.
So what you can do?
Make sure that debugging is turned of.
Check the logs
Open CF Admin’s Monitor tool and see what happens when you run this.
(If you can’t see monitor, use task manager and see if jrun takes same amount of memory like set in cfadmin)
You could also make rough estimation how big is your xml, e.g. number of rows by average number of characters in that XML node. And if it’s too large this could help you figure out.
Checkout Charlie Arehart’s list of tools which could help you with this and other issues http://www.carehart.org/cf411/
There are other ways to build XML which could save memory and/or processing time. But let’s first figure out where’s the problem.