Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何构建Perl套接字服务器?_Json_Perl_Sockets_Server_Multiprocessing - Fatal编程技术网

Json 如何构建Perl套接字服务器?

Json 如何构建Perl套接字服务器?,json,perl,sockets,server,multiprocessing,Json,Perl,Sockets,Server,Multiprocessing,我在这方面已经找到了一些稀疏的资源,但我希望构建一个Perl服务器作为“微服务”。更具体地说,是一个SOA格式的LAMPhp/Perl/MariaDB web应用程序 为后端构建高效Perl服务器的最佳方法是什么?Web层为特定的“服务”(高级服务)向特定的Perl服务器打开一个PHP流TCP套接字。该服务器必须异步地为许多Web服务器的请求提供服务。然后,该服务要么直接连接到MySQL以获取答案(简单案例),要么必须进行一些计算工作以生成答案 我的天真实现是单任务: use IO::Socke

我在这方面已经找到了一些稀疏的资源,但我希望构建一个Perl服务器作为“微服务”。更具体地说,是一个SOA格式的LAMPhp/Perl/MariaDB web应用程序

为后端构建高效Perl服务器的最佳方法是什么?Web层为特定的“服务”(高级服务)向特定的Perl服务器打开一个PHP流TCP套接字。该服务器必须异步地为许多Web服务器的请求提供服务。然后,该服务要么直接连接到MySQL以获取答案(简单案例),要么必须进行一些计算工作以生成答案

我的天真实现是单任务:

use IO::Socket::INET;
use Data::Dumper;
use JSON::XS qw(encode_json decode_json);

$| = 1;

my $socket = new IO::Socket::INET (
    LocalHost => '0.0.0.0',
    LocalPort => '7000',
    Proto => 'tcp',
    Listen => 5,
    Reuse => 1
);

while(1) {
        my $client_socket = $socket->accept();
        my $client_address = $client_socket->peerhost();
        my $client_port = $client_socket->peerport();
        my $client_json = "";
        $client_socket->recv($client_json, 1024);
        my $client_data = decode_json $client_json;
        %response = %{process_request($client_data)};
        $reply_json = encode_json(\%response);
        $client_socket->send($reply_json);
        shutdown($client_socket, 1);
}
因此,这显然有问题,因为这是文档中的一个复制粘贴示例。它一次连续处理一个套接字/请求

我的问题是:“在Perl中,有什么最佳实践可以构建一个能够高效多路复用和处理许多传入请求的服务器?”

我自己的想法是构建一个“select”或“epoll”主进程,通过Thread::Queue分岔到一个小的工作线程池


有什么建议吗

>我会考虑使用一个完整的框架,比如MjayListor,或者舞者,或者类似于包的网络::Server。从其perldoc中引用:

   "Net::Server" is an extensible, generic Perl server engine.

   "Net::Server" attempts to be a generic server as in "Net::Daemon" and "NetServer::Generic".  It includes with it the ability to run as an
   inetd process ("Net::Server::INET"), a single connection server ("Net::Server" or "Net::Server::Single"), a forking server
   ("Net::Server::Fork"), a preforking server which maintains a constant number of preforked children ("Net::Server::PreForkSimple"), or as a
   managed preforking server which maintains the number of children based on server load ("Net::Server::PreFork").  In all but the inetd type,
   the server provides the ability to connect to one or to multiple server ports.

Hth

< P>我会考虑使用一个完整的框架,比如MjayListor,或者舞者,或者一个包类网::服务器。从其perldoc中引用:

   "Net::Server" is an extensible, generic Perl server engine.

   "Net::Server" attempts to be a generic server as in "Net::Daemon" and "NetServer::Generic".  It includes with it the ability to run as an
   inetd process ("Net::Server::INET"), a single connection server ("Net::Server" or "Net::Server::Single"), a forking server
   ("Net::Server::Fork"), a preforking server which maintains a constant number of preforked children ("Net::Server::PreForkSimple"), or as a
   managed preforking server which maintains the number of children based on server load ("Net::Server::PreFork").  In all but the inetd type,
   the server provides the ability to connect to one or to multiple server ports.

HTH

这个问题不太适合堆栈溢出,因为它太宽泛了,而且听起来您可能也在询问关于库、非现场资源等的建议。尽管如此,我还是想尝试一下,当你遇到具体问题时,再回来问一些具体的问题。你想提交什么样的数据?@MattJacob是的,这个问题很广泛,但我希望它足够具体,可以得到一些指导。我很感激Mojolicous的指点,我会尽我所能进行研究。这个问题不太适合堆栈溢出,因为它太宽泛了,而且听起来你可能也在征求关于库、场外资源等的建议。我已经说过,我会在,当你遇到具体问题时,再回来问一些具体的问题。你想提交什么样的数据?@MattJacob是的,这个问题很广泛,但我希望它足够具体,可以得到一些指导。我很欣赏Mojolicous的指点,我会尽职调查并研究它。我会调查这些框架,看看它们是否是我所需要的。另一方面,服务器正在分叉,这意味着从长远来看,它将不能作为一个可行的解决方案工作。我将研究这些框架,看看它们是否是我所需要的。另一方面,服务器正在分叉,这意味着从长远来看,它将不能作为一个可行的解决方案工作。