Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xou3g-0006VL-MA for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Nov 2014 13:03:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xou3g-0006qj-1w for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Nov 2014 13:03:32 +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 1Xou3e-0006qc-SY for pgsql-jdbc@postgresql.org; Thu, 13 Nov 2014 13:03:31 +0000 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xou3X-00005S-Fi for pgsql-jdbc@postgresql.org; Thu, 13 Nov 2014 13:03:28 +0000 Received: by mail-wi0-f179.google.com with SMTP id ex7so898430wid.12 for ; Thu, 13 Nov 2014 05:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=b5xQtqtQaRJmjcAwqmyfEUU/nLLsI8vOC34PNIlfcCA=; b=wVedQr3qo84C5HJsZ9Z23xmR3+83zKM1TQ2l3AU71Kt3FVSXrTyA/23RaT02RQKZlT 1mIflH32Ky9GXQXhyJQa7MC6CZIqQSQAcIiA5v35FWvup+Z9uXrCA0Qq/AMzbn6WXxqA l2qdbAKYUhfVa+cGBbbGrLh3idt1KcCTtrAxvMLGQez+FCs2j49CDtMWEFqClp3AbavW 1sODpPK4Gt4kSHf/ero3vW/21utXZZyGvCce1826tttTzSIAstVf2+FPvxrWTHU7dlgA 1Lw4hDPEKsqR9r6ba7RBmM+tH/eUJflWzZGD9OtPHTiKk3E/d5VJRYvdQhC2fy3RDt/t ja/g== X-Received: by 10.180.107.1 with SMTP id gy1mr3738308wib.8.1415883799652; Thu, 13 Nov 2014 05:03:19 -0800 (PST) Received: from [172.31.254.245] ([85.183.84.148]) by mx.google.com with ESMTPSA id w4sm6367495wjw.39.2014.11.13.05.03.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Nov 2014 05:03:19 -0800 (PST) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: New significance of holdable result sets in Java 8 From: Marko Topolnik In-Reply-To: Date: Thu, 13 Nov 2014 14:02:54 +0100 Cc: Kevin Wooten , List Content-Transfer-Encoding: quoted-printable Message-Id: <44768229-8F23-43D6-AD21-BC96380C4019@gmail.com> References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com> To: Dave Cramer X-Mailer: Apple Mail (2.1878.6) X-Pg-Spam-Score: -2.7 (--) 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 Dave, when you say this, is the hat you are wearing that of a database implemento= r or that of a system designer? A system designer may very reasonably want his system designed along the fo= llowing guidelines: 1. the database is about storage: give it plenty of that, and make it fast = (SSD); 2. the middle tier is about business logic: focus on CPU power and internet= bandwith, dimension RAM as needed to serve as many concurrent requests as = the CPU can take. -- Marko Topolnik On 12. stu. 2014., at 20:18, Dave Cramer wrote: > Marko, >=20 > While PG might take less RAM per cursor than the client side, we will ver= y quickly run out if there are N clients where N is some non-trivial number= and the cursors are large. This would potentially be catastrophic since Po= stgreSQL will spill to disk and potentially run out of disk space. >=20 > You may argue that it might not happen but I'd prefer the client crashed = than the server. >=20 > Dave >=20 > Dave Cramer >=20 > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca >=20 > On 12 November 2014 13:58, Kevin Wooten wrote: > I=92m inclined to agree with Dave, your usage of holdable cursors sounds = like an extremely burdensome (server wise) solution to a =93nice to have=94= application architecture solution. >=20 > Why not make a stream adapter that fetches results in groups using LIMIT/= OFFSET. This would work in any situation regardless of cursors, transactio= ns, etc and would *only* cost for large result sets that need to extra roun= d trips. >=20 > That being said=85 pgjdbc-ng uses real cursors when asked for them and re= spects the foldability requirement. There are limitations based on postgre= s=92s feature set but I believe what you are asking for works.=20 >=20 >> On Nov 12, 2014, at 11:51 AM, Dave Cramer wrote: >>=20 >> Marko, >>=20 >> When you say holdable cursors are you referring to a holdable cursor out= side of a transaction? It seems so because the transaction commits after le= aving the service layer ? >>=20 >> If so these are not without significant cost on the server side. >>=20 >> Dave Cramer >>=20 >> dave.cramer(at)credativ(dot)ca >> http://www.credativ.ca >>=20 >> On 12 November 2014 10:22, Marko Topolnik wro= te: >> As of the release of Java 8 and its Streams API a new door has opened fo= r many things, including an important improvement in the way RESTful servic= es can be implemented. Let me briefly describe the architecture with Spring= 's REST support: an MVC framework is used where the Controller dispatches t= he HTTP request to a Service method; the Service method contacts the databa= se and returns a Model-oriented representation of the response; the View la= yer then transforms it into the actual HTTP response bytes. >>=20 >> Data is passed from Controller to View as the return value of a method. = Traditionally, if you wanted a collection-shaped response, you would return= a List. This meant eager loading of all data needed for the response, whic= h caused scalability issues related to the JVM heap space. >>=20 >> With the Streams API it is now very convenient to return a lazily-evalua= ted stream of Model objects. It is also very convenient to make this stream= pull data directly from an underlying ResultSet, tronsforming each row on-= the-fly into a Model object. This, however, calls for holdable result sets = because the transaction commits when program control leaves the Service lay= er. >>=20 >> The Spring team has recognized the relevance of the above use case and w= ith release 4.1.2 they have introduced a specific enhancement needed to sup= port result sets holdable into the View layer (albeit only when JDBC is use= d over Hibernate). This is described in the issue SPR-12349 [1]. Spring als= o plans to support this use case with additional helper code which turns Hi= bernate's ScrollableResults into a Stream (SPR-12388 [2]). >>=20 >> The above could raise the level of interest of the PostgreSQL JDBC team = in implementing holdable result sets backed by native holdable cursors inst= ead of the current client-side cursors, which don't allow the space complex= ity to be reduced from O(n) to O(1) on the JVM side. I am aware that this i= s not a trivial endeavor as it requires intervention into the FE/BE protoco= l, but I would nevertheless propose that this concern be reassessed in the = light of new developments in the Java ecosystem. >>=20 >> Regards, >> Marko Topolnik >>=20 >>=20 >>=20 >> [1] https://jira.spring.io/browse/SPR-12349 >> [2] https://jira.spring.io/browse/SPR-12388 >>=20 >> -- >> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-jdbc >>=20 >=20 >=20 --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc