8 |
use Storable; |
use Storable; |
9 |
use File::Slurp; |
use File::Slurp; |
10 |
use Net::Ping; |
use Net::Ping; |
11 |
|
use Time::HiRes qw(time); |
12 |
|
|
13 |
our $pids; |
our $pids; |
14 |
our $ports; |
our $ports; |
35 |
return; |
return; |
36 |
} |
} |
37 |
|
|
38 |
warn "start_node $host\n"; |
warn "start_node $host [$port]\n"; |
39 |
|
|
40 |
my $ssh_config = '-F etc/lib.ssh'; |
my $ssh_config = '-F etc/lib.ssh'; |
41 |
|
|
65 |
|
|
66 |
$self->{sock}->{$port} = $sock; |
$self->{sock}->{$port} = $sock; |
67 |
|
|
68 |
warn "\nconnected to $port\n"; |
warn "# connected to $port\n"; |
69 |
|
|
70 |
$self->{connected}->{$port} = $host; |
$self->{connected}->{$port} = $host; |
71 |
|
|
109 |
|
|
110 |
sub send_to_all { |
sub send_to_all { |
111 |
my ( $self, $data ) = @_; |
my ( $self, $data ) = @_; |
112 |
$self->send_to( $_, $data ) foreach keys %{ $self->{connected} }; |
$self->send_to( $_, $data ) foreach sort keys %{ $self->{connected} }; |
113 |
} |
} |
114 |
|
|
115 |
sub get_from_all { |
sub get_from_all { |
116 |
my ( $self ) = @_; |
my ( $self ) = @_; |
117 |
my $result; |
my $result; |
118 |
$result->{$_} = $self->get_from( $_ ) foreach keys %{ $self->{connected} }; |
$result->{$_} = $self->get_from( $_ ) foreach sort keys %{ $self->{connected} }; |
119 |
return $result; |
return $result; |
120 |
} |
} |
121 |
|
|
185 |
} |
} |
186 |
|
|
187 |
$t_merge = time - $t_merge; |
$t_merge = time - $t_merge; |
188 |
warn sprintf "\nmerged %d in %.4fs %.2f/s\n", $tick, $t_merge, $t_merge / $tick ; |
warn sprintf "\nmerged %d in %.4fs\n", $tick, $t_merge; |
189 |
|
|
190 |
|
return $tick; |
191 |
} |
} |
192 |
|
|
193 |
|
|
194 |
sub view { |
sub view { |
195 |
my ( $self, $view ) = @_; |
my ( $self, $view ) = @_; |
196 |
|
|
197 |
|
my $t = time; |
198 |
$out = {}; |
$out = {}; |
199 |
|
|
200 |
warn "run view $view ", -s $view, " bytes\n"; |
warn "run view $view ", -s $view, " bytes\n"; |
202 |
my $view_code = read_file($view); |
my $view_code = read_file($view); |
203 |
$self->send_to_all({ view => $view_code }); |
$self->send_to_all({ view => $view_code }); |
204 |
|
|
205 |
|
my $total; |
206 |
|
|
207 |
foreach my $port ( keys %{ $self->{connected} } ) { |
foreach my $port ( keys %{ $self->{connected} } ) { |
208 |
my $result = $self->get_from( $port ); |
my $result = $self->get_from( $port ); |
209 |
warn "# result ", dump $result if $self->{debug}; |
warn "# result ", dump $result if $self->{debug}; |
210 |
if ( $result->{view} ) { |
if ( my $out = delete $result->{out} ) { |
211 |
$self->merge( $result->{view} ); |
warn "[$port] result ", dump $result if $result; |
212 |
|
$total += $self->merge( $out ); |
213 |
} else { |
} else { |
214 |
warn "no view from $port\n"; |
warn "no out from $port in ",dump $result; |
215 |
} |
} |
216 |
} |
} |
217 |
|
|
218 |
|
warn sprintf "view %d in %.4fs\n", $total, time - $t; |
219 |
|
|
220 |
return $out; |
return $out; |
221 |
} |
} |
222 |
|
|