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