X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 85B9E52B23 for ; Sun, 31 Jul 2005 14:10:17 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68524-01 for ; Sun, 31 Jul 2005 17:10:14 +0000 (GMT) Received: from flake.decibel.org (flake.decibel.org [67.100.216.10]) by svr1.postgresql.org (Postfix) with ESMTP id 9596A52B19 for ; Sun, 31 Jul 2005 14:10:13 -0300 (ADT) Received: by flake.decibel.org (Postfix, from userid 1001) id BEE3015252; Sun, 31 Jul 2005 12:10:12 -0500 (CDT) Date: Sun, 31 Jul 2005 12:10:12 -0500 From: "Jim C. Nasby" To: Matthew Schumacher Cc: pgsql-performance@postgresql.org Subject: Re: Performance problems testing with Spamassassin 3.1.0 Message-ID: <20050731171012.GS60019@decibel.org> References: <1122532023.25574.1.camel@localhost.localdomain> <42E9749F.6000709@aptalaska.net> <1122616211.5691.340.camel@lamb.mcmillan.net.nz> <42EA6966.8090402@aptalaska.net> <1122668371.5691.352.camel@lamb.mcmillan.net.nz> <19405.1122670917@sss.pgh.pa.us> <42EAA410.9010700@aptalaska.net> <42EC612A.1080908@arbash-meinel.com> <42ECF3AE.6060809@arbash-meinel.com> <42ED017A.2050207@aptalaska.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42ED017A.2050207@aptalaska.net> X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/504 X-Sequence-Number: 13745 On Sun, Jul 31, 2005 at 08:51:06AM -0800, Matthew Schumacher wrote: > Ok, here is the current plan. > > Change the spamassassin API to pass a hash of tokens into the storage > module, pass the tokens to the proc as an array, start a transaction, > load the tokens into a temp table using copy, select the tokens distinct > into the token table for new tokens, update the token table for known > tokens, then commit. You might consider: UPDATE tokens FROM temp_table (this updates existing records) INSERT INTO tokens SELECT ... FROM temp_table WHERE NOT IN (SELECT ... FROM tokens) This way you don't do an update to newly inserted tokens, which helps keep vacuuming needs in check. > This solves the following problems: > > 1. Each email is a transaction instead of each token. > 2. The update statement is only called when we really need an update > which avoids all of those searches. > 3. The looping work is done inside the proc instead of perl calling a > method a zillion times per email. > > I'm not sure how vacuuming will be done yet, if we vacuum once per email > that may be too often, so I may do that every 5 mins in cron. I would suggest leaving an option to have SA vacuum every n emails, since some people may not want to mess with cron, etc. I suspect that pg_autovacuum would be able to keep up with things pretty well, though. -- Jim C. Nasby, Database Consultant decibel@decibel.org Give your computer some brain candy! www.distributed.net Team #1828 Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?"