Changeset 695
- Timestamp:
- 01/09/07 04:13:06 (3 years ago)
- Location:
- trunk/server
- Files:
-
- 2 modified
-
lib/MogileFS/Worker/Query.pm (modified) (2 diffs)
-
t/10-weighting.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/MogileFS/Worker/Query.pm
r675 r695 109 109 return $self->err_line("dup"); 110 110 } else { 111 warn "Error: $@\n"; 111 112 error("Error running command '$cmd': $@"); 112 113 return $self->err_line("failure"); … … 824 825 }; 825 826 827 my @devices_with_weights; 828 826 829 # 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 } 828 843 829 844 # 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); 832 846 833 847 # keep one partially-bogus path around just in case we have nothing else to send. -
trunk/server/t/10-weighting.t
r688 r695 13 13 $ENV{PERL5LIB} = "$Bin/../../api/perl/lib" . ($ENV{PERL5LIB} ? ":$ENV{PERL5LIB}" : ""); 14 14 $ENV{TESTING} = 1; 15 $ENV{T_FAKE_IO W_DEV1} = 5;16 $ENV{T_FAKE_IO W_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). 17 17 } 18 18 use MogileFS::Client; … … 71 71 # test some basic commands to backend 72 72 ok($tmptrack->mogadm("domain", "add", "testdom"), "created test domain"); 73 ok($tmptrack->mogadm("class", "add", "testdom", "2copies", "--mindevcount=2"), "created 4copies class in testdom");73 ok($tmptrack->mogadm("class", "add", "testdom", "2copies", "--mindevcount=2"), "created 2copies class in testdom"); 74 74 75 75 ok($tmptrack->mogadm("host", "add", "hostA", "--ip=127.0.1.1", "--status=alive"), "created hostA"); … … 77 77 78 78 ok($tmptrack->mogadm("device", "add", "hostA", 1), "created dev1 on hostA"); 79 ok($tmptrack->mogadm("device", "add", "hostB", 2), "created dev 4on hostB");79 ok($tmptrack->mogadm("device", "add", "hostB", 2), "created dev2 on hostB"); 80 80 81 81 # wait for monitor … … 116 116 } 117 117 118 ok($stats{1} < 1 0, "Device 1 should get roughly 5% of traffic, got: $stats{1}");119 ok($stats{2} > 80, "Device 2 should get roughly 9 0% of traffic, got: $stats{2}");118 ok($stats{1} < 15, "Device 1 should get roughly 5% of traffic, got: $stats{1}"); 119 ok($stats{2} > 80, "Device 2 should get roughly 95% of traffic, got: $stats{2}"); 120 120
