Ken & Bill,
Here's a patch that's small but has a *big* performance
change in it. This patches the 5.3.15 distribution.
Over the last few months, I've been seeing my mailserver
incur 90-99% CPU utilization during peak loads. During
that time, I was seeing between 5 & 10 authentications
per second. Auth's were taking 2-3 seconds each.
I've updated the courier authdaemon to keep the connections
alive (removing the vclose() in preauthvchkpw) and passing
the environment over the auth socket. That helped alot,
however my cpu was still at 80-99% (both CPU's).
This patch changes vopen_smtp_relay() from a void to int.
The function should return non-zero only if the ip list changed
and tcprules should be run. Before, tcprules was fork/exec'd
on every authentication. With this patch, its only run if
a new IP address was inserted into the relay table. My cpu's
dramatically changed so that they're 99% idle !!! I don't
even see them at the top of the process list (ever). I used
to have 5-15 daemons at the top all the time before this patch.
(And I thought I was going to need more hardware...) Now
I can process 5 auth's per second with only one or two daemons
running. Each auth now only takes milliseconds, even at
peak times.
There is a catch... I've only patched the mysql code to return
the proper values if the table was updated. I've updated oracle
and pgsql to return 1 if the table was updated, 0 on error. So
we need someone to update the code for the other databases to
regognize when the replace did an insert vs. a replace (delete/insert).
Mysql returns 1 row affected on insert only, 2 rows affected if
there was a delete/insert (i.e. replace). We only need to update
tcprules if there was an insert only.
I'll be creating a patch for the courier authlib code so
you can run authdaemon as well soon.
Thanks,
Brian
> Ken, all:
>
> I've put together vpopmail 5.3.15 with a few minor fixes for
> vdeloldusers and vlimits (from Brian):
>
> ChangeLog:
> http://shupp.org/patches/vpopmail-ChangeLog
>
> Download:
> http://shupp.org/patches/vpopmail-5.3.15.tar.gz
>
> Cheers,
>
> Bill Shupp
>
>
diff -c vpopmail-5.3.15.orig/vmysql.c vpopmail-5.3.15/vmysql.c
*** vpopmail-5.3.15.orig/vmysql.c Fri Jan 24 03:30:33 2003
--- vpopmail-5.3.15/vmysql.cMon Jan 27 08:43:31 2003
***
*** 702,717
}
#ifdef POP_AUTH_OPEN_RELAY
! void vopen_smtp_relay()
{
char *ipaddr;
time_t mytime;
int err;
mytime = time(NULL);
ipaddr = getenv("TCPREMOTEIP");
if ( ipaddr == NULL ) {
! return;
}
if ( ipaddr != NULL && ipaddr[0] == ':') {
--- 702,718
}
#ifdef POP_AUTH_OPEN_RELAY
! int vopen_smtp_relay()
{
char *ipaddr;
time_t mytime;
int err;
+ int rows;
mytime = time(NULL);
ipaddr = getenv("TCPREMOTEIP");
if ( ipaddr == NULL ) {
! return 0;
}
if ( ipaddr != NULL && ipaddr[0] == ':') {
***
*** 720,726
++ipaddr;
}
! if ( (err=vauth_open_update()) != 0 ) return;
snprintf( SqlBufUpdate, SQL_BUF_SIZE,
"replace into relay ( ip_addr, timestamp ) values ( \"%s\", %d )",
--- 721,727
++ipaddr;
}
! if ( (err=vauth_open_update()) != 0 ) return 0;
snprintf( SqlBufUpdate, SQL_BUF_SIZE,
"replace into relay ( ip_addr, timestamp ) values ( \"%s\", %d )",
***
*** 731,739
printf("vmysql: sql error[7]: %s\n", mysql_error(&mysql_update));
}
}
res_update = mysql_store_result(&mysql_update);
mysql_free_result(res_update);
! return;
}
void vupdate_rules(int fdm)
--- 732,744
printf("vmysql: sql error[7]: %s\n", mysql_error(&mysql_update));
}
}
+ rows = mysql_affected_rows(&mysql_update);
res_update = mysql_store_result(&mysql_update);
mysql_free_result(res_update);
!
! /* return true if only INSERT (didn't exist) */
! /* would return 2 if replaced, or -1 if error */
! return rows == 1;
}
void vupdate_rules(int fdm)
***
*** 1493,1499
"disable_smtp, perm_account, perm_alias, perm_forward, "
"perm_autoresponder, perm_maillist, perm_quota, perm_defaultquota) \n"
"VALUES \n"
! "('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
domain,
limits->maxpopaccounts,
limits->maxaliases,
--- 1498,1504
"disable_smtp, perm_account, perm_alias, perm_forward, "
"perm_autoresponder, perm_maillist, perm_quota, perm_defaultquota) \n"
"VALUES \n"
! "('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d,
%d, %d, %d, %d, %d, %d)",
domain,
limits->maxpopaccounts,
limits->maxaliases,
diff -c vpopmail-5.3.15.orig/voracle.pc vpopmail-5.3.15/voracle.pc
*** vpopmail-5.3.15.orig/voracle