/[Sack]/trunk/bin/lorry.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/lorry.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 119 - (show annotations)
Tue Oct 6 23:04:45 2009 UTC (14 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 2198 byte(s)
new commands: [r]estart, [sh]ell, [i]nfo [0.08]

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 } elsif ( $cmd =~ m{^r} ) {
97 $lorry->restart_nodes;
98 } elsif ( $cmd =~ m{^i} ) {
99 $lorry->send_to_all({ info => 1 });
100 my $info = $lorry->get_from_all;
101 foreach my $port ( keys %$info ) {
102 warn "[$port] $lorry->{port_on_host}->{$port} ", dump( $info->{$port} ), "\n";
103 }
104 } elsif ( $cmd =~ m{^sh\s+(.+)} ) {
105 $lorry->send_to_all({ sh => $1 });
106 my $sh = $lorry->get_from_all;
107 foreach my $port ( keys %$sh ) {
108 warn "[$port] $1\n$sh->{$port}->{sh}\n";
109 }
110 } else {
111 warn "UNKNOWN $cmd\n" if $cmd;
112 }
113 }
114
115 warn "exit all nodes\n";
116 $lorry->send_to_all( { exit => 1 } );
117
118 duration 'total usage';
119

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26