Thursday, November 25, 2010

Memory Consumption of Associated Models?

Hi all,

I recently ran into a speedbump with our application. I have this
model that has about 18 declared associations (excluding circular
references/recursions generated by CakePHP). I noticed OOM errors
happening on our test server and made some quick detective work on our
models, which lead me to our "main" application model. Doing a
debug_backtrace() inside the model class, I noticed that the total
dump (not the raw binary value) of the backtrace array easily exceeded
100MB, which in any web app, is way too much. Just to prove the point,
I tried trimming the associations within the model, and the
application ran (with "not associated" model errors, of course).

Is there any way to curb or control the number of models loaded into
memory, specially when they are not used during runtime? I also read
about the lazy-loading plugins by Matt Curry and Lorenzo Rodríguez
that load the associated models only when they are needed, but for
this project I was thinking if there was a way to do the same thing
without using plugins? The Containable behavior only works for
queries, not for the in-memory PHP objects. I'm thinking that
bindModel() calls on-the-fly are the only way to conserve memory,
downside is I have to write the bindModel() code in places where the
associations would be used, which are a lot.

Suggestions would be deeply appreciated.

Cheers,
OJ

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: