views:

162

answers:

2

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!
+1  A: 

run this (while your scheduled task is running) to see if anything is locking/blocking it:

SELECT
    r.session_id AS spid
        ,r.cpu_time,r.reads,r.writes,r.logical_reads 
        ,r.blocking_session_id AS BlockingSPID
        ,LEFT(OBJECT_NAME(st.objectid, st.dbid),50) AS ShortObjectName
        ,LEFT(DB_NAME(r.database_id),50) AS DatabaseName
        ,s.program_name
        ,s.login_name
        ,OBJECT_NAME(st.objectid, st.dbid) AS ObjectName
        ,SUBSTRING(st.text, (r.statement_start_offset/2)+1,( (CASE r.statement_end_offset
                                                                  WHEN -1 THEN DATALENGTH(st.text)
                                                                  ELSE r.statement_end_offset
                                                              END - r.statement_start_offset
                                                             )/2
                                                           ) + 1
                  ) AS SQLText
    FROM sys.dm_exec_requests                          r
        JOIN sys.dm_exec_sessions                      s ON r.session_id = s.session_id
        CROSS APPLY sys.dm_exec_sql_text (sql_handle) st
    WHERE r.session_id!=@@SPID
KM
Nice query :) I'll definitely use it in future.
zarko.susnjar
+3  A: 

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?

  1. Make sure that debugging is turned of.

  2. Check the logs

  3. 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)

  4. 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.

zarko.susnjar
I had to write the XML file line by line instead of keeping the whole thing in memory and writing it at once.
Jason