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 |
|
13 |
my $view = 'views/00.demo.pl'; |
14 |
my $offset = 0; |
15 |
my $limit = 5; |
16 |
my @cloud = ( 'localhost', 'localhost' ); |
17 |
|
18 |
|
19 |
my $lorry = Sack::Lorry->new; |
20 |
|
21 |
my $info; |
22 |
|
23 |
foreach my $host ( @cloud ) { |
24 |
if ( my $port = $lorry->start_node( $host ) ) { |
25 |
|
26 |
warn "started [$port] on $host\n"; |
27 |
|
28 |
my $data = Sack::From->shard( path => '/data/isi/full.txt', offset => $offset, limit => $limit ); |
29 |
|
30 |
$lorry->send_to( $port, { data => $data } ) || die "can't send to $port: $!"; |
31 |
$info->{$port} = { |
32 |
host => $host, |
33 |
offset => $offset, |
34 |
limit => $limit, |
35 |
}; |
36 |
|
37 |
$offset += $limit; |
38 |
|
39 |
} else { |
40 |
warn "[$port] skipped"; |
41 |
} |
42 |
} |
43 |
|
44 |
warn "info ",dump $info; |
45 |
|
46 |
warn "load status ", dump( $lorry->get_from_all ); |
47 |
|
48 |
warn "run view $view ", -s $view, " bytes\n"; |
49 |
my $view_code = read_file($view); |
50 |
$lorry->send_to_all({ view => $view_code }); |
51 |
warn "result ", dump( $lorry->get_from_all ); |
52 |
|
53 |
warn "exit all nodes\n"; |
54 |
$lorry->send_to_all( { exit => 1 } ); |
55 |
|