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

Comparing Coro/myhttpd/httpd.pl (file contents):
Revision 1.33 by root, Wed Aug 29 01:40:44 2001 UTC vs.
Revision 1.34 by root, Thu Aug 30 02:58:17 2001 UTC

5 5
6use HTTP::Date; 6use HTTP::Date;
7 7
8no utf8; 8no utf8;
9use bytes; 9use bytes;
10
11our @wait_time = (); # used to calculcate avg. waiting time
12our $wait_time_length = 25;
13 10
14# at least on my machine, this thingy serves files 11# at least on my machine, this thingy serves files
15# quite a bit faster than apache, ;) 12# quite a bit faster than apache, ;)
16# and quite a bit slower than thttpd :( 13# and quite a bit slower than thttpd :(
17 14
31 my $format = shift; 28 my $format = shift;
32 printf "---: $format\n", @_; 29 printf "---: $format\n", @_;
33} 30}
34 31
35our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; 32our $connections = new Coro::Semaphore $MAX_CONNECTS || 250;
36our $transfers = new Coro::Semaphore $MAX_TRANSFER || 50; 33
34our $wait_factor = 0.95;
35
36our @transfers = (
37 [(new Coro::Semaphore $MAX_TRANSFERS_SMALL || 50), 600],
38 [(new Coro::Semaphore $MAX_TRANSFERS_LARGE || 50), 600],
39);
37 40
38my @newcons; 41my @newcons;
39my @pool; 42my @pool;
40 43
41# one "execution thread" 44# one "execution thread"
69our $HTTP_NOW; 72our $HTTP_NOW;
70 73
71Event->timer(interval => 1, hard => 1, cb => sub { 74Event->timer(interval => 1, hard => 1, cb => sub {
72 $NOW = time; 75 $NOW = time;
73 $HTTP_NOW = time2str $NOW; 76 $HTTP_NOW = time2str $NOW;
74}); 77})->now;
75 78
76# the "main thread" 79# the "main thread"
77async { 80async {
78 slog 1, "accepting connections"; 81 slog 1, "accepting connections";
79 while () { 82 while () {
426 $idx); 429 $idx);
427} 430}
428 431
429sub handle_file { 432sub handle_file {
430 my $self = shift; 433 my $self = shift;
431 my $length = -s _; 434 my $length = $self->{stat}[7];
435 my $queue = $::transfers[$length >= $::TRANSFER_SMALL];
432 my $hdr = { 436 my $hdr = {
433 "Last-Modified" => time2str ((stat _)[9]), 437 "Last-Modified" => time2str ((stat _)[9]),
434 }; 438 };
435 439
436 my @code = (200, "ok"); 440 my @code = (200, "ok");
482 $self->response(@code, $hdr, ""); 486 $self->response(@code, $hdr, "");
483 487
484 if ($self->{method} eq "GET") { 488 if ($self->{method} eq "GET") {
485 $self->{time} = $::NOW; 489 $self->{time} = $::NOW;
486 490
487 my $transfer = $::transfers->guard; 491 my $transfer = $queue->[0]->guard;
488 $self->{fh}->writable or return; 492 $self->{fh}->writable or return;
489 493
490 push @::wait_time, $::NOW - $self->{time}; 494 $queue->[1] = $queue->[1] * $::wait_factor
491 shift @::wait_time if @wait_time > $wait_time_length; 495 + ($::NOW - $self->{time}) * (1 - $::wait_factor);
492 $self->{time} = $::NOW; 496 $self->{time} = $::NOW;
493 497
494 my ($fh, $buf, $r); 498 my ($fh, $buf, $r);
495 my $current = $Coro::current; 499 my $current = $Coro::current;
496 open $fh, "<", $self->{path} 500 open $fh, "<", $self->{path}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines