我有 unix socket server.pl 的 perl 脚本
use IO::Select;
use IO::Socket;
$lsn = new IO::Socket::INET(Listen => 512, LocalPort => 8888);
my $socket_path = '/tmp/punix.sock';
unlink($socket_path);
$SIG{PIPE} = 'IGNORE';
$|++;
$lsn = IO::Socket::UNIX->new(
Type => SOCK_STREAM,
Local => $socket_path,
Listen => 512,
) or die("Can't create server socket: $!\n");
$sel = new IO::Select( $lsn );
while(@ready = $sel->can_read) {
foreach $fh (@ready) {
if($fh == $lsn) {
# Create a new socket
$new = $lsn->accept;
$sel->add($new);
}
else {
# Process socket
my $input = <$fh>;
#........ do some work
#
# Maybe we have finished with the socket
$sel->remove($fh);
$fh->close;
}
}
}
并且客户端正在并行连接到套接字并获得结果。对于前几个连接来说,这工作正常且快速,例如 100 个连接中的 60 个连接,之后其余 40 个连接的处理速度很慢,例如每秒 1 个。server.pl 似乎没有任何泄漏/问题。可能是什么原因。我试过 Event::Lib 也是同样的问题。