简体   繁体   English

HTML :: FormHandler在使用mod_perl的Catalyst中变慢

[英]HTML::FormHandler slow in Catalyst with mod_perl

I'm using HTML::FormHandler with my mod_perl / Catalyst app to generate a form for my users. 我正在使用HTML :: FormHandler和我的mod_perl / Catalyst应用程序为我的用户生成一个表单。 It works fine, the only problem is that it slows down page load time by a lot. 它工作正常,唯一的问题是它减慢了很多页面加载时间。 Here is my subroutine that creates the new form: 这是我创建新表单的子例程:

sub edit : Chained('base') PathPart Args(0) {
    my ( $self, $c ) = @_; 

    my $form = myapp::Form::Account::Edit->new;

    #validation stuff, etc
    #...
}

Just adding in the one line " my $form = myapp::Form::Account::Edit->new; " causes my page load time to go from 50ms up to anywhere from 500-1000ms. 只需添加一行“ my $form = myapp::Form::Account::Edit->new; ”就会导致我的页面加载时间从50毫秒增加到500-1000毫秒。 I know some people could argue that 500-1000ms page load time for a site is still good, but I'm expecting this site to get high traffic, and right now it's taking that long for a page to load with just one user. 我知道有些人可能会争辩说网站的500-1000ms页面加载时间仍然很好,但是我希望这个网站能够获得高流量,而现在只需要一个用户加载一个页面需要花费很长时间。 I know that HTML::FormHandler is big, as it uses Moose, but after it's loaded once shouldn't it already be loaded? 我知道HTML :: FormHandler很大,因为它使用Moose,但是在加载一次之后它不应该已经加载了吗? Is there any way I can speed up long this is taking, or is this just the price of using HTML::FormHandler? 有没有什么方法可以加快这个,或者这只是使用HTML :: FormHandler的代价? I'd really like to keep using it if I could, as it makes my life as the coder much easier :) 如果可以的话,我真的很想继续使用它,因为它让我的编码生活更轻松:)

You can also build the form in a Moose attribute for the controller, making the form persistent. 您还可以在控件的Moose属性中构建表单,使表单保持不变。 This means that information from the last request will still be in the form object and will be cleared at the beginning of the next request (or could be cleared by the programmer after the form is rendered). 这意味着来自上一个请求的信息仍将在表单对象中,并将在下一个请求开始时清除(或者在呈现表单后由程序员清除)。 You also have to clear any additional attributes you've added to the form, or ensure that they're set on every 'process' call. 您还必须清除已添加到表单中的任何其他属性,或确保在每个“进程”调用中设置它们。

You could load a module with mod_perl, before your apps calling it. 在应用程序调用之前,您可以使用mod_perl加载模块。

http://www.conceptsolutionsbc.com/perl-articles-mainmenu-41/29-perl-and-apache/55-modperl-part-2-pre-loading-perl-modules http://www.conceptsolutionsbc.com/perl-articles-mainmenu-41/29-perl-and-apache/55-modperl-part-2-pre-loading-perl-modules

#put his to apache config file:
PerlModule HTML::FormHandler;

EDIT: 编辑:

To speed up thing at runtuime you could use memoize to speed up things. 为了加快runtuime的速度,你可以使用memoize来加快速度。

Create a new sub, called get_form_handler and memoize its output. 创建一个名为get_form_handler的新子并记住其输出。

You could even use Cache-FastMmap to store this object (output) at once and share between proceses. 您甚至可以使用Cache-FastMmap立即存储此对象(输出)并在进程之间共享。

Regards, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM