Changeset 695

Show
Ignore:
Timestamp:
01/09/07 04:13:06 (3 years ago)
Author:
hachi
Message:

r23649@lj: lj | 2007-01-08 19:10:16 -0800
Switch all logic for calculating device weights to be in Worker/Query, and make the test work again

Location:
trunk/server
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/server/lib/MogileFS/Worker/Query.pm

    r675 r695  
    109109                    return $self->err_line("dup"); 
    110110                } else { 
     111                    warn "Error: $@\n"; 
    111112                    error("Error running command '$cmd': $@"); 
    112113                    return $self->err_line("failure"); 
     
    824825    }; 
    825826 
     827    my @devices_with_weights; 
     828 
    826829    # is this fid still owned by this key? 
    827     my @devids = $fid->devids; 
     830    foreach my $devid ($fid->devids) { 
     831        my $weight; 
     832        my $dev = $dmap->{$devid}; 
     833 
     834        if (defined(my $util = $dev->observed_utilization)) { 
     835            $weight = 102 - $util; 
     836            $weight ||= 100; 
     837        } else { 
     838            $weight = $dev->weight; 
     839            $weight ||= 100; 
     840        } 
     841        push @devices_with_weights, [$devid, $weight]; 
     842    } 
    828843 
    829844    # randomly weight the devices 
    830     my @list = MogileFS::Util::weighted_list(map { [ $_, defined $dmap->{$_}->weight ? 
    831                                                      $dmap->{$_}->weight : 100 ] } @devids); 
     845    my @list = MogileFS::Util::weighted_list(@devices_with_weights); 
    832846 
    833847    # keep one partially-bogus path around just in case we have nothing else to send. 
  • trunk/server/t/10-weighting.t

    r688 r695  
    1313    $ENV{PERL5LIB} = "$Bin/../../api/perl/lib" . ($ENV{PERL5LIB} ? ":$ENV{PERL5LIB}" : ""); 
    1414    $ENV{TESTING} = 1; 
    15     $ENV{T_FAKE_IOW_DEV1} = 5; 
    16     $ENV{T_FAKE_IOW_DEV2} = 90; 
     15    $ENV{T_FAKE_IO_DEV1} = 95; # Simulating high device load (should get fewer requests). 
     16    $ENV{T_FAKE_IO_DEV2} = 5;  # Simulating low device load (shoudld get more requests). 
    1717} 
    1818use MogileFS::Client; 
     
    7171# test some basic commands to backend 
    7272ok($tmptrack->mogadm("domain", "add", "testdom"), "created test domain"); 
    73 ok($tmptrack->mogadm("class", "add", "testdom", "2copies", "--mindevcount=2"), "created 4copies class in testdom"); 
     73ok($tmptrack->mogadm("class", "add", "testdom", "2copies", "--mindevcount=2"), "created 2copies class in testdom"); 
    7474 
    7575ok($tmptrack->mogadm("host", "add", "hostA", "--ip=127.0.1.1", "--status=alive"), "created hostA"); 
     
    7777 
    7878ok($tmptrack->mogadm("device", "add", "hostA", 1), "created dev1 on hostA"); 
    79 ok($tmptrack->mogadm("device", "add", "hostB", 2), "created dev4 on hostB"); 
     79ok($tmptrack->mogadm("device", "add", "hostB", 2), "created dev2 on hostB"); 
    8080 
    8181# wait for monitor 
     
    116116} 
    117117 
    118 ok($stats{1} < 10, "Device 1 should get roughly 5% of traffic, got: $stats{1}"); 
    119 ok($stats{2} > 80, "Device 2 should get roughly 90% of traffic, got: $stats{2}"); 
     118ok($stats{1} < 15, "Device 1 should get roughly 5% of traffic, got: $stats{1}"); 
     119ok($stats{2} > 80, "Device 2 should get roughly 95% of traffic, got: $stats{2}"); 
    120120