[Catalyst] Store something in the stash at startup
Octavian Rasnita
octavian.rasnita at ssifbroker.ro
Wed Aug 18 05:19:42 GMT 2010
From: "Tomas Doran" <bobtfish at bobtfish.net>
>
> On 17 Aug 2010, at 06:27, Octavian Rasnita wrote:
>>
>> I load and store this object in the stash on each request in the
>> Root::auto : Private method with:
>>
>> $c->stash(menu => $c->model('Menu'));
>>
>> But this would re-create the menu object on each request, and this takes
>> time.
>
> No, it wouldn't. The adaptor you showed has a lifetime of the
> application, and so it won't be recreated each request.
Thank you all for remembering me this! I used Catalyst::Model::Factory
somewhere else exactly because it doesn't create just a single object
instance like C::M::Adaptor, but I have forgotten.
> > Also, even if you were creating an object every request (which you
> aren't), if you're worrying about this without numbers, then this is
> premature opimisation.
Well, it is not exactly without numbers. I have tried
ab -n 200 -c 5 http://localhost/
The result was... 3 to 4 requests per second.
I commented the line that stores the menu in the stash (for not using the
menu at all) and the same command line gave a result of around 33 requests
per second, which is a very big difference.
So I think the buggy part is the module that creates the menu object from
the data structure loaded in the configuration file.
I will first try to use the data structure directly in the TT template
without creating an object from it.
If it would be too slow, I will try to "draw" the menu entirely in the
template without using an external data structure, although I don't like
this.
Thank you all very much for your help.
Octavian
__________ Information from ESET NOD32 Antivirus, version of virus signature database 5374 (20100817) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
More information about the Catalyst
mailing list