From: | Alban Hertroys <haramrae(at)gmail(dot)com> |
---|---|
To: | Steven Grimm <sgrimm(at)thesegovia(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Inconsistent performance with LIKE and bind variable on long-lived connection |
Date: | 2017-06-10 08:46:35 |
Message-ID: | 65641F01-5BC1-4EDF-AA1F-69796D6EFC83@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> On 10 Jun 2017, at 5:37, Steven Grimm <sgrimm(at)thesegovia(dot)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 Java 5 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Nikander | 2017-06-10 10:26:26 | Deadlock with single update statement? |
Previous Message | Ken Tanzer | 2017-06-10 04:14:15 | Re: Limiting DB access by role after initial connection? |