Re: [GENERAL] Inconsistent performance with LIKE and bind variable onlong-lived connection - Mailing list pgsql-general

From Alban Hertroys
Subject Re: [GENERAL] Inconsistent performance with LIKE and bind variable onlong-lived connection
Date
Msg-id 65641F01-5BC1-4EDF-AA1F-69796D6EFC83@gmail.com
Whole thread Raw
In response to [GENERAL] Inconsistent performance with LIKE and bind variable on long-lived connection  (Steven Grimm <sgrimm@thesegovia.com>)
Responses Re: [GENERAL] Inconsistent performance with LIKE and bind variable onlong-lived connection
List pgsql-general
> On 10 Jun 2017, at 5:37, Steven Grimm <sgrimm@thesegovia.com> wrote:

[…]

I notice that you're declaring your ResultSet variable inside the loop, which means that you create and destroy it
frequently.I've been told that this is a pattern that the GC has trouble keeping up with (although that was around the
Java5 era), so you might be seeing the effects of memory churn in your client instead of in the database. 

I modified your function to not do that anymore, does that make a difference?

Note; the long variables are scalar instead of objects. I don't think they need the same treatment, but it can't hurt.

>   private static void logTime(String name, PreparedStatement stmt) throws SQLException {
>     StringBuilder out = new StringBuilder(String.format("%-22s", name));
>     ResultSet rs;
>     long startTime, endTime;
>
>     for (int i = 0; i<  20; i++) {
>       startTime = System.currentTimeMillis();
>       rs = stmt.executeQuery();
>       while (rs.next()) {
>         rs.getString(1);
>       }
>       endTime = System.currentTimeMillis();
>       rs.close();
>
>       out.append(String.format(" %3d", endTime - startTime));
>     }
>
>     stmt.close();
>
>     System.out.println(out);
>   }



Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



pgsql-general by date:

Previous
From: Ken Tanzer
Date:
Subject: Re: [GENERAL] Limiting DB access by role after initial connection?
Next
From: Rob Nikander
Date:
Subject: [GENERAL] Deadlock with single update statement?