[html-formfu] Speed of processing

Kahlil Hodgson kahlil.hodgson at dealmax.com.au
Sat Oct 31 07:15:38 GMT 2009


On 10/30/2009 08:37 AM, Octavian Râşniţă wrote:

> You are probably right. I don't think I understand very well why the
> form should be cloned,

Carl is right on the money :-) Cloning is definitely necessary and is 
what I use in my single-process cache.  Think of the case where two 
different clients try to process the same form at roughly the same time
(and are using the same catalyst process)

   1. A requests a page gets the form first and initialises the cache
   2. B requests the same page gets the same form object from the cache
   3. A submits the form with errors using the same form object as B 
(from the cache)
   4. B submits the form without errors but using the same form object 
as A (from the cache)

Not too sure, but either A gets no errors or B gets the errors from A.
There are a bunch of other similar cases, but the upshot is that we have 
to separate the objects used by different requests.

The fix is to simply store a clone in the cache, and when you retrieve a 
cached object you make another clone.  This is what I did, and despite 
the double clone operation, we still get a noticeable improvement. 
Perhaps doing a clear_errors() on the form before retrieving would be 
faster, but I'm not sure this would disentangled the requests sufficiently.

> but maybe we could choose which of the forms need
> to be cached, and we could choose to cache only those forms that
> couldn't be modified, so they shouldn't be cloned.
> This way the caching of entire forms could be done probably easier at
> least for those cases of forms that don't need to be cloned.

I'm not too sure, but caching forms that include callbacks is probably 
not possible.  Caching forms that get their options from a model may not 
give you a significant speed up.  Pre-caching all cachable forms at 
start-up is probably possible.

> Unfortunately this is a very big issue because the speed decrease is
> very high and if a page uses a form made with HTML::FormFu it becomes
> unimportant if other parts of the page do caching, or if we use database
> query improvements.

This is a huge issue for me as well.  I have a deployment due in early 
December and I need to get this working under mod_perl by then.  The 
fact that the single-proccess cache produces a noticeable improvement 
(2-3 times faster using the Catalyst test server) is promising.  The 
effect of the single-process cache on a mod_perl environment is much 
less: you have more processes and apache recycles your processes after a 
certain number of request, so the cache hit rate is much smaller.

Anyway, I have an unrelated deadline on Wednesday, after which I'll have 
more time to work on this, perhaps with some help from the list :-)

Ciao!

Kal

PS I need a holiday.

-- 
Kahlil (Kal) Hodgson                       GPG: C37B01F4
Head of Technology                         (m) +61 (0) 4 2573 0382
DealMax Pty Ltd                            (w) +61 (0) 3 9008 5281

Suite 1005
401 Docklands Drive
Docklands VIC 3008 Australia

"All parts should go together without forcing.  You must remember that
the parts you are reassembling were disassembled by you.  Therefore,
if you can't get them together again, there must be a reason.  By all
means, do not use a hammer."  -- IBM maintenance manual, 1925




More information about the HTML-FormFu mailing list