1 |
#!/usr/bin/perl |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use Data::Dump qw(dump); |
7 |
use File::Slurp; |
8 |
|
9 |
use lib 'lib'; |
10 |
use Sack::From; |
11 |
use Sack::Lorry; |
12 |
use Net::Ping; |
13 |
use Sack::Color; |
14 |
|
15 |
my $view = 'views/00.demo.pl'; |
16 |
my $offset = 0; |
17 |
my $limit = 5000; |
18 |
my @cloud = ( 'localhost', 'localhost' ); |
19 |
|
20 |
push @cloud, ( '192.168.2.200', '192.168.2.200' ) if `hostname` =~ m{t61p}; |
21 |
|
22 |
my $lorry = Sack::Lorry->new; |
23 |
|
24 |
my $from = Sack::From->new( |
25 |
path => '/data/isi/full.txt', |
26 |
limit => $limit * scalar @cloud, |
27 |
); |
28 |
|
29 |
my $info; |
30 |
|
31 |
my $p = Net::Ping->new; |
32 |
|
33 |
foreach my $host ( @cloud ) { |
34 |
|
35 |
if ( ! $p->ping( $host ) ) { |
36 |
warn "SKIP $host - doesn't respond to ping\n"; |
37 |
next; |
38 |
} |
39 |
|
40 |
if ( my $port = $lorry->start_node( $host ) ) { |
41 |
|
42 |
warn "started [$port] on $host\n"; |
43 |
|
44 |
my $data = $from->shard( $limit ); |
45 |
$lorry->send_to( $port, { data => $data } ) || die "can't send to $port: $!"; |
46 |
|
47 |
$info->{$port} = { |
48 |
host => $host, |
49 |
offset => $offset, |
50 |
limit => $limit, |
51 |
}; |
52 |
|
53 |
$offset += $limit; |
54 |
|
55 |
} else { |
56 |
warn "[$port] skipped"; |
57 |
} |
58 |
} |
59 |
|
60 |
warn "info ",dump $info; |
61 |
|
62 |
warn "load status ", dump( $lorry->get_from_all ); |
63 |
|
64 |
while ( $view ) { |
65 |
warn dump( $lorry->view( $view ) ); |
66 |
print "sack> "; |
67 |
my $cmd = <STDIN>; |
68 |
last unless defined $cmd; # CTRL+D |
69 |
chomp($cmd); |
70 |
} |
71 |
|
72 |
warn "exit all nodes\n"; |
73 |
$lorry->send_to_all( { exit => 1 } ); |
74 |
|