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.19 by root, Mon Dec 3 04:57:22 2001 UTC vs.
Revision 1.22 by root, Mon Dec 3 14:44:14 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines