ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Coro/myhttpd/access.pl
(Generate patch)

Comparing cvsroot/Coro/myhttpd/access.pl (file contents):
Revision 1.20 by root, Mon Dec 3 05:40:09 2001 UTC vs.
Revision 1.25 by root, Tue Dec 4 03:43:54 2001 UTC

1package transferqueue; 1package transferqueue;
2
3my @reserve = (
4 [ 1_200_000, 1],
5 [ 3_000_000, 1],
6 [ 75_000_000, 1],
7);
2 8
3sub new { 9sub new {
4 my $class = shift; 10 my $class = shift;
5 bless { 11 bless {
6 slots => $_[0], 12 slots => $_[0],
12sub start_transfer { 18sub start_transfer {
13 my $self = shift; 19 my $self = shift;
14 my $size = $_[0]; 20 my $size = $_[0];
15 21
16 my $transfer = bless { 22 my $transfer = bless {
17 queue => $self, 23 queue => $self,
18 time => $::NOW, 24 time => $::NOW,
19 size => $size, 25 size => $size,
20 coro => $Coro::current, 26 coro => $Coro::current,
27 started => 0,
21 }, transfer::; 28 }, transfer::;
22 29
23 push @{$self->{wait}}, $transfer; 30 push @{$self->{wait}}, $transfer;
24 Scalar::Util::weaken($self->{wait}[-1]);
25 31
26 $self->wake_next; 32 $self->wake_next;
27 33
28 $trans; 34 $transfer;
35}
36
37sub sort {
38 my @queue = grep $_, @{$_[0]{wait}};
39
40 $_->{spb} = ($::NOW-$_->{time}) / ($_->{size} || 1) for @queue;
41
42 $_[0]{wait} = [sort { $b->{spb} <=> $a->{spb} } @queue];
43
44 Scalar::Util::weaken $_ for @{$_[0]{wait}};
29} 45}
30 46
31sub wake_next { 47sub wake_next {
32 my $self = shift; 48 my $self = shift;
33 49
34 $self->sort; 50 $self->sort;
35 51
36 while($self->{slots} && @{$self->{wait}}) { 52 while (@{$self->{wait}}) {
53 my $size = $self->{wait}[0]{size};
54 my $min = 0;
55 for (@reserve) {
56 last if $size <= $_->[0];
57 $min += $_->[1];
58 }
59 last unless $self->{slots} > $min;
37 my $transfer = shift @{$self->{wait}}; 60 my $transfer = shift @{$self->{wait}};
38 if ($transfer) {
39 $self->{lastspb} = $transfer->{spb}; 61 $self->{lastspb} = $transfer->{spb};
40 $self->{avgspb} ||= $transfer->{spb}; 62 $self->{avgspb} ||= $transfer->{spb};
41 $self->{avgspb} = $self->{avgspb} * 0.95 + $transfer->{spb} * 0.05; 63 $self->{avgspb} = $self->{avgspb} * 0.95 + $transfer->{spb} * 0.05;
64 $self->{started}++;
42 $transfer->wake; 65 $transfer->wake;
43 last; 66 last;
44 }
45 } 67 }
46}
47
48sub sort {
49 $_[0]{wait} = [
50 sort { $b->{spb} <=> $a->{spb} }
51 grep { $_ && ($_->{spb} = ($::NOW-$_->{time})/($_->{size}||1)), $_ }
52 @{$_[0]{wait}}
53 ];
54} 68}
55 69
56sub waiters { 70sub waiters {
57 $_[0]->sort; 71 $_[0]->sort;
58 @{$_[0]{wait}}; 72 @{$_[0]{wait}};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines