Have anyone be familiar with epoll ?

LUKE luke at tc.program.com.tw
Fri Nov 3 10:45:02 UTC 2006


Sorry my english is very poor. Our mother language is chinese.
===============================================================
I have some problem about epoll. The Danga::Socket use epoll ,too. Is it have the
same problem?

When i use one program to send data. The speed of upload file is slow.
But when i use two(>=2) programs to testing the transmission speed at
the same time. It is very fast. The  transmission speed is almost equal
to (* how many programs is running)

I can not find any solution to slove the problem.I try to modify the the
value of epoll_wait()'s parameter.

my $events_count = epoll_wait( $epoll,15,3600, $events );
my $events_count = epoll_wait( $epoll,2,0, $events );
my $events_count = epoll_wait( $epoll,2,-1, $events );
my $events_count = epoll_wait( $epoll,2,100, $events );

But the problem still exist.
And i find that the  $events_count always is 1 when i upload file via
another programs.
=========================================================
#!/usr/bin/perl
use strict;
use IO::Socket;
use Sys::Syscall ':epoll';
use Errno 'EWOULDBLOCK';
my ( $haveEpoll, $epoll );
if ( Sys::Syscall::epoll_defined() )
{
 $epoll = eval { epoll_create(1); };
 $haveEpoll = defined $epoll && $epoll >= 0;
}
if ( !$haveEpoll )
{
 require IO::Poll;
}

my $listen = IO::Socket::INET->new(Proto => 'tcp',
       LocalPort => 21,
       Listen =>  SOMAXCONN ,
       Reuse => 1) or die $!;

PollIn_Event_Add( $epoll, fileno($listen) );

my %accepthash;
my $events;
while (1)
{
 $events = [];
 my $events_count = epoll_wait( $epoll,15,3600, $events );

 for ( my $i = 0 ; $i < $events_count ; $i++ )
 {
  my $ev = $events->[$i];
  $ev ||= [];

        if (! defined $accepthash{$ev->[0] } && $ev->[0] eq
fileno($listen) ){
        my $connect=$listen->accept();
        PollIn_Event_Add( $epoll, fileno($connect) );
        $accepthash{fileno($connect)}=$connect;
   open(handle,">/usr/local/Portal/cache/" . fileno($connect) );
  close(handle);
        }else{

  if ( $ev->[1] == EPOLLIN )
  {
   my $buffer='';
   my $rc = sysread($accepthash{$ev->[0]}, $buffer, 16384,0 );
   if ( defined $rc )
   {
    if ( $rc > 0 )
    {
     #print $rc . "\n";
     open(handle,">>/usr/local/Portal/cache/" . $ev->[0]);
     print handle $buffer;
     close(handle);
     substr( $buffer, 0, $rc ) = '';
    } else
    {

                eval { shutdown( $accepthash{$ev->[0]}, 2 ); };
                delete $accepthash{$ev->[0]};
    }


   } elsif ( $! == EWOULDBLOCK )
   {

   } else
   {

                eval { shutdown( $accepthash{$ev->[0]}, 2 ); };
                delete $accepthash{$ev->[0]};
    PollIn_Event_Del( $epoll, $ev->[0] );
   }

  }elsif($ev->[1] == EPOLLERR){

                eval { shutdown( $accepthash{$ev->[0]}, 2 ); };
                delete $accepthash{$ev->[0]};
    PollIn_Event_Del( $epoll, $ev->[0] );
  }
        }
 }
}

sub PollIn_Event_Add
{
 my ( $epoll, $fd ) = @_;
 my $ctl_rtn;
 $ctl_rtn = epoll_ctl( $epoll, EPOLL_CTL_ADD, $fd, EPOLLIN | EPOLLERR );
 print 'PollIn_Event_Add:' . $ctl_rtn . "\n";
}

sub PollIn_Event_Del
{
 my ( $epoll, $fd ) = @_;
 my $ctl_rtn;
 $ctl_rtn = epoll_ctl( $epoll, EPOLL_CTL_DEL, $fd,0 );
 print 'PollIn_Event_Del:' . $ctl_rtn . "\n";
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/djabberd/attachments/20061103/af86c1a6/attachment.html


More information about the Djabberd mailing list