Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 89630 invoked from network); 31 Mar 2006 12:22:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 31 Mar 2006 12:22:28 -0000 Received: (qmail 84197 invoked by uid 500); 31 Mar 2006 12:22:22 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 84180 invoked by uid 500); 31 Mar 2006 12:22:22 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 84169 invoked by uid 99); 31 Mar 2006 12:22:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Mar 2006 04:22:22 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [128.231.90.107] (HELO nihrelayxway2.hub.nih.gov) (128.231.90.107) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Mar 2006 04:22:21 -0800 Received: from holmes.nhgri.nih.gov (HELO [128.231.145.14]) ([128.231.145.14]) by nihrelayxway2.hub.nih.gov with ESMTP; 31 Mar 2006 07:22:01 -0500 X-IronPortListener: NIH_Relay X-SBRS: None X-IronPort-AV: i="4.03,150,1141621200"; d="scan'208"; a="157551781:sNHT28722024" User-Agent: Microsoft-Entourage/11.2.3.060209 Date: Fri, 31 Mar 2006 07:21:59 -0500 Subject: Re: Database transaction across multiple web requests From: Sean Davis To: Tomas Zerolo , "modperl@perl.apache.org" Message-ID: Thread-Topic: Database transaction across multiple web requests Thread-Index: AcZUvbUR8824zsCwEdqDXAANkzVl6A== In-Reply-To: <20060331115956.GA23657@www.trapp.net> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On 3/31/06 6:59 AM, "Tomas Zerolo" wrote: > Howdy, > > this is not strictly a modperl question, but I'm sure some of you are > downright experts on this. > > We have a modperl2 applicattion with a database backend (PostgreSQL, > DBI). For session management we use Apache::Session. > > Now the need has arisen to serve requests yielding many records as > answers -- so the user wants to page through them, a bunch at a time, > search-engine style. > > As far as I see it, there are basically three options: > > (a) Create a database cursor and page through it > (b) Repeat the query (making sure there is a sort criterium) at each > page request, starting at a variable offset and limiting the > result set > (c) Do the whole query at once, putting the results in some kind > of array. > > Variant (a) seems most attractive -- the problem is PostgreSQL wants to > keep a transaction open while the cursor is active (which is > understandable, since the cursor is effectively a (partial) snapshot of > the database). And the transaction is bound to the connection. So I'd > have to make sure that subsequent web requests in one session "find" the > same database connection. Has this been done? Or is this a "don't do > that"? > > There is not much to say on variants (b) and (c), I guess. The usual > trade-offs, (b) generating more database activity and (c) being > potentially a memory killer with the usual optimization tricks. > > Thanks for any pointers, since I have been googling in vain for a while. Tomas, I can't see that a is viable in a web environment, but I'm no "expert". For starters, when does the transaction complete--are you going to trust users to "log off" when they are done with a search? It seems like if you are dealing with enough traffic on your site to swamp a database backend, keeping open that number of database connections open would be prohibitive. Also, if you ever move from a one-server system to use a couple of machines, anything that you can envision hacking together is then useless, as you obviously can't have the same database handle open on multiple servers. I think either B or C is probably going to be easiest (as you already know). Have you benchmarked either b or c? Also, you might have a look at this: http://perlmonks.org/?node_id=492067 It probably falls into category b from above, but the AJAX component makes this look like a pretty slick system. I have never tried it, but I found it intriguing. Sean