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 Sack::Color; |
13 |
use Getopt::Long; |
14 |
use Time::HiRes qw(time); |
15 |
|
16 |
|
17 |
my $view = 'views/00.demo.pl'; |
18 |
my $offset = 0; |
19 |
my $limit = 5000; |
20 |
my $cloud_file; |
21 |
|
22 |
|
23 |
GetOptions( |
24 |
'view=s' => \$view, |
25 |
'limit=i' => \$limit, |
26 |
'cloud=s' => \$cloud_file, |
27 |
) or die $!; |
28 |
|
29 |
my $t = time; |
30 |
sub duration { |
31 |
my $now = time; |
32 |
my $d = $now - $t; |
33 |
warn sprintf "%.4fs %s\n", $d, join(' ',@_); |
34 |
$t = $now; |
35 |
} |
36 |
|
37 |
|
38 |
my $lorry = Sack::Lorry->new; |
39 |
|
40 |
my @cloud = -e $cloud_file ? read_file $cloud_file : ( 'localhost' ); |
41 |
warn "bring up cloud ",dump @cloud; |
42 |
|
43 |
my $from = Sack::From->new( |
44 |
path => '/data/isi/full.txt', |
45 |
limit => $limit * scalar @cloud, |
46 |
); |
47 |
|
48 |
duration 'load finished'; |
49 |
|
50 |
my $info; |
51 |
|
52 |
foreach my $host ( @cloud ) { |
53 |
chomp $host; |
54 |
|
55 |
if ( my $port = $lorry->start_node( $host ) ) { |
56 |
|
57 |
warn "started [$port] on $host\n"; |
58 |
|
59 |
my $data = $from->shard( $limit ); |
60 |
$lorry->send_to( $port, { data => $data } ) || die "can't send to $port: $!"; |
61 |
|
62 |
$info->{$port} = { |
63 |
host => $host, |
64 |
offset => $offset, |
65 |
limit => $limit, |
66 |
}; |
67 |
|
68 |
$offset += $limit; |
69 |
|
70 |
} |
71 |
} |
72 |
|
73 |
duration 'cloud up'; |
74 |
|
75 |
warn "info ",dump $info; |
76 |
|
77 |
warn "load status ", dump( $lorry->get_from_all ); |
78 |
|
79 |
our $out; |
80 |
our $repl = 1; |
81 |
|
82 |
while ( $repl ) { |
83 |
print "sack> "; |
84 |
my $cmd = <STDIN>; |
85 |
last unless defined $cmd; # CTRL+D |
86 |
duration 'repl wait'; |
87 |
chomp($cmd); |
88 |
if ( $cmd =~ m{^v} ) { |
89 |
$out = $lorry->view( $view ); |
90 |
duration 'view'; |
91 |
} elsif ( $cmd =~ m{^d} ) { |
92 |
warn dump $out; |
93 |
duration 'dump'; |
94 |
} elsif ( $cmd =~ m{^x} ) { |
95 |
$repl = 0; |
96 |
} else { |
97 |
warn "unknown $cmd\n"; |
98 |
} |
99 |
} |
100 |
|
101 |
warn "exit all nodes\n"; |
102 |
$lorry->send_to_all( { exit => 1 } ); |
103 |
|
104 |
duration 'total usage'; |
105 |
|