On Thu, 12 May 2005 20:08:46 +0000 (UTC)
[EMAIL PROTECTED] wrote:

> > My profiling results named peer_ip_string() and _load_plugins() as the
> > main culprits.  I don't entirely trust that now, but I do have
> > optimizations for both if you want them.
> 
> I have a fix for _load_plugins, but not peer_ip_string - I got around
> that  slowness by turning off the max per IP code.

Here's both then.

Brian
=== lib/Qpsmtpd.pm
==================================================================
--- lib/Qpsmtpd.pm  (revision 1371)
+++ lib/Qpsmtpd.pm  (local)
@@ -197,11 +197,13 @@
   return wantarray ? @config : $config[0];
 }
 
+my @real_plugins;
 sub load_plugins {
   my $self = shift;
   
   $self->log(LOGERROR, "Plugins already loaded") if $self->{hooks};
   $self->{hooks} = {};
+  if(@real_plugins) { @_ = ($self); goto &_load_real_plugins; }
   
   my @plugins = $self->config('plugins');
 
@@ -264,12 +266,23 @@
     Qpsmtpd::Plugin->compile($plugin_name, $package, "$dir/$plugin", 
$self->{_test_mode}) unless
         defined &{"${package}::register"};
     
-    my $plug = $package->new();
-    push @ret, $plug;
-    $plug->_register($self, @args);
+    push(@real_plugins, [$package,[EMAIL PROTECTED]);
+       # my $plug = $package->new();
+       # push @ret, $plug;
+       # $plug->_register($self, @args);
 
   }
-  
+  @_ = ($self); goto &_load_real_plugins;
+}
+
+sub _load_real_plugins {
+  my ($self) = @_;
+  my @ret;
+  for my $p (@real_plugins) {
+    my $plug = $p->[0]->new();
+    push @ret, $plug;
+    $plug->_register($self, @{$p->[1]});
+  }
   return @ret;
 }
 
=== Socket.pm
==================================================================
--- Socket.pm  (revision 1369)
+++ Socket.pm  (revision 1370)
@@ -25,6 +25,7 @@
 
 use fields qw(sock fd write_buf write_buf_offset write_buf_size
               read_push_back post_loop_callback
+                         rem_ip
               closed event_watch debug_level);
 
 use Errno qw(EINPROGRESS EWOULDBLOCK EISCONN
@@ -765,9 +766,12 @@
 ### Returns the string describing the peer's IP
 sub peer_ip_string {
     my Danga::Socket $self = shift;
+       return $self->{rem_ip} if defined $self->{rem_ip};
     my $pn = getpeername($self->{sock}) or return undef;
     my ($port, $iaddr) = Socket::sockaddr_in($pn);
-    return Socket::inet_ntoa($iaddr);
+    my $r = Socket::inet_ntoa($iaddr);
+       $self->{rem_ip} = $r;
+    return $r;
 }
 
 ### METHOD: peer_addr_string()

Reply via email to