Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: A question of fork efficiency

by trippledubs (Deacon)
on Aug 06, 2019 at 03:54 UTC ( #11104011=note: print w/replies, xml ) Need Help??


in reply to A question of fork efficiency

Here is my go, I like this blog entry about arguments in functions: https://www.matheus.ro/2018/01/29/clean-code-avoid-many-arguments-functions/

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use IO::Socket::INET; sub portCheck { my ($server,$port) = @_; my $sock = IO::Socket::INET->new( PeerAddr => $server, Timeout => 1, PeerPort => $port, Proto => 'tcp', ) || return 0; return 1; } my @checks = ( [ 'perlmonks.com',80 ], [ 'perlmonks.org',80 ], [ 'perlmonks.org',25], ); my @kids; for (@checks) { my $pid = fork // die; if ($pid) { push @kids,$pid; next; } exit portCheck(@$_); } for (0..$#kids) { print "@{$checks[$_]}\n"; waitpid($kids[$_],0); print $? >> 8 ,"\n"; }

Replies are listed 'Best First'.
Re^2: A question of fork efficiency
by synless (Acolyte) on Aug 06, 2019 at 14:02 UTC

    Thanks for the reply. I'll test that against what I have and check out that article soon. Also note there are quite a few arguments as I moved that function into a module so it needs to be passed arguments that use to be global vars inherited on the command line.

Re^2: A question of fork efficiency
by synless (Acolyte) on Aug 06, 2019 at 19:01 UTC

    I tested your version against mine and it is around 8 seconds faster than my current version. Though tweaking your version to give similar output may negate some of that. This is the time output running against 7052 servers:

    real 0m58.968s user 0m50.566s sys 1m3.864s

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11104011]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-10-20 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?