如何减少 Perl CGI 脚本的启动时间?

发布于 2024-07-16 08:52:23 字数 261 浏览 3 评论 0原文

我正在开发一些 CGI 脚本,并且正在尝试找到一种解决方案来减少使用“use”导入大量模块时产生的“启动时间”。

更新:

提供的解决方案很好,但我正在使用的脚本在控制台和 CGI​​ 模式下运行,检查是否存在一些典型的 HTTP 环境变量。

在“控制台模式”下,它们“正常”转储数据,在“html 模式”下,它们进行一些实时替换并将其他 HTTP 标头发送到客户端。

我想改善这两种情况的启动时间。

I'm developing some CGI scripts and I'm trying to find a solution to decrease the "starting time" produced when I import a lot of modules with "use".

Update:

The solutions provided are nice, but the scripts I'm working runs both in console and CGI mode checking if some typical HTTP environment variables are present.

In "console mode" they dump the data "normally", and in "html mode" they make some realtime replacements and send other HTTP headers to the client.

I'd like to improve the startup time in both cases.

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

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

发布评论

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

评论(6

2024-07-23 08:52:23

考虑使用 CGI::Fast 来启动一个 Perl 进程来处理多个请求。 我花费了很少的精力就将一些大型 CGI 脚本更改为 CGI::Fast。 与 mod_perl 不同,在托管站点上运行 CGI::Fast 非常容易,因为您可以重新启动脚本而无需重新启动 Apache(至少当我要求 mod_perl 时我的托管商是这么告诉我的)。

Consider using CGI::Fast in order to start one perl process to handle multiple requests. It took me very little effort to change some of my big CGI scripts over to CGI::Fast. Unlike mod_perl, it's very easy to run CGI::Fast on hosting sites because you can restart your scripts without restarting Apache (at least that's what my hoster told me when I asked for mod_perl).

你曾走过我的故事 2024-07-23 08:52:23

使用 mod_perl 运行脚本怎么样?

How about using mod_perl to run your scrips?

感性不性感 2024-07-23 08:52:23
  • 确保这实际上是你的瓶颈
  • 只导入你需要的模块
  • 确保你不必搜索无数的地方来找到它们
  • 考虑让启动成本高昂的进程热运行(例如作为守护进程)并使用更轻量级的 CGI 脚本来启动它们
  • 研究各种加速器,而不是从 shell 执行完整的 CGI(取决于您用来服务页面的内容)。
  • Make sure this is actually your bottleneck
  • Only import modules you need
  • Make sure you aren't having to search a zillion places to find them
  • Consider having processes with costly startup run hot (e.g. as a daemon) and use lighter weight CGI scripts to start them
  • Look into various accelerators rather than doing full CGI from a shell (depends on what you're using to serve the pages).
乙白 2024-07-23 08:52:23

您始终可以尝试 less 编译指示:

use less 'starttime';

当然,这取决于系统*< /代码>。 最好的选择是使用 mod_perl 或 FastCGI 模块之一:CGI::Fast, FCGI,

如果需要从命令行快速运行,您可能需要迁移到客户端/服务器架构(这就是 FastCGI 的全部)。

* 警告当前没有系统为 less pragma 实现启动时间选项。

You could always try the less pragma:

use less 'starttime';

Of course, that is system dependent*. Your best bet is to use mod_perl or one of the FastCGI modules: CGI::Fast, FCGI, etc.

If it needs to be fast from the commandline you may want to move to a client/server architecture (which is all FastCGI is).

* warning no systems currently implement a starttime option for the less pragma.

汹涌人海 2024-07-23 08:52:23

好吧,其他人已经建议 CGI 可能是您的问题,所以我认为您无法从图片中删除 CGI

您可能需要考虑这篇旧文章。 显然,启动时间缓慢的一个原因是巨大的 @INC,因此将所有内容整合到一个简短的 PERL5LIB 中似乎有很大帮助(这似乎是一个合理的假设,但我从未尝试过)。

或者(或另外),如果您不介意在运行时支付一些费用,您可以使用 Class::Autouse

享受吧!

Well, others already have suggested that CGI might be your problem here, so I'll consider that you can't remove CGI from the picture.

You might want to consider this old article. Apparently one source of slow startup time is a huge @INC so consolidating everything in a short PERL5LIB seem to help tremendously (that seems to be a fair assumption, but I never tried it).

Alternatively (or additionally), if you don't mind paying some price at run time you can use Class::Autouse

Enjoy!

在你怀里撒娇 2024-07-23 08:52:23

尝试使用 SpeedyCGI 或持久 Perl。

两者都实现了大致相同的想法:它们不是 Perl 解释器,而是解析程序并将其保存在内存中的包装器,从而节省了每次运行时初始化解释器和解析所需的时间。

这应该适用于您描述的双环境设置,但在使用 CGI::Fast 或 mod_perl 时可能不会出现这种情况。

编辑如果这有帮助,那就好。 如果没有,您将必须测量脚本运行时的时间。

Try using SpeedyCGI or Persistent Perl.

Both implement roughly the same idea: Instead of the Perl interpreter, they a wrapper that parses the program and keep it in memory, thus saving the time required for initializing the interpreter and parsing on every run.

This should work fine with the dual-environment setup you described which would/might not be the case when using CGI::Fast or mod_perl.

EDIT If this helps, fine. If it doesn't, you'll have to measure where your script spends its run-time.

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