Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to improve CFC performance

Guest
Nov 23, 2009 Nov 23, 2009

Hi All,

The database queries I had at the top of the page were moved into a CFC and now it is taking noticeable amount of time in displaying the data. How do I improve the performance of the CFC so that it does not take more amount of time for displaying the data.

I'm on CF 9 Standard version and the methods in the CFC return queries to the page that invoke the component.

Please help. Thanks.

- Milind

TOPICS
Advanced techniques
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2009 Nov 24, 2009

Can you show us some "before" and "after" code?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 24, 2009 Nov 24, 2009

Adam,

Its the same queries that I had on the page are now in a CFC. Do you still need the SQLs? There is absolutely no change in the queries.

Thanks.

- Milind

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2009 Nov 24, 2009

Well if the SQL is identical then no need to post it.  But everything else in the CFC and the calling code would help.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 25, 2009 Nov 25, 2009

Okay ... here we go

This is how I invoke the CFC:

<cfinvoke component="dbqueries.iriqueries" method="getRunDetails" returnvariable="qryRunDetails">
     <cfinvokeargument name="projid" value="#trim(url.pid)#">
     <cfinvokeargument name="runid" value="#trim(url.rid)#">
     <cfinvokeargument name="cru" value="#trim(url.cru)#">
</cfinvoke>


<cfif IsQuery(qryRunDetails)>

     <!--- Data display processing --->

<cfelse>

     <!--- Error message processing --->

</cfif>

And the CFC has following code (I have modified the column names and table names):

<cffunction name="getRunDetails" returntype="query" output="no">
     <cfargument name="projid" type="string" required="yes">
     <cfargument name="runid" type="string" required="yes">
     <cfargument name="cru" type="string" required="yes">
    
     <cfset var qryRunDetails = "">
       
     <cftry>
          <cfquery datasource="#mrsdsn#" name="qryRunDetails">
          SELECT col1, col2, col3, col4, col5
          FROM my_table_name
          WHERE trim(pcn) = <cfqueryparam cfsqltype="cf_sql_varchar" maxlength="13" value="#trim(arguments.projid)#">
          AND trim(run_id) = <cfqueryparam cfsqltype="cf_sql_varchar" maxlength="20" value="#trim(arguments.runid)#">
          AND trim(cru) = <cfqueryparam cfsqltype="cf_sql_varchar" maxlength="20" value="#trim(arguments.
cru)#">
          AND col9 is null
          ORDER BY
col1 ASC
          </cfquery>
          <cfcatch type="database"><cfset bError = true></cfcatch>
     </cftry>
    
     <cfreturn qryRunDetails>
</cffunction>

Note that variables bError and mrsdsn has been declared at the component level not at the method level.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2009 Nov 25, 2009

OK, so not really "displaying" the data in the CFC method: just fetching it.  I don't see anything suboptimal in your code, anyhow.  It's always good to put a second set of eyes on these things though.

As Dan said there is a bit of an overhead instantiating a CFC, but it should be marginal compared to running a DB query.

Can you split your CFC instantiation from your method call and time both separately to see how much overhead the CFC instantiation is actually adding?

Oh, and is "dbqueries.iriqueries" the full path to the CFC from the webroot, or is it relative to your current template or a custom tag path?  I guess the question is does CF have to hunt around for the CFC, or is that its explicit path?  What'd the relevant dir structure, and where are any mappings or custom tag paths pointing?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 25, 2009 Nov 25, 2009

Adam -

  1. How do I separate the instantiation of CFC from method call? Can you provide help?
  2. "dbqueries" is the directory directly under "<cfroot>\CustomTags\". So, I do not think CF would take time in trying to locate the iriqueries.cfc file.

Is there a properties and/or xml file that I can read in order to find out what directories CF looks?

Thanks for taking time in helping me.

- Milind

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2009 Nov 25, 2009

You can create an object instance with createObject(): http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-697b.html

And then you can call its methods as per the example in the docs.  It's a bit less clunky than <cfinvoke> IMO.

There's something in the docs about which order CF looks for things in, but I suspect on custom tag paths is going to be one of the last places (found the page: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7e17.html).

Whilst testing, move your CFC into the same dir structure as your calling code, and see if that improves things.  I gotta say I always explicitly path my CFCs, eg: com.mydomain.myapp.somepackage.someCfc, where /com is a CF mapping.  That said... I would not expect this to reflect much of a performance hit / improvement.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2009 Nov 24, 2009

Why did you move the queries?  Is it so they are available to other pages, or did you do it for philisophical reasons?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 24, 2009 Nov 24, 2009

Yes, I moved them to a CFC so that the same queries can be made available to other pages. But, I was surprised to see the performance taking a hit.

Thanks.

- Milind

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2009 Nov 24, 2009

CFCs do come with a bit of a performance price.  How big a hit are you seeing?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2009 Nov 25, 2009

This thread might be relevent.

http://forums.adobe.com/thread/529289?tstart=0

Also, to see where the delay is occurring, cfdumping a gettickcount() right before your cfinvoke tag and at various places in the cfc may provide some useful information.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2009 Nov 25, 2009

Milind,

Did you turn debugging on? Coldfusion's debugging apparatus parses and records some administration about all the files involved in a request, from the Application.cfc events fired, through to the objects instantiated and methods invoked.

In general, with debugging on, the CFC will contribute much more to the debugger's consumption than an ordinary CFM page. To compare like with like, switch debugging off before doing any comparison. You may likely find there is nothing wrong with your CFC's performance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 26, 2009 Nov 26, 2009

No. The debugging is not turned on.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2009 Nov 27, 2009
No. The debugging is not turned on.

Then turn it on in the Coldfusion Administration. It will display the processes involved in a request and their execution times.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 26, 2009 Nov 26, 2009

Just a long shot from prior experience:

Does  "dbqueries." happen to be a mapping set in CF administrator? I have seen a few times, random, that when its' a mapping, it is a bit slower rather than letting it parse the file/folder path of the webroot. I never could figure it out, but once I had this issue, 2-4 sec difference by having the CF mapping.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 26, 2009 Nov 26, 2009

No "dbqueries" is not mapped. Its a physical directory under "<cfroot>\CustomTags\".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2009 Nov 27, 2009
LATEST

Does this perform any better?

<cfset qryRunDetails = createobject("component", "dbqueries.iriqueries").getRunDetails(trim(url.pid),trim(url.rid),trim(url.cru))>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources