/[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

Diff of /trunk/bin/lorry.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 113 by dpavlin, Mon Oct 5 23:53:46 2009 UTC revision 150 by dpavlin, Fri Oct 9 17:10:54 2009 UTC
# Line 10  use lib 'lib'; Line 10  use lib 'lib';
10  use Sack::From;  use Sack::From;
11  use Sack::Lorry;  use Sack::Lorry;
12  use Sack::Color;  use Sack::Color;
13    use Sack;
14    
15  use Getopt::Long;  use Getopt::Long;
16  use Time::HiRes qw(time);  use Time::HiRes qw(time);
17    
18    
19  my $view   = 'views/00.demo.pl';  my $view   = 'views/00.demo.pl';
20  my $offset = 0;  my $limit  = 0;
21  my $limit  = 5000;  my $cloud;
 my $cloud_file;  
22    
23    
24  GetOptions(  GetOptions(
25          'view=s'  => \$view,          'view=s'  => \$view,
26          'limit=i' => \$limit,          'limit=i' => \$limit,
27          'cloud=s' => \$cloud_file,          'cloud=s' => \$cloud,
28  ) or die $!;  ) or die $!;
29    
 my $t = time;  
 sub duration {  
         my $now = time;  
         my $d = $now - $t;  
         warn sprintf "%.4fs %s\n", $d, join(' ',@_);  
         $t = $now;  
 }  
   
30    
31  my $lorry = Sack::Lorry->new;  my $lorry = Sack::Lorry->new( view => $view, cloud => $cloud );
   
 my @cloud = -e $cloud_file ? read_file $cloud_file : ( 'localhost' );  
 warn "bring up cloud ",dump @cloud;  
32    
33  my $from  = Sack::From->new(  my $from  = Sack::From->new(
34          path => '/data/isi/full.txt',          path => '/data/isi/full.txt',
35          limit => $limit * scalar @cloud,          limit => $limit * $lorry->cloud_size,
36  );  );
37    
38  duration 'load finished';  duration 'pre-load finished';
   
 my $info;  
   
 foreach my $host ( @cloud ) {  
         chomp $host;  
   
         if ( my $port = $lorry->start_node( $host ) ) {  
39    
40                  warn "started [$port] on $host\n";  $lorry->start_nodes;
   
                 my $data = $from->shard( $limit );  
                 $lorry->send_to( $port, { data => $data } ) || die "can't send to $port: $!";  
   
                 $info->{$port} = {  
                         host => $host,  
                         offset => $offset,  
                         limit => $limit,  
                 };  
   
                 $offset += $limit;  
   
         }  
 }  
41    
42  duration 'cloud up';  duration 'cloud up';
43    
44  warn "info ",dump $info;  $lorry->load_nodes( $from );
45    
46    duration 'load finished';
47    
 warn "load status ", dump( $lorry->get_from_all );  
48    
49  our $out;  our $out;
50  our $repl = 1;  our $cmd;
51    
52  while ( $repl ) {  do {
53          print "sack> ";          print "sack> ";
54          my $cmd = <STDIN>;          $cmd = <STDIN>;
55          last unless defined $cmd; # CTRL+D          last unless defined $cmd; # CTRL+D
         duration 'repl wait';  
56          chomp($cmd);          chomp($cmd);
57          if ( $cmd =~ m{^v} ) {  } while $lorry->command($cmd);
                 $out = $lorry->view( $view );  
                 duration 'view';  
         } elsif ( $cmd =~ m{^d} ) {  
                 warn dump $out;  
                 duration 'dump';  
         } elsif ( $cmd =~ m{^x} ) {  
                 $repl = 0;  
         } else {  
                 warn "unknown $cmd\n";  
         }  
 }  
58    
59  warn "exit all nodes\n";  warn "exit all nodes\n";
60  $lorry->send_to_all( { exit => 1 } );  $lorry->send_to_all( { exit => 1 } );

Legend:
Removed from v.113  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.26