我如何在执行的各个阶段进行 Perl CGI 性能测量、基准测试、时间测量?

发布于 2024-10-06 12:30:50 字数 1191 浏览 0 评论 0原文

我想知道用于测量 CGI Perl 代码在各个阶段的执行持续时间的技术(编码、库、配置):

  1. 启动 Perl 解释器
  2. 开始运行 Perl 代码
  3. 加载到本地 Perl .pm 模块中以
  4. 完成运行代码的

例程我对 3 和 4 特别感兴趣,我不认为我可以对 1) 或 2) 做太多事情,因为我不想尝试优化 Perl 解释器,我在这里唯一能做的就是升级将硬件升级到更快的机器和/或使用 mod_perl 而不是经典的 CGI。

3)加载本地 Perl 模块我想测量需要多长时间,但我不确定如何编码,因为我不知道(或不确定)如何在加载这些模块之前执行代码。如果我确实知道,那么我会记录它们加载之前的时间,然后记录它们加载后的时间并计算差异。

4)应该是最容易获得的,因为我会在执行开始时和结束时记录时间(在变量中)。

我在 stackoverflow.com 上进行了搜索,发现:

Google 搜索结果包含时值得一读:

I would like to know techniques (coding, libraries, configurations) for measuring the duration of execution of CGI Perl code at various stages:

  1. starting up the Perl interpreter
  2. beginning running the Perl code
  3. loading in local Perl .pm modules for routines
  4. completed running the code

I'm particularly interested in 3 and 4, I don't believe there is much I can do about 1) or 2) as I wouldn't want to try to optimise the Perl interpreter, the only thing I can do here is upgrade the hardware to a faster machine and/or use mod_perl instead of classic CGI.

With 3) loading the local Perl modules I would like to measure how long it takes but I'm not sure how to code this as I don't know (or am not sure) how to get code to execute before loading these modules. If I did know, then I would record the time before they load, then record the time after they have loaded and calculate the difference.

4) should be the easiest to obtain as I would record the time (in a variable) at start of execution and then at end.

I've done a search at stackoverflow.com and found:

Google search results included:

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

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

发布评论

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

评论(2

南笙 2024-10-13 12:30:50

您可以使用 FastCGI 减少 1)。它还将减少第 2) 和 3) 阶段。

对于测量 3),您可以使用 BEGIN 块。示例:

use Benchmark ':hireswallclock';
my ($t0,$t1);
BEGIN {$t0 = Benchmark->new;}
use DBIx::Class;
BEGIN {$t1 = Benchmark->new;}
print "the loading took:",timestr(timediff($t1, $t0)),"\n";

Deve::NYTProf 将帮助您完成 4)。还有一些特定的模块,如 Template::Timer、CGI::Application::Plugin::DevPopup::Timing、DBIx::Class::Storage::Statistics。

You can reduce 1) with FastCGI. It will reduce stages 2) and 3) too.

For measuring 3) you can use BEGIN blocks. Example:

use Benchmark ':hireswallclock';
my ($t0,$t1);
BEGIN {$t0 = Benchmark->new;}
use DBIx::Class;
BEGIN {$t1 = Benchmark->new;}
print "the loading took:",timestr(timediff($t1, $t0)),"\n";

Deve::NYTProf will help you with 4). Also there are specific modules like Template::Timer, CGI::Application::Plugin::DevPopup::Timing, DBIx::Class::Storage::Statistics.

彡翼 2024-10-13 12:30:50

除了FastCGI之外,还有mod_perl,更重要的是PSGI。使用 PSGI,您可以将应用程序与具体的网络服务器后端分离。

In addition to FastCGI, there is also mod_perl and more importantly PSGI. With PSGI you can decouple your app from concrete webserver backend.

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