On 10/25/05, Barney Boisvert <[EMAIL PROTECTED]> wrote:
> Instantiation is expensive, so you want to avoid it as part of request
> handling.

I think that's overstating the issue rather dramatically. For example,
both Mach II and Model-Glue instantiate a whole bunch of objects on
every request (the event object, the event context / queue, etc etc).

> The solution is a
> pool of already-instantiated object that are sitting unused.

To be honest, the overhead of the pooling machinery is often going to
be close to that of just creating the objects in the first place. With
a pooling system you have to return your objects to the pool when
you're done whereas a transient object created for a request can just
be 'ignored' (left for the garbage collector to clean up).

I would recommend pooling IF AND ONLY IF you have done load testing
and proved that the application has a bottleneck that is caused by
creating and initializing specific objects on each request.

What can cause an instantiation to be "slow"? I'm not entirely sure
but the following will all contribute to some degree:
- having a lot of code in the pseudo-constructor (between
<cfcomponent> and <cffunction>, e.g., having lots of instance
variables being initialized - which you usually then overwrite in the
init() method anyway... having lots of instance variables is a warning
sign of possible poor design: an object that does too much),
- having a deep inheritance chain (something to be avoided anyway for
many "good design" issues),
- having lots of methods (also something to be avoided since each
object should be cohesive - do one job only and do it well).

> So you don't really save any time overall (you still have to
> instantiate everything), but you avoid having to do it while a client
> is waiting for a request.  With CF, you'd probably set up a scheduled
> task or event gateway that runs every X time and ensures that your
> pool has enough instances, creating more if needed.

This is way complex for most apps - I really think it's overkill and I
would not recommend it as a 'default' approach.
--
Sean A Corfield -- http://corfield.org/
Got frameworks?

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to