CFC generation is slow
19 Message(s) by 6 Author(s) originally posted in advanced cfml techniques
| From: obouillaud |
Date: Wednesday, October 17, 2007
|
Hi
Here is my problem :
as soon as I create a cfc, it takes a lot of time (on a computer time scale).
Here is a simple test :
On my
server it takes between 170 and 200 ms for each
loop of hundred CFC
generations.
That is around 16ms for each CFC... where is the
error ???
As soon as I need
inheritance or imbricated cfc's for example to
display a
small
list of 5
product s on a page, it takes 150-400 ms to
generate !!!
Do you've the same behavior ?
<CFLOOP from="1" to="10" index="j">
<CFSET start = GetTickCount()>
<CFLOOP from="1" to="100" index="i">
<CFSET "product_#j#_#i#" =
CreateObject("component ","composants.produits.test")>
</CFLOOP>
<CFSET looptime = GetTickCount() - start>
<CFOUTPUT>
#j# : #looptime# ms
<br />
</CFOUTPUT>
</CFLOOP>
------------------------------------------------------
and my test.CFC
file :
<CFCOMPONENT> </CFCOMPONENT>
| From: Adam Cameron |
Date: Wednesday, October 17, 2007
|
| From: "[CJ]" |
Date: Wednesday, October 17, 2007
|
component
instantiation has always been an expensive process, and not
well-suited for doing within a loop.
can not you
instantiate it once, then do the
assignment inside the loop?
<CFSET myComponent = createObject('component', 'com.produits.test') />
<CFLOOP index="i" ... ><CFSET "myVar#i#" = myComponent /></CFLOOP>
?
| From: Grizzly9279 |
Date: Wednesday, October 17, 2007
|
This was a known issue with CF7 at least; rumor has it CF8 was supposed to
speed up
object instantiation (among other things). Your mileage may vary
though.
Like CJ suggested, you may need to re-
design your
app roach to account for
performance limitations in this
programming environment.
I have gone so far as to implement an "object recycling" mechanism in the past
so I could re-use old, discarded CFCS objects, since it was many times faster
to do that than to create brand new CFC
instance s every time.
Like anything, there's more than one way to skin a cat. Sometimes you've to
get creative to get the desired result. I know that's not the answer you were
looking for, but at least you know that you're not alone in this :)
| From: GArlington |
Date: Thursday, October 18, 2007
|
wrote in
message :
[CJ] : your suggestion is very interresting, that's why I love forums, you can
pass 3 days looking for a solution and someone totaly outside of the project
finds a solution in a few minutes !
... too bad in the case I have the biggest problem, it's not possible as the
instancied object varies. I have a "product" abstract object which is
overridden by some "book", "software", ... objects. As I have betwen 10 and 20
different "flavours" of objects, even if I can instanciate them just one time
(which is better than on each row), I'll still have 10 to 20 x 16ms per
page... which is still slow.
I'm working on a caching mechanism to store the objects in the Application
scope, it looks promising.
You can
cache the components in
session scope (it is safer than
application scope), but depending on your component design you can
wrote in message an object caching component some
time ago, average request/response time is less than 1 ms. If you want
I can share that
code and you can work on improving it.
| From: obouillaud |
Date: Thursday, October 18, 2007
|
[CJ] : your suggestion is very interresting, that's why I love forums, you can
pass 3 days looking for a solution and someone totaly outside of the project
finds a solution in a few minutes !
... too bad in the case I have the biggest problem, it's not possible as the
instancied object varies. I have a "product" abstract object which is
overridden by some "book", "software", ... objects. As I have betwen 10 and 20
different "flavours" of objects, even if I can instanciate them just one time
(which is better than on each row), I'll still have 10 to 20 x 16ms per
page... which is still slow.
I'm working on a caching mechanism to store the objects in the Application
scope, it looks promising.
| From: Grizzly9279 |
Date: Thursday, October 18, 2007
|
CF7 cannot create "copies" of CFCS unfortunately. I can not speak for CF8
though. CF8 was supposed to add
support for object serialization however; this
leads to me believe that it should be possible in CF8 to "copy" an object, if
only by a serialization and de-serialization process.
So in other words, applying the assignment
operator to a CFC will always
result in a pass-by-reference assignment (a pointer). And no, the duplicate()
function doesn't work as you hope it'd against CFCS :)
Best of luck.
| From: cf_dev2 |
Date: Thursday, October 18, 2007
|
at the end I have a struct of objects which all refers to the same object,
with same properties.
Yes, its important to understand that
ColdFusion passes most complex objects
(structures, queries, cfcs, ..) by reference. You can use Duplicate() on some
objects to obtain an independent copy. But as Grizzly9279 mentioned, cfc's are
not one of them
http://livedocs.adobe.com/Cold Fusion/7/htmldocs/00001008.htm
| From: obouillaud |
Date: Thursday, October 18, 2007
|
Ok... I did not test but I'm quite sure that serialization + duplication +
"unserialiszation" is slower than a new CreateObject.
I tried my Application scope cache... and if it seems perfect on my dev
server, it seems a bad idea on my production server.
The structure in the Application scope rise from a few KB to 10 MB, 15 MB
everything seems fine... but after a while the server becomes very slow,
unresponsive... with average response time higher than 60 seconds... an I have
to restart the server.
Too bad that the caching solution seems worse than the "slow solution"
| From: Adam Cameron |
Date: Thursday, October 18, 2007
|
Ok... I did not test but I'm quite sure that serialization + duplication +
"unserialiszation" is slower than a new CreateObject.
Eek, yes.
Did you ever answer my question as to which ColdFusion version, btw?
One thing you could look at is - and this is a
bit of a cop-out, I agree -
is to store the member variables of the object in a cache (so that's just a
struct), and use the (cached) CFC instance as a factory
sort of
arrangement. When you need to do any operations on the object, pass the
cached struct in as one of the arguments of the
method you're calling. Not
very object-oriented, no, but ColdFusion ain't OO. Plus it has trouble
instantiating objects, so one has to work around this.
--
Adam
| From: GArlington |
Date: Friday, October 19, 2007
|
wrote in message:
Ok... I did not test but I'm quite sure that serialization + duplication +
"unserialiszation" is slower than a new CreateObject.
I tried my Application scope cache... and if it seems perfect on my dev
server, it seems a bad idea on my production server.
The structure in the Application scope rise from a few KB to 10 MB, 15 MB
everything seems fine... but after a while the server becomes very slow,
unresponsive... with average response time higher than 60 seconds... an I have
to restart the server.
Too bad that the caching solution seems worse than the "slow solution"
Your problem may be to do with live server (mis) configuration.
I just implemented object caching (currently about 5600 objects cached
at 50KB each) AND component caching on per session basis (average 400
concurrent sessions with 20-30 cached components each). It runs on
live server with average page response time under 1 second.
| From: Adam Cameron |
Date: Friday, October 19, 2007
|
Adam : in my first post is written "I'm running CF8 but it was the same thing
on CF7"... That should answer your question :-)
Did you edit the post to
include that after the fact? I'm reading from the
NNTP feed, and that's not in your first post that I'm looking at.
Either way, sorry for the "silly" question.
I was hoping you were foing to say "CFMX6.0", or something, which was a
known dog at instantiating CFCs. CF8's a lot better.> Your suggestion makes me think that in fact it'd probably be a better idea
to avoid CFC usage. Maybe just CFM pages with includes and functions should be
far more efficient !
Yeah, they can be a bit of a pain in the butt performance-wise. It depends
on the situation. They're fine for
stateless factory
type things, or as
"bags o' functions", but not much chop as "
real " objects, if one's app is
going to rely heavily on them.
One thing I think of when I'm looking at your code (which I realise is just
an example,but infer it's related to your real situation) though: you're
basically generating a collection of products in your loop. So why do not
you create ONE collection
class , which loads its
data from [whatever
mechanism your individual products are loaded via]. I guess it depends on
whether you're dealing with the collection or with one-off products more
often. The collection class could still have a getProduct(sku=something)
method.
--
Adam
| From: obouillaud |
Date: Friday, October 19, 2007
|
Adam : in my first post is written "I'm running CF8 but it was the same thing
on CF7"... That should answer your question :-)
Your suggestion makes me think that in fact it'd probably be a better idea
to avoid CFC usage. Maybe just CFM pages with includes and functions should be
far more efficient !
| From: Adam Cameron |
Date: Friday, October 19, 2007
|
I already use a collection... but it's a collection of "product" objects... ;-(
Sure: I'm imagining it's this collection you
sample code came from, this
being the case. Which'd be fine if that notion worked.
What I'm suggesting isn't make a "collection of objects"; make a class
that is "ObjectCollection", and do not deal with the individual items as
objects; deal with ONE object which works @xxxxxxxxxxx collection-level, not
object-level.
--
Adam
| From: obouillaud |
Date: Friday, October 19, 2007
|
I edited my first post a few minutes after its initial post... I can not remember
why, but I guess it was to add the CF8/CF7 fact... I did not knew that the
newsgroup did not reflect the changes of the posts. Sorry.
I already use a collection... but it's a collection of "product" objects... ;-(
| From: obouillaud |
Date: Saturday, October 20, 2007
|
I understand. and I should store the properties of my products in a struct ?
And the methods within the ObjectCollection CFC ?
for example I have a "set_price(float price ,bool with_taxes)" method in my
product object. It set both the price with taxes and without taxes (that's an
example). So in your suggestion I should rewrite this method with something
like :
set_price(float price ,bool with_taxes, struct table_of_products,int
product_id) which means pass the struct of my products and the id of the
product I want to se the price ?
| From: Adam Cameron |
Date: Monday, October 22, 2007
|
I understand. and I should store the properties of my products in a struct ?
And the methods within the ObjectCollection CFC ?
Yep.
Note: this is only a suggestion, and something to mull over. I have given it
as much thought as it has taken me to type in.> set_price(float price ,bool with_taxes, struct table_of_products,
Well the struct'd be one of the member variables of the object, so
there's probably no reason to pass it in to the method. It's "safe" to
reference member variables directly.
My suggestion of having an external struct holding the data was back when
we were discussing having the Product CFC instance as a "bag o' functions"
relating to a product struct - which'd accordingly only need to be
created once, as opposed to a discrete object for each product.
If you're just having the one object for the ProductCollection, then the
data should remain in the object.
--
Adam
| From: obouillaud |
Date: Wednesday, October 24, 2007
|
That's really lots of work, just to bypass Cold Fusion flaws !
They said since CFMX that it's an object oriented language. Everybody is
writing about inheritance, design patterns, ... and when you use it... you end
up with a slow application, which also seems the cause of server instabilities
(cpu/memory intensive) !
Sometimes I think about my firsts ColdFusion pages, with includes, and
query +
output
directly in the CFM file... not very good for reusability... but the
performances were never a problem !
| From: Adam Cameron |
Date: Wednesday, October 24, 2007
|
That's really lots of work, just to bypass Cold Fusion flaws !
Sure.> They said since CFMX that it's an object oriented language.
No-one that knows what they're talking about has ever claimed that.
It's got some object-oriented touches to it. It ain't OO, and
Macromedia /
Adobe have never claimed as much.To be honest, we have had the problems you're seeing in the past, but not for
a couple of years. And we use CFCS fairly extensively. Sometimes stuff
needs coding around or to be factored in a different way, but as long as
one does not get too dogmatic about things, there's no probs with that.
--
Adam
Next Message: OnLoad, Using JAVAscript takes too long.
Blogs related to CFC generation is slow
Pda
23, 2006 update latest shiloh nouvel update grd analyst news updates lbc8516 update round mound of ass updates current emerging political legal issues affect pda phone virtual lapdance ice pda ibuprofin updated progress story cons
slow ...
Pda
... alienation of affection aleupdat.exe p4xfcu+bios update ak 74 update export model size buy purchase promotion update code amount bi28 days os x locks up when updating ipod update.tds.net/accelerator cfupdate
coldfusion mx qj.updates
...
Adobe Flash
Generator was discontinued in 2002 in favor of new technologies such as Flash Remoting, which allows for seamless transmission of data between the server and the client, and
ColdFusion Server. In October 2000, usability guru Jakob
...
Liveblogging MAX 2007 Day 1 General Session keynote - keep ...
Built using Dreamweaver and
ColdFusion. Using both Flash and HTML to deliever the experience. CF8 and CS3 now out, and their more productive. Lets see what features we can add to United Way in 1 week - challenged Ben Forta and Scott
...
Reiki Healing Love providing Distant Energy Spiritual (Healing ...
We have also updated the Flash Remoting (formerly the
ColdFusion Adapter) to allow you to invoke
CFCs from Flex/ActionScript3 applications. And the Flex messaging Gateway, which supports publishing and subscribing to Flex destinations
...
Pda
+
generation-x + access to any computer ( update) pda comparison chart dell ibm hewlett packard compaq gateway pda waiver home care update epson multimedia storage viewer p-2000 compaco presario 1230 updates atheros a5005g wireless card
...