Persistent DB connections and other persistent resources (was Re: [Mimedefang] SpamAssassin and SQL user preferences)

David F. Skoll dfs at roaringpenguin.com
Sun Sep 8 22:29:01 EDT 2002


On Sun, 8 Sep 2002, Aaron Paetznick wrote:

> David, what
> if we provided native, persistant facilities from the multiplexor?  That
> would be far better, IMHO.

This is not required.  If you want a persistent database connection, there
are two ways to do it:

1) Open it inside the filter, outside any subroutine definition.  Keep the
connection in a global variable.

2) Keep a global variable, something like this, in filter_begin:

	sub filter_begin {
		unless defined ($DatabaseConnection) {
			$DatabaseConnection = my_db_connect_func(whatever);
		}
		# ...
	}

The global variable (and the database connection) will persist until the
slave is killed, after it has processed its limit of messages.

There is no hook for cleaning up, but this should not be necessary because
the Perl process terminates anyway.  If you absolutely postively need
a cleanup, trap SIGINT, do you cleanup in the signal handler and exit.

> SpamAssassin does have built-in hooks for database preferences, but
> providing this functionality from within MIMEDefang would be far more
> elegant, also IMHO.

And it's how CanIt works.  I do not use persistent database connections,
because so far the overhead has been acceptable.  I might change that
later on.

--
David.




More information about the MIMEDefang mailing list