X-Original-To: pgsql-general-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id B72D69FA357 for ; Mon, 3 Jul 2006 12:16:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 12707-06 for ; Mon, 3 Jul 2006 12:16:35 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200]) by postgresql.org (Postfix) with ESMTP id 29D309FA232 for ; Mon, 3 Jul 2006 12:16:34 -0300 (ADT) Received: from einstein.muc.ecircle.de (einstein.muc.ecircle.de [192.168.1.7]) by mail.ecircle.de (READY) with ESMTP id B187055C019; Mon, 3 Jul 2006 17:16:33 +0200 (CEST) Received: from [192.168.1.91] ([192.168.1.91]) by einstein.muc.ecircle.de with Microsoft SMTPSVC(6.0.3790.1830); Mon, 3 Jul 2006 17:16:48 +0200 Subject: Re: [JDBC] Is what I want possible and if so how? From: Csaba Nagy To: Joost Kraaijeveld Cc: Postgres general mailing list In-Reply-To: <3097.1151939008@sss.pgh.pa.us> References: <1151923545.6055.40.camel@localhost> <3097.1151939008@sss.pgh.pa.us> Content-Type: text/plain Message-Id: <1151939793.13456.40.camel@coppola.muc.ecircle.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Mon, 03 Jul 2006 17:16:33 +0200 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 03 Jul 2006 15:16:48.0570 (UTC) FILETIME=[B42B29A0:01C69EB3] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/83 X-Sequence-Number: 97707 On Mon, 2006-07-03 at 17:03, Tom Lane wrote: > status and TX2's select will not return the row. This isn't entirely > perfect because LIMIT acts before FOR UPDATE: TX2's select will return > nothing, rather than selecting the next available row as you might wish. > So you might want to retry the select several times before deciding > there's nothing to do. We do have a table like this, and in fact we did observe this behavior that if multiple clients ask for a row at the same time, the first gets something and the rest nothing. We're actually still looking for an optimal solution for this... For now, we added a random field to the table (with values 0-9), and the clients asks with a where clause for a random value in this field. This way there's a good chance the clients will not tip on each other's toes (i.e. the row asked for is not locked by another client). It is still necessary to retry a few times, but after introducing this random number mechanism we did notice a significant performance improvement in emptying the queue... so it must work somehow. It's true that we usually have 10-15 clients constantly polling the queue, and the queue itself is usually loaded with at least a few hundred tasks, so the random numbers are reasonably distributed to be effective. Now I wonder if there's some other way to get the same result without additional column in the table ? Cheers, Csaba.