# HG changeset patch # User carl # Date 1105892736 28800 # Node ID 7ad7d8b100bfc0ad6f1508b923b43afad45b58a4 # Parent 7f44a4974bf6d96f4995b53fdaaa7931417610ff only keep 20% of the open resolver sockets in the ready pool. diff -r 7f44a4974bf6 -r 7ad7d8b100bf ChangeLog --- a/ChangeLog Sat Jan 08 12:26:30 2005 -0800 +++ b/ChangeLog Sun Jan 16 08:25:36 2005 -0800 @@ -1,5 +1,8 @@ $Id$ +4.3 2005-01-16 + Only keep 20% of the resolver sockets in the ready pool. + 4.2 2005-01-08 Use the separate resolver processes even if we don't have the resolver interfaces and need gethostbyname. diff -r 7f44a4974bf6 -r 7ad7d8b100bf dnsbl.spec.in --- a/dnsbl.spec.in Sat Jan 08 12:26:30 2005 -0800 +++ b/dnsbl.spec.in Sun Jan 16 08:25:36 2005 -0800 @@ -1,6 +1,6 @@ Summary: DNSBL Sendmail Milter Name: dnsbl -Version: 4.2 +Version: 4.3 Release: 2 Copyright: GPL Group: System Environment/Daemons diff -r 7f44a4974bf6 -r 7ad7d8b100bf package.bash --- a/package.bash Sat Jan 08 12:26:30 2005 -0800 +++ b/package.bash Sun Jan 16 08:25:36 2005 -0800 @@ -1,6 +1,6 @@ #!/bin/bash -VER=dnsbl-4.2 +VER=dnsbl-4.3 mkdir $VER target1=/home/httpd/html/510sg/util/dnsbl.tar.gz target2=/home/httpd/html/510sg/dnsbl.conf diff -r 7f44a4974bf6 -r 7ad7d8b100bf src/dnsbl.cpp --- a/src/dnsbl.cpp Sat Jan 08 12:26:30 2005 -0800 +++ b/src/dnsbl.cpp Sun Jan 16 08:25:36 2005 -0800 @@ -205,6 +205,8 @@ static int resolver_socket = NULL_SOCKET; // socket used to listen for resolver requests static time_t ERROR_SOCKET_TIME = 60; // number of seconds between attempts to open the spam filter socket static time_t last_error_time; +static int resolver_sock_count = 0; // protected with fd_pool_mutex +static int resolver_pool_size = 0; // protected with fd_pool_mutex // packed structure to allow a single socket write to dump the @@ -290,6 +292,9 @@ void my_disconnect(int sock) { if (sock != NULL_SOCKET) { + pthread_mutex_lock(&fd_pool_mutex); + resolver_sock_count--; + pthread_mutex_unlock(&fd_pool_mutex); shutdown(sock, SHUT_RDWR); close(sock); } @@ -316,13 +321,17 @@ if (sock != NULL_SOCKET) { bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0); if (!rc) { - int er = errno; my_disconnect(sock); sock = NULL_SOCKET; last_error_time = now; } } else last_error_time = now; + if (sock != NULL_SOCKET) { + pthread_mutex_lock(&fd_pool_mutex); + resolver_sock_count++; + pthread_mutex_unlock(&fd_pool_mutex); + } return sock; } @@ -410,6 +419,7 @@ err = false; fd = *i; fd_pool.erase(fd); + resolver_pool_size--; } else { // pool is empty, get a new fd @@ -434,8 +444,16 @@ else { int result = pthread_mutex_lock(&fd_pool_mutex); if (!result) { + if (resolver_sock_count > resolver_pool_size*5) { // return the fd to the pool fd_pool.insert(fd); + resolver_pool_size++; + } + else { + // more than 20% of the open resolver sockets are in the pool + // that is enough, so just close this one. + my_disconnect(fd); + } pthread_mutex_unlock(&fd_pool_mutex); } else { diff -r 7f44a4974bf6 -r 7ad7d8b100bf xml/dnsbl.in --- a/xml/dnsbl.in Sat Jan 08 12:26:30 2005 -0800 +++ b/xml/dnsbl.in Sun Jan 16 08:25:36 2005 -0800 @@ -2,7 +2,7 @@ -DNSBL Sendmail milter - Version 4.2 +DNSBL Sendmail milter - Version 4.3
Introduction