rockstar / scripts / sample_loadbalance.pl

#!/usr/bin/perl -w

#This script implements an equal-volume load balancer for Rockstar
my ($num_writers) = split(/ /, scalar <>);
print STDERR "[Loadbalance] Num writers: $num_writers\n";
my (@chunks) = split(/ /, scalar <>);
print STDERR "[Loadbalance] Recommended chunks: @chunks[0..2]\n";
my ($box_size) = split(/ /, scalar <>);
print STDERR "[Loadbalance] Box size: $box_size\n";
my ($scale) = split(/ /, scalar <>);
print STDERR "[Loadbalance] Scale factor: $scale\n";

scalar <>; #Skip format specification

while (<>) {
    last if (/^#/); #Signifies return format specification
    my ($id, $ip, $port) = split;
    print STDERR "[Loadbalance input] $_";
    my $output = "$id $ip $port ";
    my $x_min = ($id % $chunks[0])/($chunks[0]) * $box_size;
    my $x_max = (($id % $chunks[0])+1)/($chunks[0]) * $box_size;
    $id = int($id/$chunks[0]);
    my $y_min = ($id % $chunks[1])/($chunks[1]) * $box_size;
    my $y_max = (($id % $chunks[1])+1)/($chunks[1]) * $box_size;
    $id = int($id/$chunks[1]);
    my $z_min = ($id / $chunks[2]) * $box_size;
    my $z_max = (($id+1) / $chunks[2]) * $box_size;
    $output .= " $x_min $y_min $z_min $x_max $y_max $z_max\n";
    push @output, $output;
    print STDERR "[Loadbalance output] $output";
}

#Note: need to print output *after* all input has been received.
print @output;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.