Perl FastCGI不';不能并行执行脚本

Perl FastCGI不';不能并行执行脚本,perl,fastcgi,Perl,Fastcgi,我对FastCGI还是新手。我无法理解如何并行执行Perl脚本 问题在于,当我在浏览器中多次打开同一URL时,例如: http://example.com/myscript.pl 一种解决方案是为客户端请求的每个脚本生成一个新的Perl进程。但这样做会破坏FastCGI的目的;我不想为每个输入请求每秒产生几十个Perl进程。那是太多的开销了 Perl应该如何与FastCGI一起工作?我一定是做错了什么事 如果我的lighttpd配置很重要(可能有一些错误),那么它是这样的: server.mod

我对FastCGI还是新手。我无法理解如何并行执行Perl脚本

问题在于,当我在浏览器中多次打开同一URL时,例如:

http://example.com/myscript.pl 一种解决方案是为客户端请求的每个脚本生成一个新的Perl进程。但这样做会破坏FastCGI的目的;我不想为每个输入请求每秒产生几十个Perl进程。那是太多的开销了

Perl应该如何与FastCGI一起工作?我一定是做错了什么事

如果我的lighttpd配置很重要(可能有一些错误),那么它是这样的:

server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_redirect", "mod_fastcgi", ) server.document-root = "/var/www" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) server.errorlog = "/var/log/lighttpd/error.log" server.pid-file = "/var/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" index-file.names = ( "index.php", "index.html", "index.htm", "default.htm", " index.lighttpd.html" ) url.access-deny = ( "~", ".inc" ) static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) include_shell "/usr/share/lighttpd/use-ipv6.pl" dir-listing.encoding = "utf-8" server.dir-listing = "enable" compress.cache-dir = "/var/cache/lighttpd/compress/" compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" ) include_shell "/usr/share/lighttpd/create-mime.assign.pl" include_shell "/usr/share/lighttpd/include-conf-enabled.pl" fastcgi.server = ( ".pl" => (( "socket" => "/var/run/lighttpd/perl-fcgi.socket", "bin-path" => "/usr/local/lib/cgi-bin/perl-dispatcher.fcgi", "check-local" => "disable", "max-procs" => 8, )) ) server.modules=( “mod_访问”, “mod_别名”, “mod_compress”, “mod_重定向”, “mod_fastcgi”, ) server.document-root=“/var/www” server.upload-dirs=(“/var/cache/lighttpd/uploads”) server.errorlog=“/var/log/lighttpd/error.log” server.pid-file=“/var/run/lighttpd.pid” server.username=“www-data” server.groupname=“www-data” index-file.names=(“index.php”、“index.html”, “index.htm”、“default.htm”, “index.lighttpd.html”) url.access-deny=(“~”,“.inc”) static-file.exclude-extensions=(“.php”、“.pl”、“.fcgi”) 包括_shell“/usr/share/lighttpd/use-ipv6.pl” dir-listing.encoding=“utf-8” server.dir-listing=“启用” compress.cache-dir=“/var/cache/lighttpd/compress/” compress.filetype=(“应用程序/x-javascript”、“文本/css”, “text/html”、“text/plain”) 包括_shell“/usr/share/lighttpd/create mime.assign.pl” include_shell“/usr/share/lighttpd/include conf enabled.pl” fastcgi.server=( “.pl”=>(( “socket”=>“/var/run/lighttpd/perl fcgi.socket”, “bin path”=>“/usr/local/lib/cgi-bin/perl-dispatcher.fcgi”, “检查本地”=>“禁用”, “最大进程”=>8, )) ) 一种解决方案是为每个脚本生成一个新的Perl进程 这是客户要求的。但这样一来,就可以击败对手了 FastCGI的目的;我不想每次都产生几十个Perl进程 第二,每一个输入请求

您似乎误解了FastCGI。每个进程仍然一次只处理一个请求,因此如果不创建几十个进程来处理请求,就无法同时处理几十个请求

FastCGI实际上提供给您的是,它可以保留进程,以便在以后的请求中重用,或者可以配置为在需要它们的实际请求到来之前提前生成进程。这两种功能都有助于在客户端等待处理请求时最小化按需生成进程的需要,但它们不会改变让一个服务器进程来处理每个传入请求的需要

一种解决方案是为每个脚本生成一个新的Perl进程 这是客户要求的。但这样一来,就可以击败对手了 FastCGI的目的;我不想每次都产生几十个Perl进程 第二,每一个输入请求

您似乎误解了FastCGI。每个进程仍然一次只处理一个请求,因此如果不创建几十个进程来处理请求,就无法同时处理几十个请求


FastCGI实际上提供给您的是,它可以保留进程,以便在以后的请求中重用,或者可以配置为在需要它们的实际请求到来之前提前生成进程。在客户端等待处理请求时,这两项功能都有助于最大限度地减少按需生成进程的需要,但它们并没有改变让一个服务器进程来处理每个传入请求的需要。

如果最多有8个进程池,则传入的第9个请求将等待一段时间才能得到服务。如果可能,可以通过加快脚本速度或增加池来解决此问题。@mpapec您应该从头开始重新阅读问题:-)这里的问题是,从第二个请求开始就已经有等待时间了。池中有8个进程,但只使用其中一个。其他7个什么也不做。如果你有最多8个进程池,传入的第9个请求将等待一段时间才能得到服务。如果可能,可以通过加快脚本速度或增加池来解决此问题。@mpapec您应该从头开始重新阅读问题:-)这里的问题是,从第二个请求开始就已经有等待时间了。池中有8个进程,但只使用其中一个。其他7个进程什么都不做。问题是其他7个进程什么都不做。只有第一个正在运行。正如我在示例中提到的,如果我对两个请求执行了两次请求,那么即使我执行了两次请求,也只会运行其中一个进程。相反,我所期望的是两个进程将处理每个example.com/myscript.pl请求。FastCGI不允许每个进程一次处理一个请求。这只取决于实施情况。最初的FastCGI规范允许在旧连接尚未完成时获取新连接。它还允许多路复用,为不同的连接发送/接收数据包,并行完成它们。起初,他们只考虑使用多线程来利用这些功能,但从那时起,人们还可以使用异步技术或轮询(基于事件的技术)。@CrouchingKitten-关于规范的有趣细节。我不知道这一点。但是,今天(在最初的问题/答案发布6年后),ApacheModu fastcgi和Perl CGI::Fast(OP使用的实现)的组合是否允许单个进程同时处理多个请求?或者是否有另一组基于FastCGI的Perl实现允许这样做?如果是这样的话,我很想看到另一个答案贴在上面,上面有如何做的细节。@DaveSherohman On http://example.com/myscript.pl http://example.com/myscript_copy.pl
#! /usr/bin/perl

use CGI::Fast;

{
    while (new CGI::Fast) {
        do $ENV{SCRIPT_FILENAME};
    }
}
server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_redirect", "mod_fastcgi", ) server.document-root = "/var/www" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) server.errorlog = "/var/log/lighttpd/error.log" server.pid-file = "/var/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" index-file.names = ( "index.php", "index.html", "index.htm", "default.htm", " index.lighttpd.html" ) url.access-deny = ( "~", ".inc" ) static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) include_shell "/usr/share/lighttpd/use-ipv6.pl" dir-listing.encoding = "utf-8" server.dir-listing = "enable" compress.cache-dir = "/var/cache/lighttpd/compress/" compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" ) include_shell "/usr/share/lighttpd/create-mime.assign.pl" include_shell "/usr/share/lighttpd/include-conf-enabled.pl" fastcgi.server = ( ".pl" => (( "socket" => "/var/run/lighttpd/perl-fcgi.socket", "bin-path" => "/usr/local/lib/cgi-bin/perl-dispatcher.fcgi", "check-local" => "disable", "max-procs" => 8, )) )