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 Sack; |
14 |
|
15 |
use Getopt::Long; |
16 |
use Time::HiRes qw(time); |
17 |
|
18 |
|
19 |
my $view = 'views/00.demo.pl'; |
20 |
my $offset = 0; |
21 |
my $limit = 5000; |
22 |
my $cloud_file; |
23 |
|
24 |
|
25 |
GetOptions( |
26 |
'view=s' => \$view, |
27 |
'limit=i' => \$limit, |
28 |
'cloud=s' => \$cloud_file, |
29 |
) or die $!; |
30 |
|
31 |
|
32 |
my $lorry = Sack::Lorry->new; |
33 |
|
34 |
my @cloud = -e $cloud_file ? read_file $cloud_file : ( 'localhost' ); |
35 |
@cloud = map { chomp $_; $_; } @cloud; |
36 |
my $cloud_size = scalar @cloud; |
37 |
|
38 |
warn "cloud with $cloud_size nodes: ",join(' ', @cloud),$/; |
39 |
my $from = Sack::From->new( |
40 |
path => '/data/isi/full.txt', |
41 |
limit => $limit * $cloud_size, |
42 |
); |
43 |
|
44 |
duration 'load finished'; |
45 |
|
46 |
my $info; |
47 |
|
48 |
my $port = 4000; |
49 |
|
50 |
foreach my $host ( @cloud ) { |
51 |
|
52 |
if ( $lorry->start_node_port( $host, $port ) ) { |
53 |
|
54 |
warn "started [$port] on $host\n"; |
55 |
|
56 |
my $data = $from->shard( $limit ); |
57 |
$lorry->send_to( $port, { data => $data } ) || die "can't send to $port: $!"; |
58 |
|
59 |
$info->{$port} = { |
60 |
host => $host, |
61 |
offset => $offset, |
62 |
limit => $limit, |
63 |
}; |
64 |
|
65 |
$port++; |
66 |
$offset += $limit; |
67 |
|
68 |
} |
69 |
} |
70 |
|
71 |
duration 'cloud up'; |
72 |
|
73 |
warn "info ",dump $info; |
74 |
|
75 |
warn "load status ", dump( $lorry->get_from_all ),$/; |
76 |
|
77 |
our $out; |
78 |
our $repl = 1; |
79 |
|
80 |
while ( $repl ) { |
81 |
print "sack> "; |
82 |
my $cmd = <STDIN>; |
83 |
last unless defined $cmd; # CTRL+D |
84 |
duration 'repl wait'; |
85 |
chomp($cmd); |
86 |
if ( $cmd =~ m{^v} ) { |
87 |
$out = $lorry->view( $view ); |
88 |
duration 'view'; |
89 |
} elsif ( $cmd =~ m{^d} ) { |
90 |
warn dump $out; |
91 |
duration 'dump'; |
92 |
} elsif ( $cmd =~ m{^x} ) { |
93 |
$repl = 0; |
94 |
} elsif ( $cmd =~ m{^r} ) { |
95 |
$lorry->restart_nodes; |
96 |
} elsif ( $cmd =~ m{^i} ) { |
97 |
$lorry->send_to_all({ info => 1 }); |
98 |
my $info = $lorry->get_from_all; |
99 |
foreach my $port ( $lorry->connected ) { |
100 |
warn "[$port] $lorry->{port_on_host}->{$port} ", dump( $info->{$port} ), "\n"; |
101 |
} |
102 |
} elsif ( $cmd =~ m{^u} ) { |
103 |
my $updated; |
104 |
foreach my $host ( @cloud ) { |
105 |
next if $updated->{$host}++; |
106 |
warn "update $host\n"; |
107 |
system "find /srv/Sack/ | cpio --create | ssh -F etc/lib.ssh $host cpio --extract --make-directories --unconditional"; |
108 |
} |
109 |
} elsif ( $cmd =~ m{^sh\s+(.+)} ) { |
110 |
$lorry->send_to_all({ sh => $1 }); |
111 |
my $sh = $lorry->get_from_all; |
112 |
foreach my $port ( $lorry->connected ) { |
113 |
warn "[$port]# $1\n$sh->{$port}->{sh}"; |
114 |
} |
115 |
} else { |
116 |
warn "UNKNOWN $cmd\n" if $cmd; |
117 |
} |
118 |
} |
119 |
|
120 |
warn "exit all nodes\n"; |
121 |
$lorry->send_to_all( { exit => 1 } ); |
122 |
|
123 |
duration 'total usage'; |
124 |
|