[SJF Logo]
Steve Friedl's Weblog

April 27, 2003
SpamAssassin patches: UNIX domain sockets

I'm a very happy user of SpamAssassin, having integrated it into Postfix. I am also using the spamc/spamd system, and it's been working great on my system and that of two customers. SpamAssassin just rocks.

I have made a couple of patches to version 2.60 (the development release) that I've been using for a couple of days now, and I'll be submitting them to the project once I have a bit more time on them.

Change #1 is to support UNIX domain sockets for spamc/spamd communiations. The current program uses TCP/IP to send the message from the client to the daemon, and to get the reply, but when the client and server are on the same machine, a faster version of IPC is available. UNIX domain sockets avoid all the TCP/IP overhead, and by my testing run 3-4 times faster than even IP via localhost. This IPC uses a filename for rendesvous (say, "/tmp/spamd.sock") instead of a port number, and running "netstat -an" will reveal several UNIX domain sockets.

Change #2 performs randomization of the list of IP addresses obtained from DNS when the client is talking to the server. A DNS name (say "spamserver") can contain multiple IP addresses, and it would be a kind of load balancing if a slow mail server is able to talk to several SpamAssassin servers. The -H command-line parameter to spamc will randomize the list of IP addresses and attempt to connect to them in order. This was suggested by Jeremy Zawodny, and it turns out that the changes for UNIX domain sockets meant this was easy.

All through the spamc code, the IP-related functions refer to hostname+port number, but I have replaced all these calls with a reference to a "transport" structure: this object contains either the list of IP addresses or the path to the UNIX domain socket. In the process, the code that dealt with making connections and fallback was much simplified: "doing fallback" is no longer a special case.

Those curious to apply this patch to version 2.60 (bleeding edge) can find the code here:

Posted by Steve at April 27, 2003 08:26 PM | TrackBack
Comments
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?