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

Comparing Coro/myhttpd/tbf.pl (file contents):
Revision 1.6 by root, Sat Dec 8 21:01:17 2007 UTC vs.
Revision 1.7 by root, Thu Nov 20 14:28:54 2008 UTC

1package tbf; 1package tbf;
2 2
3# kind of token-bucket-filter 3# kind of token-bucket-filter
4 4
5my $max_per_client = $::TBF_MAX_PER_CLIENT || 24000; 5my $max_per_client = $::TBF_MAX_PER_CLIENT || 118000;
6 6
7sub new { 7sub new {
8 my $class = shift; 8 my $class = shift;
9 my %arg = @_; 9 my %arg = @_;
10 my $self = bless \%arg, $class; 10 my $self = bless \%arg, $class;
11 11
12 $self->{maxbucket} ||= $self->{rate} * 3; # max 3s bucket 12 $self->{maxbucket} ||= $self->{rate} * 60; # max bucket
13 $self->{minbucket} ||= $self->{rate}; # minimum bucket to share 13 $self->{minbucket} ||= $self->{rate}; # minimum bucket to share
14 $self->{interval} ||= $::BUFSIZE / $max_per_client; # good default interval 14 $self->{interval} ||= $::BUFSIZE / $max_per_client; # good default interval
15 15
16 if ($self->{rate}) { 16 if ($self->{rate}) {
17 $self->{w} = EV::periodic 0, $self->{interval}, undef, sub { 17 $self->{w} = EV::periodic 0, $self->{interval}, undef, sub {
58sub request { 58sub request {
59 my ($self, $bytes, $weight) = @_; 59 my ($self, $bytes, $weight) = @_;
60 60
61 $weight ||= 1; 61 $weight ||= 1;
62 62
63 my $coro = $Coro::current;
64 my $id = $_tbf_id++; 63 my $id = $_tbf_id++;
64 my $cb = Coro::rouse_cb;
65 65
66 $self->{waitw} += $weight; 66 $self->{waitw} += $weight;
67 $self->{waitq}{$id} = [$weight, 0, $bytes, sub { 67 $self->{waitq}{$id} = [$weight, 0, $bytes, sub {
68 delete $self->{waitq}{$id}; 68 delete $self->{waitq}{$id};
69 $self->{waitw} -= $weight; 69 $self->{waitw} -= $weight;
70 $coro->ready; 70 &$cb;
71 }]; 71 }];
72 72
73 Coro::schedule; 73 Coro::rouse_wait;
74} 74}
75 75
761; 761;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines