如何限制 IIS 中 Perl 脚本的执行时间?

发布于 2024-07-05 12:01:30 字数 334 浏览 6 评论 0原文

这是一个共享托管环境。 我控制服务器,但不一定控制内容。 我有一个使用 Perl 脚本的客户端,该脚本似乎时不时地失去控制,并消耗 50% 的处理器资源,直到进程被终止。

使用 ASP 脚本,我可以限制脚本运行的时间,并且 IIS 会在 90 秒后将其关闭。 这不适用于 Perl 脚本,因为它作为 cgi 进程运行(并且实际上启动外部进程来执行脚本)。

同样,在工作进程中查找过多资源消耗的技术可能不会看到这一点,因为正在消耗的资源(处理器)正在被子进程而不是 WP 本身占用。

有没有办法让 IIS 中止运行时间过长的 Perl 脚本(或其他 cgi 类型进程)? 如何??

This is a shared hosting environment. I control the server, but not necessarily the content. I've got a client with a Perl script that seems to run out of control every now and then and suck down 50% of the processor until the process is killed.

With ASP scripts, I'm able to restrict the amount of time the script can run, and IIS will simply shut it down after, say, 90 seconds. This doesn't work for Perl scripts, since it's running as a cgi process (and actually launches an external process to execute the script).

Similarly, techniques that look for excess resource consumption in a worker process will likely not see this, since the resource that's being consumed (the processor) is being chewed up by a child process rather than the WP itself.

Is there a way to make IIS abort a Perl script (or other cgi-type process) that's running too long? How??

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

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

发布评论

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

评论(4

流殇 2024-07-12 12:01:30

在 UNIX 风格的系统上,我会使用信号处理程序捕获 ALRM 事件,然后使用警报函数启动计时器,然后再启动我预计可能会超时的操作。 如果操作完成,我将使用 Alarm(0) 关闭警报并正常退出,否则信号处理程序应该拾取它以优雅地关闭所有内容。

我已经有一段时间没有在 Windows 上使用 perl 了,虽然 Windows 有点 POSIXy,但我不能保证这会起作用; 您必须检查 perl 文档以了解您的平台是否支持信号或支持的程度。

有关信号处理和使用alarm()的这种自毁编程的更多详细信息可以在 Perl Cookbook 中找到。 这是从另一篇文章中摘录并稍作修改的简短示例:

eval {
    # Create signal handler and make it local so it falls out of scope
    # outside the eval block
    local $SIG{ALRM} = sub {
        print "Print this if we time out, then die.\n";
        die "alarm\n";
    };

    # Set the alarm, take your chance running the routine, and turn off
    # the alarm if it completes.
    alarm(90);
    routine_that_might_take_a_while();
    alarm(0);
};

On a UNIX-style system, I would use a signal handler trapping ALRM events, then use the alarm function to start a timer before starting an action that I expected might timeout. If the action completed, I'd use alarm(0) to turn off the alarm and exit normally, otherwise the signal handler should pick it up to close everything up gracefully.

I have not worked with perl on Windows in a while and while Windows is somewhat POSIXy, I cannot guarantee this will work; you'll have to check the perl documentation to see if or to what extent signals are supported on your platform.

More detailed information on signal handling and this sort of self-destruct programming using alarm() can be found in the Perl Cookbook. Here's a brief example lifted from another post and modified a little:

eval {
    # Create signal handler and make it local so it falls out of scope
    # outside the eval block
    local $SIG{ALRM} = sub {
        print "Print this if we time out, then die.\n";
        die "alarm\n";
    };

    # Set the alarm, take your chance running the routine, and turn off
    # the alarm if it completes.
    alarm(90);
    routine_that_might_take_a_while();
    alarm(0);
};
箜明 2024-07-12 12:01:30

ASP 脚本超时适用于所有脚本语言。 如果脚本在 ASP 页中运行,脚本超时将关闭有问题的页。

The ASP script timeout applies to all scripting languages. If the script is running in an ASP page, the script timeout will close the offending page.

暗恋未遂 2024-07-12 12:01:30

关于这个的更新...

事实证明,这个特定的脚本显然有点错误,并且 Googlebot 具有“按下按钮”并使其疯狂的不可思议的能力。 该脚本是一个较旧的商业应用程序,用于执行日历。 显然,它显示“下个月”和“上个月”的链接,如果您多次关注“下个月”,您就会从悬崖上掉下来。 然而,结果页面仍然包含“下个月”链接。 Googlebot 会不断地击败脚本并吞噬处理器。

奇怪的是,添加带有 Disallow: / 的 robots.txt 并没有解决问题。 要么 Googlebot 已经掌握了该脚本并且不会释放,要么它只是忽略了 robots.txt。

无论如何,Microsoft 的 Process Explorer (http://technet.microsoft.com/en- us/sysinternals/bb896653.aspx)提供了巨大的帮助,因为它使我能够更详细地查看 perl.exe 进程的环境,并且我能够从中确定是 Googlebot 导致了我的问题问题。

一旦我知道这一点(并确定 robots.txt 无法解决问题),我就能够直接使用 IIS 来阻止从 *.googlebot.com 到该网站的所有流量,这在本例中效果很好,因为我们不这样做不在乎 Google 是否将此内容编入索引。

非常感谢大家发布的其他想法!

埃里克·朗曼

An update on this one...

It turns out that this particular script apparently is a little buggy, and that the Googlebot has the uncanny ability to "press it's buttons" and drive it crazy. The script is an older, commercial application that does calendaring. Apparently, it displays links for "next month" and "previous month", and if you follow the "next month" too many times, you'll fall off a cliff. The resulting page, however, still includes a "next month" link. Googlebot would continuously beat the script to death and chew up the processor.

Curiously, adding a robots.txt with Disallow: / didn't solve the problem. Either the Googlebot had already gotten ahold of the script and wouldn't let loose, or else it simply was disregarding the robots.txt.

Anyway, Microsoft's Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) was a huge help, as it allowed me to see the environment for the perl.exe process in more detail, and I was able to determine from it that it was the Googlebot causing my problems.

Once I knew that (and determined that robots.txt wouldn't solve the problem), I was able to use IIS directly to block all traffic to this site from *.googlebot.com, which worked well in this case, since we don't care if Google indexes this content.

Thanks much for the other ideas that everyone posted!

Eric Longman

时光暖心i 2024-07-12 12:01:30

谷歌搜索“iis cpu limit”给出以下命中:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/38fb0130-b14b-48d5-a0a2-05ca131cf4f2.mspx?mfr=true

” CPU 监控功能可监控并自动关闭消耗大量 CPU 时间的工作进程,并为各个应用程序池启用 CPU 监控。”

http://technet.microsoft.com/en-us/library/cc728189。 aspx

“通过使用CPU监控,您可以监控工作进程的CPU使用情况,并可以选择关闭消耗大量CPU时间的工作进程。CPU监控仅在工作进程隔离模式下可用。”

Googling for "iis cpu limit" gives these hits:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/38fb0130-b14b-48d5-a0a2-05ca131cf4f2.mspx?mfr=true

"The CPU monitoring feature monitors and automatically shuts down worker processes that consume large amounts of CPU time. CPU monitoring is enabled for individual application pools."

http://technet.microsoft.com/en-us/library/cc728189.aspx

"By using CPU monitoring, you can monitor worker processes for CPU usage and optionally shut down the worker processes that consume large amounts of CPU time. CPU monitoring is only available in worker process isolation mode."

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