views:

152

answers:

5

I've been doing some logging of object creation times in our open account process in production. Periodically, initializing an object would take way longer than expected. By initializing I mean calling it's init() and passing a couple of arguments that may be simple variables or objects. e.g.

<cfset validateObj = createObject("component", "compExample").init( 
        productionMode = VARIABLES.productionMode, 
        ipWhiteListed = isWhiteListed, 
        ipLocatorObj = VARIABLES.ipLocatorObj ) />

Thats all that happens in init() methods. Generally the execution time would be 0ms, but at random times I might get 3 or 3.5 seconds. This is not specific to one particular server or to our generally busy period. It appears to be quite random.

One thought was that these templates were being evicted from our template cache as they are not especially frequently used, although I checked cfstat on a number of servers and the max CP/Sec is -1.

Running CF 8,0,1

Has anybody else ever come across this?

A: 

Any chance you are running the profiler from the server manager? This has caused us similar random slowness.

Tom Hubbard
Hi, nope, no profilers running. Thanks.
Bazza
A: 

Couple of thoughts.... Is there any locking going on or dependencies on a network/webservice/database. Do you have have any auditing or similar going on (for example AOP)?

Also what CF version are you on? Are the servers running the .1 updates (if applicable, i.e. 8.01).

John Whish
Hi John, using CF8 with .1 updates, no network/webservice/database activity in the init method, that's the strange thing. No auditing going on on.
Bazza
+1  A: 

There may be something within that init method calling something else that could cause the random slow performance. This may be due to how the arguments are being stored within the CFC by the init method.

Inside the CFC init method, is it just:

<cfset variables.productionMode = arguments.productionMode />

Or using a setter method such as:

<cfset setProductionMode(arguments.productionMode) />

Perhaps a structAppend?

<cfset structAppend(variables, arguments) />

The first method, just a straight-up set would be least likely to cause any issues. The second method, using a setter method, could slow things down depending on what that setter method is doing, what other methods it may be calling, etc... The third method should be fairly consistent but I have seen structAppend and other internal functions randomly slow down for no apparent reason.

I think John Whish's comments are definitely something to look into. As well, is there any odd amount of traffic occurred on this server when the init method slows down?

Have you tried isolating just the createObject() call to see if it is the object instantiation resulting in the slow-down or if it truly is the init method? Generally in CF object instantiation can be a randomly slow process. This may be better in CF 8 lately but experience says it could be the problem.

Greg S
Hi Greg, I'm using the the first method, straight up set. We are using cf8. I'll have a go at isolating the createObject() but believe that it's not actually instantiated until a method is called on it.
Bazza
Thanks Bazza, I'm actually just in the process of switching from cf7 to cf9 and I forgot that CF8 may actually automatically call the init method soon as createObject is called, not sure. I know in CF 7 init was just a pseudo-constructor and never actually invoked by CF automatically.Another way to isolate may just be to <cfreturn /> at the very top of the init method, just to see if it is the object creation penalty or something strange with that method.Good luck!
Greg S
+1  A: 

always upgrade the jvm to the latest version and then see if the problem still exists.

rip747
A: 

Increased the max number of items in the template cache. As the cache uses LRU and these objects are specific to functionality that is not particularly frequently used they were getting evicted from the cache. Updated half the servers and kept half the same and compared after the weekend. There was a dramatic reduction in object instantiation times on the servers where the cache was increased.

Bazza