Yeah, that sounds right.
A refinement would be to only lock if the application data was not
defined (so, test for it and return if it is defined) and, within the
lock, to retest for it being defined (just as you have now). The test
within the lock is to avoid a race condition where many clients hit at
once before the data is loaded, and all of them hit the cflock and
block. One of them "wins" the lock and loads the data, then each of the
other clients gets the lock and can see that they have nothing to do.
Thanks
Mark
-----Original Message-----
From: Rick Root [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 25, 2007 8:33 AM
To: CF-Talk
Subject: Lock question
I have a flex app that uses a single cfc method to populate all of its
drop down lists. The method is called getListData
It runs 55 queries, and stores the results of those queries in a
structure, and returns the structure to Flex.
This works great, but it's a performance drag - especially if 10 or more
people attempt to launch the application at the same time (like in
training).
I'm using shared objects to reduce the load on the server (the data is
only retrieved once per day).
But in an effort to improve performance, since the data being returned
is the same for *ALL* users, I'm thinking of storing the whole structure
in the application scope.
I want to do locking on this so that only one thread can access the code
within the getlistdata method at a time.... so I'm thinking of doing
something like this.
<cffunction name="getlistdata" ..>
<cfset var retVal=structNew()>
<cflock name="foo" type="exclusive">
<cfif isDefined("application.enquireListData")>
<cfreturn application.enquireListData>
<cfelse>
<cfquery name="retVal.states"...> ...</cfquery>
<cfquery name="retVal.countries"...> ...</cfquery>
<cfquery name="retVal.etc"...> ...</cfquery>
<cfset application.enquireListData = retVal>
</cfif>
</cflock>
<cfreturn retVal>
</cffunction>
So even if 10 peole access it at the same time, only the first one is
going to get the lock.. the first one will run the queries and create
the application variable, while the others wait for the lock to be
released.
The 50 queries only take about a second or two to run, so the wait for
the lock won't be that long.
Am I on the right track here?
--
Rick Root
Check out CFMBB, BlogCFM, ImageCFC, ImapCFC, CFFM, and more at
www.opensourcecf.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade to ColdFusion 8 and integrate with Adobe Flex
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292051
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4