为什么我的 Catalyst 应用程序重启速度很慢?

发布于 2024-08-02 03:54:23 字数 679 浏览 1 评论 0原文

每次构建 Catalyst 应用程序时,我都会遇到应用程序(重新)启动速度极其缓慢的情况,延迟约为 10 秒。 今天,我发现延迟是由以下几行引起的:

use lib '/home/zoul/opt/lib/perl/5.8';
use lib '/home/zoul/opt/share/perl/5.8';
use lib '/home/zoul/opt/lib/perl/5.8.8';
use lib '/home/zoul/opt/share/perl/5.8.8';

这些行仅在服务器上需要,因为我没有在那里获得 root 访问权限,并且将我的 Perl 模块安装在 ~/opt 下。 (我无法使用 Apache 的 SetEnv 模块,因为主机不支持它。因此我必须将库路径输入到 App.pm 中。)在我的开发计算机上表现出血淋淋的延迟,路径不存在。

我的问题:(1)为什么线路会造成这么大的延迟,大约7秒? (2) 有什么好的方法可以解决这个问题? 天真的条件use不起作用:

if ($on_the_hosting_machine)
{
    use lib '…';
}

我想我可以eval以某种方式,或者有更好的方法吗?

Each time I build a Catalyst application I come to a point where the application gets painfully slow to (re)start, the delay is about 10 seconds. Today I figured the delay is caused by the following lines:

use lib '/home/zoul/opt/lib/perl/5.8';
use lib '/home/zoul/opt/share/perl/5.8';
use lib '/home/zoul/opt/lib/perl/5.8.8';
use lib '/home/zoul/opt/share/perl/5.8.8';

These lines are only needed on the server, since I haven’t got root access there and have my Perl modules installed under ~/opt. (I can’t use Apache’s SetEnv module, since the hoster does not support it. Therefore I have to enter the library paths into App.pm.) On my development machine that exhibits the gory delay the paths do not exist.

My questions: (1) Why do the lines cause so much delay, about 7 seconds? (2) What’s a nice way to solve this? Naive conditional use does not work:

if ($on_the_hosting_machine)
{
    use lib '…';
}

I guess I could eval somehow, or is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

亚希 2024-08-09 03:54:23

我不做 Catalyst,所以我不确定这是否能解决您的问题,但您可以尝试做 lib.pm 本质上所做的事情:

BEGIN { 
    if ( $on_the_hosting_machine ) {
        unshift @INC, qw'
            /home/zoul/opt/lib/perl/5.8
            /home/zoul/opt/share/perl/5.8
            /home/zoul/opt/lib/perl/5.8.8
            /home/zoul/opt/share/perl/5.8.8
        ';
    }
};

I do not do Catalyst, so I am not sure if this is going solve your problem, but you can try to do what is essentially what lib.pm does:

BEGIN { 
    if ( $on_the_hosting_machine ) {
        unshift @INC, qw'
            /home/zoul/opt/lib/perl/5.8
            /home/zoul/opt/share/perl/5.8
            /home/zoul/opt/lib/perl/5.8.8
            /home/zoul/opt/share/perl/5.8.8
        ';
    }
};
丶情人眼里出诗心の 2024-08-09 03:54:23

1) 每次有 use 或 require 语句时,它都会按顺序搜索 lib 中的所有目录。 每个 use lib 都会(至少)执行两次 stat 调用。

use lib 只是一个将内容推送到 @LIB 的包装器...但它也会搜索 arch 目录是否存在,并将其推送到 @LIB(如果存在)。

您可以使用 no lib pragma 来反转更改:

no lib ('/home/zoul/opt/lib/perl/5.8', '/home/zoul/opt/share/perl/5.8', '/home/zoul/opt/lib/perl/5.8.8', '/home/zoul/opt/share/perl/5.8.8');

更好的是,您可以修改开发环境以匹配生产,甚至只是将这些目录符号链接到开发设置的真实位置。

1) Every time you have a use or require statement, it searches through all the directories in lib in order. Each use lib does (at least) two stat calls.

use lib is just a wrapper for pushing things onto @LIB... but it also searches for the presence of an arch directory and pushes that on to @LIB if it exists, too.

You can reverse the change using the no lib pragma:

no lib ('/home/zoul/opt/lib/perl/5.8', '/home/zoul/opt/share/perl/5.8', '/home/zoul/opt/lib/perl/5.8.8', '/home/zoul/opt/share/perl/5.8.8');

Better yet, you could modify your dev environment to match production, or even just symlink those directories to the real locations for your dev setup.

百善笑为先 2024-08-09 03:54:23

查看 Jean-Louis Leroy 的 “及时开始”Perl.com 上。 他描述了同样的问题以及一个巧妙的解决方案。

Check out "A Timely Start" by Jean-Louis Leroy on Perl.com. He describes the same problem and a clever fix for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文