Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XVbQG-0003fL-Gf for pgsql-jdbc@arkaria.postgresql.org; Sun, 21 Sep 2014 07:19:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XVbQF-0004G0-Sf for pgsql-jdbc@arkaria.postgresql.org; Sun, 21 Sep 2014 07:19:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XVbQE-0004Fr-Rk for pgsql-jdbc@postgresql.org; Sun, 21 Sep 2014 07:19:03 +0000 Received: from mout.kundenserver.de ([212.227.17.10]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XVbQB-0001Lj-6L for pgsql-jdbc@postgresql.org; Sun, 21 Sep 2014 07:19:00 +0000 Received: from ayaki.localdomain (124-148-195-121.dyn.iinet.net.au [124.148.195.121]) by mrelayeu.kundenserver.de (node=mreue105) with ESMTP (Nemesis) id 0MV56z-1XoRzP2Kwn-00YVDF; Sun, 21 Sep 2014 09:18:49 +0200 Message-ID: <541E7BD1.5090107@2ndquadrant.com> Date: Sun, 21 Sep 2014 15:18:41 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: "Lussier, Denis" , Dave Cramer CC: Enrico Olivelli - Diennea , "pgsql-jdbc@postgresql.org" Subject: Re: Disk buffering of resultsets References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:YIq2Mdta31mztHdtrgTxQv61gWj0deZtI+DxVSSzkqv XIUg7ro6kmeefp7ft24Z+TpLCV+JFkjSqv3+b4jEKrDAR0eYjm 6HPbAZGH5PWzXOmc3wE9sTdyrJl/CqCjapyKypCHv1tqwr048V S+/pnwAfkf1/FG2cRkCgwdaxsF5N05JGNdfpy1XqR7DvP7N3KD LNOU0jEvYSW4f5UUEB3NsU1pHjyFzzq2eHWYBjj4spuKmMfCpV 1GkhmaVG4qUXYPcMklHExBXczGXSCBvHcWFkW5P5ATqw2+7YT8 gK7DBzYX+iJ6WyLDfveI8nN+IyB9Fc++SOpIBcB7P2KRfVxudK 0lMj1/ro/N8LFHdjB3xO7Jlw5o61H0PVaUGDUu/mv X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -2.2 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org On 09/21/2014 11:24 AM, Lussier, Denis wrote: > This does seem very worthwhile. Can someone please sketch out a > mini-design and see if it makes sense to the pgjdbc core? I'd be > willing to hack some code, but, I'd want the design to be pre-vetted. > > Here's my first quick strawman: > > 1.) Get the TEMP directory (may be OS specific). Use Java's tempfile handling, let it use the default temporary directory, but give the user the option of overriding it with a JDBC driver parameter. Java 7, use the Path and Files classes for tempfile handling. Java 6 and below, use File.createTempFile(...). Both let you override the target directory. > 2.) After reading more than 100 rows, determine the average size per row > and check the available JVM memory. I'm not sure you can portably check available JVM memory. I'd prefer to see if we can use an existing, mature library that transparently serializes resultsets to disk under memory pressure. Possibly including use of soft references to load results from the on-disk store and let them be discarded by the JVM under pressure. Rather than reinventing the wheel, lets see what already exists in this problem space. > 3.) Flush the rows to disk once more than 65% of JVM memory is exhausted > OR according to a parameter that can be set. I'd rather have low-cost spill to disk that we can use earlier and more aggressively when we're reading whole tuple sets at once, rather than use up lots of JVM memory and possibly unnecessarily evict soft reference based caches from applications. On Linux, if it wasn't Java code I'd want to just create an mmap()ed file and start writing to it for result sets of almost any size. Let the OS deal with whether to actually flush it to disk or not. I'm not sure if that's practical from Java though, and IIRC Windows has more aggressive writing of memory mapped files that could cause performance issues. -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc