Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any benefit to wrapping CFTHREAD around database inserts?

We have a few thousand catalogs with pages that are accessed up to a half a million times each day. At the end of every page hit, we insert some of the CGI variables into a database. If a form was submitted or a search was performed, we insert some of that information to another database. No information needs to be returned from each of these database inserts. These inserts happen at the end of the page processing.

I've read that once a "run" thread is launched page processing continues and doesn't wait for a response. This seems like it would speed up the page being complete because it's not waiting for the queries in the pages to run. Is this correct?

Is there any benefit to putting these database inserts into their own thread like this?

<cffunction
    name="OnRequest"
    access="public"
    returntype="void"
    output="true"
    hint="Fires after pre page processing is complete.">

    <cfargument name="RequestedContent" type="string" required="true" />


    <!--- OUTPUT THE PAGE CONTENT --->
    <cfinclude template="#ARGUMENTS.RequestedContent#" />

    <cfscript>
        thread
            action="run"
            name="Tracking" {
            include "track1.cfm";
            include "track2.cfm";
        }
    </cfscript>

    <cfreturn />
</cffunction>
like image 202
Evik James Avatar asked Mar 20 '23 02:03

Evik James


1 Answers

You are correct in that if you don't ever join the threads in the page then the page will finish sooner. The threads will potentially finish their execution after all content has been sent to the user and the http connection closed.

I would say this sounds like a bonafied use of that feature, but I also agree that if inserts are taking that much time you may want to look at how you are processing data.

like image 151
Daniel Baughman Avatar answered Apr 08 '23 17:04

Daniel Baughman