pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSevere performance degradation when using the 9.2-1000 JDBC 4 driver
25+ messages / 9 participants
[nested] [flat]
* Severe performance degradation when using the 9.2-1000 JDBC 4 driver
@ 2012-10-05 19:27 emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-05 20:12 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Thomas Kellerer <spam_eater@gmx.net>
2012-10-06 00:43 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
2012-10-06 13:29 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Dave Cramer <pg@fastcrypt.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
0 siblings, 4 replies; 25+ messages in thread
From: emergency.shower@gmail.com @ 2012-10-05 19:27 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
after the upgrade the latest PortgreSQL 9.2-1000 JDBC 4 driver, we
discovered a severe performance degradation when connecting to 8.4,
9.0, 9.1, and 9.2 servers. In a test application the
DriverManager#getConnection(String, String, String) call constantly
took > 4500 ms compared to < 20 ms with the previous 9.1-903 JDBC 4
driver. This makes the driver virtually unusable in production
environments.
Client: Windows 2008 R2, Windows 7
Server: PostgreSQL 8.4, 9.0, 9.1, 9.2 on Linux 2.6
Regards,
Alex
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
@ 2012-10-05 20:12 ` Thomas Kellerer <spam_eater@gmx.net>
3 siblings, 0 replies; 25+ messages in thread
From: Thomas Kellerer @ 2012-10-05 20:12 UTC (permalink / raw)
To: pgsql-jdbc
emergency.shower@gmail.com wrote on 05.10.2012 21:27:
> after the upgrade the latest PortgreSQL 9.2-1000 JDBC 4 driver, we
> discovered a severe performance degradation when connecting to 8.4,
> 9.0, 9.1, and 9.2 servers. In a test application the
> DriverManager#getConnection(String, String, String) call constantly
> took > 4500 ms compared to < 20 ms with the previous 9.1-903 JDBC 4
> driver. This makes the driver virtually unusable in production
> environments.
>
> Client: Windows 2008 R2, Windows 7
> Server: PostgreSQL 8.4, 9.0, 9.1, 9.2 on Linux 2.6
I cannot confirm that.
I actually have the impression that it's faster (at least using "localhost", can't test a remote server right now).
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
@ 2012-10-06 00:43 ` Kris Jurka <books@ejurka.com>
2012-10-08 07:49 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
3 siblings, 1 reply; 25+ messages in thread
From: Kris Jurka @ 2012-10-06 00:43 UTC (permalink / raw)
To: emergency.shower@gmail.com <emergency.shower@gmail.com>; +Cc: pgsql-jdbc
On Fri, 5 Oct 2012, emergency.shower@gmail.com wrote:
> after the upgrade the latest PortgreSQL 9.2-1000 JDBC 4 driver, we
> discovered a severe performance degradation when connecting to 8.4,
> 9.0, 9.1, and 9.2 servers. In a test application the
> DriverManager#getConnection(String, String, String) call constantly
> took > 4500 ms compared to < 20 ms with the previous 9.1-903 JDBC 4
> driver. This makes the driver virtually unusable in production
> environments.
Can you show us the connection URL that you are using? Are you using SSL?
It appears that some of the 9.2 changes may require a DNS lookup that they
didn't before and you might be getting a timeout there. Any DNS issues on
your side?
Kris Jurka
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-06 00:43 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
@ 2012-10-08 07:49 ` emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-08 07:54 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
0 siblings, 1 reply; 25+ messages in thread
From: emergency.shower@gmail.com @ 2012-10-08 07:49 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
Hi Kris,
On Sat, Oct 6, 2012 at 2:43 AM, Kris Jurka <books@ejurka.com> wrote:
>
> Can you show us the connection URL that you are using?
Other as stated before, only connection URLs with IPv4 Addresses were
involved in our tests.
> Are you using SSL?
No SSL.
> It appears that some of the 9.2 changes may require a DNS lookup that they
> didn't before and you might be getting a timeout there. Any DNS issues on
> your side?
Actually there are two distinct problems:
- a reverse lookup failure with a subdomain in the local network that
contains some of the test hosts, and
- a reverse lookup failure with hosts that are located in our DMZ.
The first seems to be repairable to me, for the second I don't know.
-Alex
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-06 00:43 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
2012-10-08 07:49 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
@ 2012-10-08 07:54 ` emergency.shower@gmail.com <emergency.shower@gmail.com>
0 siblings, 0 replies; 25+ messages in thread
From: emergency.shower@gmail.com @ 2012-10-08 07:54 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
The problem comes from the getHostName() call in
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(InetSocketAddress[],
String, String, Properties, Logger).
doAuthentication(newStream, address.getHostName(), user, info, logger);
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
@ 2012-10-06 13:29 ` Dave Cramer <pg@fastcrypt.com>
3 siblings, 0 replies; 25+ messages in thread
From: Dave Cramer @ 2012-10-06 13:29 UTC (permalink / raw)
To: emergency.shower@gmail.com <emergency.shower@gmail.com>; +Cc: pgsql-jdbc
It's actually pretty easy to compile in eclipse.
Load the project from source, then you have to remove all of the
concrete implementations that you don't need.
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Sat, Oct 6, 2012 at 8:23 AM, emergency.shower@gmail.com
<emergency.shower@gmail.com> wrote:
> Hi Dave,
>
>> Any chance you can run this in debug mode to find out exactly what is
>> taking so long ?
>
> I will try to dig deeper into the problem when I'm back in the office
> next week (the problem is not reproducible in my home network).
>
> Is there a chance or even a guide how to compile the driver within an
> IDE, preferably Eclipse?
>
> -Alex
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
@ 2012-10-18 04:16 ` Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
3 siblings, 1 reply; 25+ messages in thread
From: Sérgio Saquetim @ 2012-10-18 04:16 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: Rafael dos Santos Silva <xfalcox@gmail.com>
I can confirm the problem, it's taking about 4000ms to get a Connection. I did a simple Java class to test that:
/*
* JavaApplication1.java
*
* Criado em Oct 18, 2012, 12:40:56 AM
*
* Copyright(c) 2012 Sérgio Ernesto Diniz Saquetim. Todos os direitos reservados.
*/
package javaapplication1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* [Insira a descrição da classe aqui]
*
* @author Sérgio Saquetim <sergiosaquetim@gmail.com>
* @version 0.1
* @since 0.1
*/
public class JavaApplication1 {
/**
* Função de entrada de execução do programa.
*
* @param args os argumentos da linha de comando
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://192.168.1.100/frames?user=postgres&password=postgres@mac";
long time = System.currentTimeMillis();
try (Connection conn = DriverManager.getConnection(url)) {
System.out.println("Elapsed Time: "+(System.currentTimeMillis()-time));
try (PreparedStatement pst = conn.prepareStatement("SELECT version();")) {
try (ResultSet rs = pst.executeQuery()) {
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
}
}
}
}
The result using the : 9.2-1000 JDBC 4
run:
Elapsed Time: 5172
PostgreSQL 9.2.1 on x86_64-apple-darwin, compiled by i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00), 64-bit
Now using the 9.1-903 JDBC 4:
Elapsed Time: 50
PostgreSQL 9.2.1 on x86_64-apple-darwin, compiled by i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00), 64-bit
I'm getting the same results in my company what makes this Driver unusable in production. Is there any workaround? Will I get to much trouble if I use 9.1-903 JDBC 4 version driver with Postgres 9.2?
Thanks a lot!
Em sexta-feira, 5 de outubro de 2012 16h27min21s UTC-3, "emergency.shower@gmail.com" escreveu:
> Hi,
>
>
>
> after the upgrade the latest PortgreSQL 9.2-1000 JDBC 4 driver, we
>
> discovered a severe performance degradation when connecting to 8.4,
>
> 9.0, 9.1, and 9.2 servers. In a test application the
>
> DriverManager#getConnection(String, String, String) call constantly
>
> took > 4500 ms compared to < 20 ms with the previous 9.1-903 JDBC 4
>
> driver. This makes the driver virtually unusable in production
>
> environments.
>
>
>
> Client: Windows 2008 R2, Windows 7
>
> Server: PostgreSQL 8.4, 9.0, 9.1, 9.2 on Linux 2.6
>
>
>
> Regards,
>
> Alex
>
>
>
>
>
> --
>
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>
> To make changes to your subscription:
>
> http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
@ 2012-10-18 09:03 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
0 siblings, 1 reply; 25+ messages in thread
From: Craig Ringer @ 2012-10-18 09:03 UTC (permalink / raw)
To: Sérgio Saquetim <sergiosaquetim@gmail.com>; +Cc: pgsql-jdbc@postgresql.org, Rafael dos Santos Silva <xfalcox@gmail.com>
On 10/18/2012 12:16 PM, Sérgio Saquetim wrote:
> I can confirm the problem, it's taking about 4000ms to get a Connection.
That sounds like a broken DNS or reverse DNS setup in your environment,
it's about right for your average DNS timeout.
--
Craig Ringer
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
@ 2012-10-18 09:17 ` Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 09:24 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Dave Cramer <pg@fastcrypt.com>
2012-10-18 10:46 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 12:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 01:19 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
0 siblings, 4 replies; 25+ messages in thread
From: Mikko Tiihonen @ 2012-10-18 09:17 UTC (permalink / raw)
To: Craig Ringer <ringerc@ringerc.id.au>; Sérgio Saquetim <sergiosaquetim@gmail.com>; +Cc: pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
I think the DNS lookup is part of the JDBC failover connection patch that I created.
I initially used a InetSocketAddress.getHostString() that does not do any DNS lookups, but since that method was added in Java7 I had to revert to getHostName() method which does.
I see following options:
1) modify the code so that is uses reflection and if Java7 is detected it will use the no-lookup method
2) wait 4 months until Oracle drops Java6 support (Java6 was supposed to be EOL already few months back) and use the no-lookup variant
3) let the code stay as is and let users fix their dns servers
-Mikko
________________________________________
From: pgsql-jdbc-owner@postgresql.org [pgsql-jdbc-owner@postgresql.org] on behalf of Craig Ringer [ringerc@ringerc.id.au]
Sent: 18 October 2012 12:03
To: Sérgio Saquetim
Cc: pgsql-jdbc@postgresql.org; Rafael dos Santos Silva
Subject: Re: [JDBC] Severe performance degradation when using the 9.2-1000 JDBC 4 driver
On 10/18/2012 12:16 PM, Sérgio Saquetim wrote:
> I can confirm the problem, it's taking about 4000ms to get a Connection.
That sounds like a broken DNS or reverse DNS setup in your environment,
it's about right for your average DNS timeout.
--
Craig Ringer
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
@ 2012-10-18 09:24 ` Dave Cramer <pg@fastcrypt.com>
3 siblings, 0 replies; 25+ messages in thread
From: Dave Cramer @ 2012-10-18 09:24 UTC (permalink / raw)
To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; +Cc: Craig Ringer <ringerc@ringerc.id.au>; Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
On Thu, Oct 18, 2012 at 5:17 AM, Mikko Tiihonen
<Mikko.Tiihonen@nitorcreations.com> wrote:
> I think the DNS lookup is part of the JDBC failover connection patch that I created.
> I initially used a InetSocketAddress.getHostString() that does not do any DNS lookups, but since that method was added in Java7 I had to revert to getHostName() method which does.
>
> I see following options:
> 1) modify the code so that is uses reflection and if Java7 is detected it will use the no-lookup method
> 2) wait 4 months until Oracle drops Java6 support (Java6 was supposed to be EOL already few months back) and use the no-lookup variant
> 3) let the code stay as is and let users fix their dns servers
>
> -Mikko
Number 1 above is probably the best option. Even if Oracle EOL's Java6
we will still have to support it for a while. 3 is probably
indefensible.
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
@ 2012-10-18 10:46 ` Sérgio Saquetim <sergiosaquetim@gmail.com>
3 siblings, 0 replies; 25+ messages in thread
From: Sérgio Saquetim @ 2012-10-18 10:46 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: Rafael dos Santos Silva <xfalcox@gmail.com>
Mikko,
Thanks for the support, adding a DNS to the server's IP address in my hosts file solved it, but I'm curious, since I was directly using my server's IP address in the connection string, there shouldn't be any DNS requests at all. What am I missing?
About your suggestions I agree with Dave Cramer, although using Java 7 it's not a problem for me. The best solution would be number 1.
Thanks again.
Em quinta-feira, 18 de outubro de 2012 06h17min30s UTC-3, Mikko Tiihonen escreveu:
> I think the DNS lookup is part of the JDBC failover connection patch that I created.
>
> I initially used a InetSocketAddress.getHostString() that does not do any DNS lookups, but since that method was added in Java7 I had to revert to getHostName() method which does.
>
>
>
> I see following options:
>
> 1) modify the code so that is uses reflection and if Java7 is detected it will use the no-lookup method
>
> 2) wait 4 months until Oracle drops Java6 support (Java6 was supposed to be EOL already few months back) and use the no-lookup variant
>
> 3) let the code stay as is and let users fix their dns servers
>
>
>
> -Mikko
>
> ________________________________________
>
> From: pgsql-jdbc-owner@postgresql.org [pgsql-jdbc-owner@postgresql.org] on behalf of Craig Ringer [ringerc@ringerc.id.au]
>
> Sent: 18 October 2012 12:03
>
> To: S�rgio Saquetim
>
> Cc: pgsql-jdbc@postgresql.org; Rafael dos Santos Silva
>
> Subject: Re: [JDBC] Severe performance degradation when using the 9.2-1000 JDBC 4 driver
>
>
>
> On 10/18/2012 12:16 PM, S�rgio Saquetim wrote:
>
> > I can confirm the problem, it's taking about 4000ms to get a Connection.
>
>
>
> That sounds like a broken DNS or reverse DNS setup in your environment,
>
> it's about right for your average DNS timeout.
>
>
>
> --
>
> Craig Ringer
>
>
>
>
>
> --
>
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>
> To make changes to your subscription:
>
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
>
>
>
> --
>
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>
> To make changes to your subscription:
>
> http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
@ 2012-10-18 12:18 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 12:43 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Dave Cramer <pg@fastcrypt.com>
2012-10-18 13:10 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
3 siblings, 2 replies; 25+ messages in thread
From: Craig Ringer @ 2012-10-18 12:18 UTC (permalink / raw)
To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; +Cc: Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
On 10/18/2012 05:17 PM, Mikko Tiihonen wrote:
> I think the DNS lookup is part of the JDBC failover connection patch that I created.
> I initially used a InetSocketAddress.getHostString() that does not do any DNS lookups, but since that method was added in Java7 I had to revert to getHostName() method which does.
>
> I see following options:
0) Revert the JDBC failover patch or require a connection parameter to
enable it
> 1) modify the code so that is uses reflection and if Java7 is detected it will use the no-lookup method
Gah! no! Not only will this not work in most SecurityManager contexts,
but it's slow and horrid.
> 2) wait 4 months until Oracle drops Java6 support (Java6 was supposed to be EOL already few months back) and use the no-lookup variant
... then another two years or so until it's actually adopted. People
still use Java 1.4, and 1.5 remains very wide-spread. Sadly.
> 3) let the code stay as is and let users fix their dns servers
While sometimes reasonable, in this case it's also a performance
regression for functionality most will never need, so -1 to that.
--
Craig Ringer
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 12:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
@ 2012-10-18 12:43 ` Dave Cramer <pg@fastcrypt.com>
2012-10-18 12:48 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 01:15 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
1 sibling, 2 replies; 25+ messages in thread
From: Dave Cramer @ 2012-10-18 12:43 UTC (permalink / raw)
To: Craig Ringer <ringerc@ringerc.id.au>; +Cc: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
On Thu, Oct 18, 2012 at 8:18 AM, Craig Ringer <ringerc@ringerc.id.au> wrote:
> On 10/18/2012 05:17 PM, Mikko Tiihonen wrote:
>>
>> I think the DNS lookup is part of the JDBC failover connection patch that
>> I created.
>> I initially used a InetSocketAddress.getHostString() that does not do any
>> DNS lookups, but since that method was added in Java7 I had to revert to
>> getHostName() method which does.
>>
>> I see following options:
>
>
> 0) Revert the JDBC failover patch or require a connection parameter to
> enable it
>
>
>> 1) modify the code so that is uses reflection and if Java7 is detected it
>> will use the no-lookup method
>
>
> Gah! no! Not only will this not work in most SecurityManager contexts, but
> it's slow and horrid.
Surely there must be a way to detect that you are on Java7 without reflection ?
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 12:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 12:43 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Dave Cramer <pg@fastcrypt.com>
@ 2012-10-18 12:48 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-22 22:06 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
1 sibling, 1 reply; 25+ messages in thread
From: Craig Ringer @ 2012-10-18 12:48 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
On 10/18/2012 08:43 PM, Dave Cramer wrote:
> On Thu, Oct 18, 2012 at 8:18 AM, Craig Ringer <ringerc@ringerc.id.au> wrote:
>> On 10/18/2012 05:17 PM, Mikko Tiihonen wrote:
>>>
>>> I think the DNS lookup is part of the JDBC failover connection patch that
>>> I created.
>>> I initially used a InetSocketAddress.getHostString() that does not do any
>>> DNS lookups, but since that method was added in Java7 I had to revert to
>>> getHostName() method which does.
>>>
>>> I see following options:
>>
>>
>> 0) Revert the JDBC failover patch or require a connection parameter to
>> enable it
>>
>>
>>> 1) modify the code so that is uses reflection and if Java7 is detected it
>>> will use the no-lookup method
>>
>>
>> Gah! no! Not only will this not work in most SecurityManager contexts, but
>> it's slow and horrid.
>
> Surely there must be a way to detect that you are on Java7 without reflection ?
Detect, trivially, but if code that refers to a method that doesn't
exist in Java 7 is loaded it'll cause a link error from memory - so you
can't actually get to the point where you test the condition when
running in Java 6.
I'll write a toy test class to confirm that and check back.
--
Craig Ringer
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 12:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 12:43 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Dave Cramer <pg@fastcrypt.com>
2012-10-18 12:48 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
@ 2012-10-22 22:06 ` Craig Ringer <ringerc@ringerc.id.au>
0 siblings, 0 replies; 25+ messages in thread
From: Craig Ringer @ 2012-10-22 22:06 UTC (permalink / raw)
To: Віталій Тимчишин <tivv00@gmail.com>; pgsql-jdbc
On 10/23/2012 02:41 AM, Віталій Тимчишин wrote:
> AFAIR class is not loaded until after it is accessed (very same line),
> so something like this should work:
> if (isJava7()) {
> return new Java7Resolver();
> } else {
> return new Java6Resolver();
> }
Good point - that should work just fine.
--
Craig Ringer
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 12:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 12:43 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Dave Cramer <pg@fastcrypt.com>
@ 2012-10-19 01:15 ` Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
1 sibling, 0 replies; 25+ messages in thread
From: Tsunakawa, Takayuki @ 2012-10-19 01:15 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; Craig Ringer <ringerc@ringerc.id.au>; +Cc: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
> From: pgsql-jdbc-owner@postgresql.org
> On Thu, Oct 18, 2012 at 8:18 AM, Craig Ringer <ringerc@ringerc.id.au> wrote:
> > On 10/18/2012 05:17 PM, Mikko Tiihonen wrote:
> >>
> >> I think the DNS lookup is part of the JDBC failover connection patch
> >> that I created.
> >> I initially used a InetSocketAddress.getHostString() that does not do
> >> any DNS lookups, but since that method was added in Java7 I had to
> >> revert to
> >> getHostName() method which does.
> >>
> >> I see following options:
> >
> >
> > 0) Revert the JDBC failover patch or require a connection parameter to
> > enable it
> >
> >
> >> 1) modify the code so that is uses reflection and if Java7 is
> >> detected it will use the no-lookup method
> >
> >
> > Gah! no! Not only will this not work in most SecurityManager contexts,
> > but it's slow and horrid.
>
> Surely there must be a way to detect that you are on Java7 without reflection ?
System.getProperty("java.version") will do.
http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
+1 to choice 1.
Regards
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 12:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
@ 2012-10-18 13:10 ` emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 13:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
1 sibling, 1 reply; 25+ messages in thread
From: emergency.shower@gmail.com @ 2012-10-18 13:10 UTC (permalink / raw)
To: Craig Ringer <ringerc@ringerc.id.au>; +Cc: pgsql-jdbc
> 0) [...] require a connection parameter to enable it
+1 for this.
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 12:18 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 13:10 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
@ 2012-10-18 13:18 ` Sérgio Saquetim <sergiosaquetim@gmail.com>
0 siblings, 0 replies; 25+ messages in thread
From: Sérgio Saquetim @ 2012-10-18 13:18 UTC (permalink / raw)
To: pgsql-jdbc
I agree, +1 for require a connection parameter to enable it
Em quinta-feira, 18 de outubro de 2012 10h10min30s UTC-3, "emergency.shower@gmail.com" escreveu:
> > 0) [...] require a connection parameter to enable it
>
>
>
> +1 for this.
>
>
>
>
>
> --
>
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>
> To make changes to your subscription:
>
> http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
@ 2012-10-19 01:19 ` Kris Jurka <books@ejurka.com>
2012-10-19 06:36 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
3 siblings, 1 reply; 25+ messages in thread
From: Kris Jurka @ 2012-10-19 01:19 UTC (permalink / raw)
To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; +Cc: Craig Ringer <ringerc@ringerc.id.au>; Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
On Thu, 18 Oct 2012, Mikko Tiihonen wrote:
> I think the DNS lookup is part of the JDBC failover connection patch
> that I created. I initially used a InetSocketAddress.getHostString()
> that does not do any DNS lookups, but since that method was added in
> Java7 I had to revert to getHostName() method which does.
>
Is there any functionality that we need that is provided by using
InetSocketAddress or is it just a convenient object to pass around host
and port together? The simplest option to me seems to be reverting to
passing simple strings/ints around (possibly in some kind of our own
container).
Kris Jurka
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 01:19 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
@ 2012-10-19 06:36 ` Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 07:22 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
0 siblings, 1 reply; 25+ messages in thread
From: Mikko Tiihonen @ 2012-10-19 06:36 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: Craig Ringer <ringerc@ringerc.id.au>; Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
> > I think the DNS lookup is part of the JDBC failover connection patch
> > that I created. I initially used a InetSocketAddress.getHostString()
> > that does not do any DNS lookups, but since that method was added in
> > Java7 I had to revert to getHostName() method which does.
> >
>
> Is there any functionality that we need that is provided by using
> InetSocketAddress or is it just a convenient object to pass around host
> and port together? The simplest option to me seems to be reverting to
> passing simple strings/ints around (possibly in some kind of our own
> container).
It is just a convenient container. And it seems on older JVMs it cannot be used for such purposes.
I agree that we should just replace it with our own container that contains the host/port pair.
-Mikko
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 01:19 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
2012-10-19 06:36 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
@ 2012-10-19 07:22 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 13:24 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
0 siblings, 1 reply; 25+ messages in thread
From: Craig Ringer @ 2012-10-19 07:22 UTC (permalink / raw)
To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; +Cc: Kris Jurka <books@ejurka.com>; Sérgio Saquetim <sergiosaquetim@gmail.com>; pgsql-jdbc; Rafael dos Santos Silva <xfalcox@gmail.com>
On 10/19/2012 02:36 PM, Mikko Tiihonen wrote:
>>> I think the DNS lookup is part of the JDBC failover connection patch
>>> that I created. I initially used a InetSocketAddress.getHostString()
>>> that does not do any DNS lookups, but since that method was added in
>>> Java7 I had to revert to getHostName() method which does.
>>>
>>
>> Is there any functionality that we need that is provided by using
>> InetSocketAddress or is it just a convenient object to pass around host
>> and port together? The simplest option to me seems to be reverting to
>> passing simple strings/ints around (possibly in some kind of our own
>> container).
>
> It is just a convenient container. And it seems on older JVMs it cannot be used for such purposes.
> I agree that we should just replace it with our own container that contains the host/port pair.
If that's all you're using it for, then that's the simplest and best
choice. +1 from me on that.
--
Craig Ringer
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 01:19 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
2012-10-19 06:36 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 07:22 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
@ 2012-10-19 13:24 ` Scott Harrington <scotth01@sns-usa.com>
2012-10-23 02:56 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
0 siblings, 1 reply; 25+ messages in thread
From: Scott Harrington @ 2012-10-19 13:24 UTC (permalink / raw)
To: pgsql-jdbc
On Fri, 19 Oct 2012, Craig Ringer wrote:
> On 10/19/2012 02:36 PM, Mikko Tiihonen wrote:
>>>> I think the DNS lookup is part of the JDBC failover connection patch
>>>> that I created. I initially used a InetSocketAddress.getHostString()
>>>> that does not do any DNS lookups, but since that method was added in
>>>> Java7 I had to revert to getHostName() method which does.
>>>>
>>>
>>> Is there any functionality that we need that is provided by using
>>> InetSocketAddress or is it just a convenient object to pass around host
>>> and port together? The simplest option to me seems to be reverting to
>>> passing simple strings/ints around (possibly in some kind of our own
>>> container).
>>
>> It is just a convenient container. And it seems on older JVMs it cannot be
>> used for such purposes.
>> I agree that we should just replace it with our own container that contains
>> the host/port pair.
>
> If that's all you're using it for, then that's the simplest and best choice.
> +1 from me on that.
Could the new container contain the localAddress (null for "any") as well
as the target host and port? I'm using a simple patch that allows binding
my JDBC connections to specific localAddress (unit tests & docs still
to-do), and I can envision scenarios where a client with multiple NICs
might need to initiate connections to failover hostA from localAddress X
and to failover hostB from localAddress Y, in environments where iptables
SNAT may not be an option.
By creating an appropriate factory class for this laddr/caddr/cport
container we could select the best implementation (Java7-only or
pre-Java7) in a static initializer and avoid having to resort to
reflection to avoid the unwanted DNS calls as discussed earlier in this
thread. Want me to take a stab at this this weekend? I'm not git-skilled
yet so I'll just have to email a patch.
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 01:19 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
2012-10-19 06:36 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 07:22 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 13:24 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
@ 2012-10-23 02:56 ` Scott Harrington <scotth01@sns-usa.com>
2012-10-23 03:55 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 25+ messages in thread
From: Scott Harrington @ 2012-10-23 02:56 UTC (permalink / raw)
To: pgsql-jdbc
On Fri, 19 Oct 2012, Scott Harrington wrote:
> On Fri, 19 Oct 2012, Craig Ringer wrote:
>
>> On 10/19/2012 02:36 PM, Mikko Tiihonen wrote:
>>>>> I think the DNS lookup is part of the JDBC failover connection patch
>>>>> that I created. I initially used a InetSocketAddress.getHostString()
>>>>> that does not do any DNS lookups, but since that method was added in
>>>>> Java7 I had to revert to getHostName() method which does.
>>>>>
>>>>
>>>> Is there any functionality that we need that is provided by using
>>>> InetSocketAddress or is it just a convenient object to pass around host
>>>> and port together? The simplest option to me seems to be reverting to
>>>> passing simple strings/ints around (possibly in some kind of our own
>>>> container).
>>>
>>> It is just a convenient container. And it seems on older JVMs it cannot be
>>> used for such purposes.
>>> I agree that we should just replace it with our own container that
>>> contains the host/port pair.
>>
>> If that's all you're using it for, then that's the simplest and best
>> choice. +1 from me on that.
>
> Could the new container contain the localAddress (null for "any") as well as
> the target host and port? I'm using a simple patch that allows binding my
> JDBC connections to specific localAddress (unit tests & docs still to-do),
> and I can envision scenarios where a client with multiple NICs might need to
> initiate connections to failover hostA from localAddress X and to failover
> hostB from localAddress Y, in environments where iptables SNAT may not be an
> option.
>
> By creating an appropriate factory class for this laddr/caddr/cport container
> we could select the best implementation (Java7-only or pre-Java7) in a static
> initializer and avoid having to resort to reflection to avoid the unwanted
> DNS calls as discussed earlier in this thread. Want me to take a stab at this
> this weekend? I'm not git-skilled yet so I'll just have to email a patch.
Hi everyone, please look over this patch.
By introducing a simple org.postgresql.util.HostSpec to contain the
orignal caller-provided host and port, we never even need to call
InetSocketAddress.getHostName() or getHostString().
If this is accepted, then I will resubmit the localAddress patch based on
this; will be quite simple to put localAddress in HostSpec and then it's
available where needed at the time of Socket.connect in PGStream without
having to touch a dozen other constructor signatures to get it there.
Attachments:
HostSpec.patch (application/octet-stream, 27.3K) download
Index: org/postgresql/jdbc3g/Jdbc3gConnection.java
===================================================================
--- org/postgresql/jdbc3g/Jdbc3gConnection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/jdbc3g/Jdbc3gConnection.java (revision )
@@ -7,11 +7,12 @@
*/
package org.postgresql.jdbc3g;
-import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
+
/**
* This class implements the java.sql.Connection interface for JDBC3.
* However most of the implementation is really done in
@@ -19,8 +20,8 @@
*/
public class Jdbc3gConnection extends org.postgresql.jdbc3g.AbstractJdbc3gConnection implements java.sql.Connection
{
- public Jdbc3gConnection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public Jdbc3gConnection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
}
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Index: org/postgresql/jdbc4/Jdbc4Connection.java
===================================================================
--- org/postgresql/jdbc4/Jdbc4Connection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/jdbc4/Jdbc4Connection.java (revision )
@@ -7,11 +7,12 @@
*/
package org.postgresql.jdbc4;
-import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
+
/**
* This class implements the java.sql.Connection interface for JDBC4.
* However most of the implementation is really done in
@@ -19,8 +20,8 @@
*/
public class Jdbc4Connection extends AbstractJdbc4Connection implements java.sql.Connection
{
- public Jdbc4Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public Jdbc4Connection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
}
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Index: org/postgresql/jdbc3/AbstractJdbc3Connection.java
===================================================================
--- org/postgresql/jdbc3/AbstractJdbc3Connection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/jdbc3/AbstractJdbc3Connection.java (revision )
@@ -7,10 +7,10 @@
*/
package org.postgresql.jdbc3;
-import java.net.InetSocketAddress;
import java.util.Properties;
import java.sql.*;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
import org.postgresql.util.GT;
@@ -25,8 +25,8 @@
private int rsHoldability = ResultSet.CLOSE_CURSORS_AT_COMMIT;
private int savepointId = 0;
- protected AbstractJdbc3Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ protected AbstractJdbc3Connection(HostSpec[] hostSpec, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpec, user, database, info, url);
}
/**
Index: org/postgresql/core/v2/ProtocolConnectionImpl.java
===================================================================
--- org/postgresql/core/v2/ProtocolConnectionImpl.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/core/v2/ProtocolConnectionImpl.java (revision )
@@ -11,12 +11,12 @@
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Set;
import org.postgresql.PGNotification;
import org.postgresql.core.*;
+import org.postgresql.util.HostSpec;
/**
* V2 implementation of ProtocolConnection.
@@ -32,8 +32,8 @@
this.executor = new QueryExecutorImpl(this, pgStream, logger);
}
- public InetSocketAddress getAddress() {
- return pgStream.getAddress();
+ public HostSpec getHostSpec() {
+ return pgStream.getHostSpec();
}
public String getUser() {
@@ -87,7 +87,7 @@
if (logger.logDebug())
logger.debug(" FE=> CancelRequest(pid=" + cancelPid + ",ckey=" + cancelKey + ")");
- cancelStream = new PGStream(pgStream.getAddress());
+ cancelStream = new PGStream(pgStream.getHostSpec());
cancelStream.SendInteger4(16);
cancelStream.SendInteger2(1234);
cancelStream.SendInteger2(5678);
Index: org/postgresql/jdbc3/Jdbc3Connection.java
===================================================================
--- org/postgresql/jdbc3/Jdbc3Connection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/jdbc3/Jdbc3Connection.java (revision )
@@ -7,11 +7,12 @@
*/
package org.postgresql.jdbc3;
-import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
+
/**
* This class implements the java.sql.Connection interface for JDBC3.
* However most of the implementation is really done in
@@ -19,8 +20,8 @@
*/
public class Jdbc3Connection extends org.postgresql.jdbc3.AbstractJdbc3Connection implements java.sql.Connection
{
- public Jdbc3Connection(InetSocketAddress[] address,, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public Jdbc3Connection(HostSpec[] hostSpecs,, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
}
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
Index: org/postgresql/core/v3/ConnectionFactoryImpl.java
===================================================================
--- org/postgresql/core/v3/ConnectionFactoryImpl.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/core/v3/ConnectionFactoryImpl.java (revision )
@@ -14,7 +14,6 @@
import java.sql.SQLException;
import java.io.IOException;
import java.net.ConnectException;
-import java.net.InetSocketAddress;
import org.postgresql.core.*;
import org.postgresql.util.PSQLException;
@@ -24,6 +23,7 @@
import org.postgresql.util.UnixCrypt;
import org.postgresql.util.MD5Digest;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
/**
* ConnectionFactory implementation for version 3 (7.4+) connections.
@@ -46,7 +46,7 @@
private static class UnsupportedProtocolException extends IOException {
}
- public ProtocolConnection openConnectionImpl(InetSocketAddress[] addresses, String user, String database, Properties info, Logger logger) throws SQLException {
+ public ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException {
// Extract interesting values from the info properties:
// - the SSL setting
boolean requireSSL;
@@ -85,11 +85,11 @@
//
// Change by Chris Smith <cdsmith@twu.net>
- for (int addr = 0; addr < addresses.length; ++addr) {
- InetSocketAddress address = addresses[addr];
+ for (int whichHost = 0; whichHost < hostSpecs.length; ++whichHost) {
+ HostSpec hostSpec = hostSpecs[whichHost];
if (logger.logDebug())
- logger.debug("Trying to establish a protocol version 3 connection to " + address);
+ logger.debug("Trying to establish a protocol version 3 connection to " + hostSpec);
//
// Establish a connection.
@@ -98,7 +98,7 @@
PGStream newStream = null;
try
{
- newStream = new PGStream(address);
+ newStream = new PGStream(hostSpec);
// Construct and send an ssl startup packet if requested.
if (trySSL)
@@ -170,7 +170,7 @@
sendStartupPacket(newStream, params, logger);
// Do authentication (until AuthenticationOk).
- doAuthentication(newStream, address.getHostName(), user, info, logger);
+ doAuthentication(newStream, hostSpec.getHost(), user, info, logger);
// Do final startup.
ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, info, logger);
@@ -200,7 +200,7 @@
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -218,7 +218,7 @@
{
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -236,7 +236,7 @@
{
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -296,7 +296,7 @@
// We have to reconnect to continue.
pgStream.close();
- return new PGStream(pgStream.getAddress());
+ return new PGStream(pgStream.getHostSpec());
case 'N':
if (logger.logDebug())
Index: org/postgresql/core/ConnectionFactory.java
===================================================================
--- org/postgresql/core/ConnectionFactory.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/core/ConnectionFactory.java (revision )
@@ -8,10 +8,10 @@
*/
package org.postgresql.core;
-import java.net.InetSocketAddress;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLException;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLState;
@@ -42,8 +42,7 @@
*<p>
* Currently, protocol versions 3 (7.4+) and 2 (pre-7.4) are supported.
*
- * @param host the host to connect to
- * @param port the port to connect to
+ * @param hostSpecs at least one host and port to connect to; multiple elements for round-robin failover
* @param user the username to authenticate with; may not be null.
* @param database the database on the server to connect to; may not be null.
* @param info extra properties controlling the connection;
@@ -52,7 +51,7 @@
* @return the new, initialized, connection
* @throws SQLException if the connection could not be established.
*/
- public static ProtocolConnection openConnection(InetSocketAddress[] address, String user, String database, Properties info, Logger logger) throws SQLException {
+ public static ProtocolConnection openConnection(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException {
String protoName = info.getProperty("protocolVersion");
for (int i = 0; i < versions.length; ++i)
@@ -62,7 +61,7 @@
continue;
ConnectionFactory factory = (ConnectionFactory) versions[i][1];
- ProtocolConnection connection = factory.openConnectionImpl(address, user, database, info, logger);
+ ProtocolConnection connection = factory.openConnectionImpl(hostSpecs, user, database, info, logger);
if (connection != null)
return connection;
}
@@ -75,8 +74,7 @@
* Implementation of {@link #openConnection} for a particular protocol version.
* Implemented by subclasses of {@link ConnectionFactory}.
*
- * @param host the host to connect to
- * @param port the port to connect to
+ * @param hostSpecs at least one host and port to connect to; multiple elements for round-robin failover
* @param user the username to authenticate with; may not be null.
* @param database the database on the server to connect to; may not be null.
* @param info extra properties controlling the connection;
@@ -87,5 +85,5 @@
* @throws SQLException if the connection could not be established for a reason other
* than protocol version incompatibility.
*/
- public abstract ProtocolConnection openConnectionImpl(InetSocketAddress[] address, String user, String database, Properties info, Logger logger) throws SQLException;
+ public abstract ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException;
}
Index: org/postgresql/core/PGStream.java
===================================================================
--- org/postgresql/core/PGStream.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/core/PGStream.java (revision )
@@ -19,6 +19,7 @@
import java.sql.SQLException;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLException;
@@ -31,7 +32,7 @@
*/
public class PGStream
{
- private final InetSocketAddress address;
+ private final HostSpec hostSpec;
private final byte[] _int4buf;
private final byte[] _int2buf;
@@ -48,16 +49,15 @@
* Constructor: Connect to the PostgreSQL back end and return
* a stream connection.
*
- * @param host the hostname to connect to
- * @param port the port number that the postmaster is sitting on
+ * @param hostSpec the host and port to connect to
* @exception IOException if an IOException occurs below it.
*/
- public PGStream(InetSocketAddress address) throws IOException
+ public PGStream(HostSpec hostSpec) throws IOException
{
- this.address = address;
+ this.hostSpec = hostSpec;
Socket socket = new Socket();
- socket.connect(address);
+ socket.connect(new InetSocketAddress(hostSpec.getHost(), hostSpec.getPort()));
changeSocket(socket);
setEncoding(Encoding.getJVMEncoding("US-ASCII"));
@@ -65,8 +65,8 @@
_int4buf = new byte[4];
}
- public InetSocketAddress getAddress() {
- return address;
+ public HostSpec getHostSpec() {
+ return hostSpec;
}
public Socket getSocket() {
Index: org/postgresql/jdbc3g/AbstractJdbc3gConnection.java
===================================================================
--- org/postgresql/jdbc3g/AbstractJdbc3gConnection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/jdbc3g/AbstractJdbc3gConnection.java (revision )
@@ -7,18 +7,18 @@
*/
package org.postgresql.jdbc3g;
-import java.net.InetSocketAddress;
import java.sql.SQLException;
import java.util.Properties;
import org.postgresql.core.Oid;
import org.postgresql.core.TypeInfo;
+import org.postgresql.util.HostSpec;
public abstract class AbstractJdbc3gConnection extends org.postgresql.jdbc3.AbstractJdbc3Connection
{
- public AbstractJdbc3gConnection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public AbstractJdbc3gConnection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
TypeInfo types = getTypeInfo();
if (haveMinimumServerVersion("8.3")) {
Index: org/postgresql/core/v3/ProtocolConnectionImpl.java
===================================================================
--- org/postgresql/core/v3/ProtocolConnectionImpl.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/core/v3/ProtocolConnectionImpl.java (revision )
@@ -10,11 +10,11 @@
import org.postgresql.PGNotification;
import org.postgresql.core.*;
+import org.postgresql.util.HostSpec;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
@@ -37,8 +37,8 @@
this.standardConformingStrings = false;
}
- public InetSocketAddress getAddress() {
- return pgStream.getAddress();
+ public HostSpec getHostSpec() {
+ return pgStream.getHostSpec();
}
public String getUser() {
@@ -89,7 +89,7 @@
if (logger.logDebug())
logger.debug(" FE=> CancelRequest(pid=" + cancelPid + ",ckey=" + cancelKey + ")");
- cancelStream = new PGStream(pgStream.getAddress());
+ cancelStream = new PGStream(pgStream.getHostSpec());
cancelStream.SendInteger4(16);
cancelStream.SendInteger2(1234);
cancelStream.SendInteger2(5678);
Index: org/postgresql/jdbc4/AbstractJdbc4Connection.java
===================================================================
--- org/postgresql/jdbc4/AbstractJdbc4Connection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/jdbc4/AbstractJdbc4Connection.java (revision )
@@ -7,7 +7,6 @@
*/
package org.postgresql.jdbc4;
-import java.net.InetSocketAddress;
import java.sql.*;
import java.util.Map;
import java.util.HashMap;
@@ -19,6 +18,7 @@
import org.postgresql.core.Utils;
import org.postgresql.core.TypeInfo;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLException;
import org.postgresql.jdbc2.AbstractJdbc2Array;
@@ -27,8 +27,8 @@
{
private final Properties _clientInfo;
- public AbstractJdbc4Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public AbstractJdbc4Connection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
TypeInfo types = getTypeInfo();
if (haveMinimumServerVersion("8.3")) {
Index: org/postgresql/core/ProtocolConnection.java
===================================================================
--- org/postgresql/core/ProtocolConnection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/core/ProtocolConnection.java (revision )
@@ -9,8 +9,8 @@
package org.postgresql.core;
import org.postgresql.PGNotification;
+import org.postgresql.util.HostSpec;
-import java.net.InetSocketAddress;
import java.sql.*;
import java.util.Set;
@@ -40,9 +40,9 @@
static final int TRANSACTION_FAILED = 2;
/**
- * @return the address this connection is connected to.
+ * @return the host and port this connection is connected to.
*/
- InetSocketAddress getAddress();
+ HostSpec getHostSpec();
/**
* @return the user this connection authenticated as.
Index: org/postgresql/core/v2/ConnectionFactoryImpl.java
===================================================================
--- org/postgresql/core/v2/ConnectionFactoryImpl.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/core/v2/ConnectionFactoryImpl.java (revision )
@@ -15,7 +15,6 @@
import java.sql.SQLWarning;
import java.io.IOException;
import java.net.ConnectException;
-import java.net.InetSocketAddress;
import org.postgresql.core.*;
import org.postgresql.util.PSQLException;
@@ -23,6 +22,7 @@
import org.postgresql.util.UnixCrypt;
import org.postgresql.util.MD5Digest;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
/**
* ConnectionFactory implementation for version 2 (pre-7.4) connections.
@@ -38,7 +38,7 @@
private static final int AUTH_REQ_MD5 = 5;
private static final int AUTH_REQ_SCM = 6;
- public ProtocolConnection openConnectionImpl(InetSocketAddress[] addresses, String user, String database, Properties info, Logger logger) throws SQLException {
+ public ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException {
// Extract interesting values from the info properties:
// - the SSL setting
boolean requireSSL;
@@ -70,10 +70,10 @@
// - the TCP keep alive setting
boolean requireTCPKeepAlive = (Boolean.valueOf(info.getProperty("tcpKeepAlive")).booleanValue());
- for (int addr = 0; addr < addresses.length; ++addr) {
- InetSocketAddress address = addresses[addr];
+ for (int whichHost = 0; whichHost < hostSpecs.length; ++whichHost) {
+ HostSpec hostSpec = hostSpecs[whichHost];
if (logger.logDebug())
- logger.debug("Trying to establish a protocol version 2 connection to " + address);
+ logger.debug("Trying to establish a protocol version 2 connection to " + hostSpec);
//
// Establish a connection.
@@ -83,7 +83,7 @@
PGStream newStream = null;
try
{
- newStream = new PGStream(address);
+ newStream = new PGStream(hostSpec);
// Construct and send an ssl startup packet if requested.
if (trySSL)
@@ -127,7 +127,7 @@
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -146,7 +146,7 @@
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -165,7 +165,7 @@
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -199,7 +199,7 @@
// We have to reconnect to continue.
pgStream.close();
- return new PGStream(pgStream.getAddress());
+ return new PGStream(pgStream.getHostSpec());
case 'N':
if (logger.logDebug())
Index: org/postgresql/Driver.java.in
===================================================================
--- org/postgresql/Driver.java.in (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/Driver.java.in (revision )
@@ -10,7 +10,6 @@
import java.io.*;
import java.sql.*;
import java.util.*;
-import java.net.InetSocketAddress;
import java.net.URL;
import java.security.AccessController;
@@ -21,6 +20,7 @@
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLDriverVersion;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
import org.postgresql.core.Logger;
@@ -390,7 +390,7 @@
* @throws SQLException if the connection could not be made
*/
private static Connection makeConnection(String url, Properties props) throws SQLException {
- return new @JDBCCONNECTCLASS@(address(props),
+ return new @JDBCCONNECTCLASS@(hostSpecs(props),
user(props), database(props),
props, url);
}
@@ -647,15 +647,15 @@
/**
* @return the address portion of the URL
*/
- private static InetSocketAddress[] address(Properties props)
+ private static HostSpec[] hostSpecs(Properties props)
{
String[] hosts = props.getProperty("PGHOST").split(",");
String[] ports = props.getProperty("PGPORT").split(",");
- InetSocketAddress[] addresses = new InetSocketAddress[hosts.length];
- for (int i = 0; i < addresses.length; ++i) {
- addresses[i] = new InetSocketAddress(hosts[i], Integer.parseInt(ports[i]));
+ HostSpec[] hostSpecs = new HostSpec[hosts.length];
+ for (int i = 0; i < hostSpecs.length; ++i) {
+ hostSpecs[i] = new HostSpec(hosts[i], Integer.parseInt(ports[i]));
}
- return addresses;
+ return hostSpecs;
}
/**
Index: org/postgresql/util/HostSpec.java
===================================================================
--- org/postgresql/util/HostSpec.java (revision )
+++ org/postgresql/util/HostSpec.java (revision )
@@ -0,0 +1,34 @@
+/*-------------------------------------------------------------------------
+*
+* Copyright (c) 2004-2011, PostgreSQL Global Development Group
+*
+*
+*-------------------------------------------------------------------------
+*/
+package org.postgresql.util;
+
+/**
+ * Simple container for host and port.
+ */
+public class HostSpec {
+ protected final String host;
+ protected final int port;
+
+ public HostSpec(String host, int port)
+ {
+ this.host = host;
+ this.port = port;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public String toString() {
+ return host + ":" + port;
+ }
+}
Index: org/postgresql/jdbc2/AbstractJdbc2Connection.java
===================================================================
--- org/postgresql/jdbc2/AbstractJdbc2Connection.java (revision 5775ea549397ba3484868cd31082f9f271938b66)
+++ org/postgresql/jdbc2/AbstractJdbc2Connection.java (revision )
@@ -13,17 +13,13 @@
import java.util.*;
import org.postgresql.core.*;
-import java.net.InetSocketAddress;
import org.postgresql.Driver;
import org.postgresql.PGNotification;
import org.postgresql.fastpath.Fastpath;
import org.postgresql.largeobject.LargeObjectManager;
-import org.postgresql.util.PGBinaryObject;
-import org.postgresql.util.PSQLState;
-import org.postgresql.util.PGobject;
-import org.postgresql.util.PSQLException;
-import org.postgresql.util.GT;
+import org.postgresql.util.*;
+import org.postgresql.util.HostSpec;
import org.postgresql.copy.*;
/**
@@ -86,7 +82,7 @@
//
// Ctor.
//
- protected AbstractJdbc2Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException
+ protected AbstractJdbc2Connection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException
{
this.creatingURL = url;
@@ -137,7 +133,7 @@
logger.info(Driver.getVersion());
// Now make the initial connection and set up local state
- this.protoConnection = ConnectionFactory.openConnection(address, user, database, info, logger);
+ this.protoConnection = ConnectionFactory.openConnection(hostSpecs, user, database, info, logger);
this.dbVersionNumber = protoConnection.getServerVersion();
this.compatible = info.getProperty("compatible", Driver.MAJORVERSION + "." + Driver.MINORVERSION);
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 01:19 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
2012-10-19 06:36 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 07:22 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 13:24 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
2012-10-23 02:56 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
@ 2012-10-23 03:55 ` Kris Jurka <books@ejurka.com>
2012-10-23 15:00 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
0 siblings, 1 reply; 25+ messages in thread
From: Kris Jurka @ 2012-10-23 03:55 UTC (permalink / raw)
To: Scott Harrington <scotth01@sns-usa.com>; +Cc: pgsql-jdbc
On 10/22/2012 7:56 PM, Scott Harrington wrote:
> Hi everyone, please look over this patch.
>
> By introducing a simple org.postgresql.util.HostSpec to contain the
> orignal caller-provided host and port, we never even need to call
> InetSocketAddress.getHostName() or getHostString().
>
>
I think this is exactly what we want. Attached is a slightly modified
version that includes fixes to the MakeSSL classes.
Kris Jurka
Attachments:
HostSpec-v2.patch (text/plain, 31.9K) download
diff --git a/org/postgresql/Driver.java.in b/org/postgresql/Driver.java.in
index 76e0800..f6c69c0 100644
--- a/org/postgresql/Driver.java.in
+++ b/org/postgresql/Driver.java.in
@@ -10,7 +10,6 @@ package org.postgresql;
import java.io.*;
import java.sql.*;
import java.util.*;
-import java.net.InetSocketAddress;
import java.net.URL;
import java.security.AccessController;
@@ -21,6 +20,7 @@ import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLDriverVersion;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
import org.postgresql.core.Logger;
@@ -390,7 +390,7 @@ public class Driver implements java.sql.Driver
* @throws SQLException if the connection could not be made
*/
private static Connection makeConnection(String url, Properties props) throws SQLException {
- return new @JDBCCONNECTCLASS@(address(props),
+ return new @JDBCCONNECTCLASS@(hostSpecs(props),
user(props), database(props),
props, url);
}
@@ -647,15 +647,15 @@ public class Driver implements java.sql.Driver
/**
* @return the address portion of the URL
*/
- private static InetSocketAddress[] address(Properties props)
+ private static HostSpec[] hostSpecs(Properties props)
{
String[] hosts = props.getProperty("PGHOST").split(",");
String[] ports = props.getProperty("PGPORT").split(",");
- InetSocketAddress[] addresses = new InetSocketAddress[hosts.length];
- for (int i = 0; i < addresses.length; ++i) {
- addresses[i] = new InetSocketAddress(hosts[i], Integer.parseInt(ports[i]));
+ HostSpec[] hostSpecs = new HostSpec[hosts.length];
+ for (int i = 0; i < hostSpecs.length; ++i) {
+ hostSpecs[i] = new HostSpec(hosts[i], Integer.parseInt(ports[i]));
}
- return addresses;
+ return hostSpecs;
}
/**
diff --git a/org/postgresql/core/ConnectionFactory.java b/org/postgresql/core/ConnectionFactory.java
index 569d599..a351619 100644
--- a/org/postgresql/core/ConnectionFactory.java
+++ b/org/postgresql/core/ConnectionFactory.java
@@ -8,10 +8,10 @@
*/
package org.postgresql.core;
-import java.net.InetSocketAddress;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLException;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLState;
@@ -42,8 +42,7 @@ public abstract class ConnectionFactory {
*<p>
* Currently, protocol versions 3 (7.4+) and 2 (pre-7.4) are supported.
*
- * @param host the host to connect to
- * @param port the port to connect to
+ * @param hostSpecs at least one host and port to connect to; multiple elements for round-robin failover
* @param user the username to authenticate with; may not be null.
* @param database the database on the server to connect to; may not be null.
* @param info extra properties controlling the connection;
@@ -52,7 +51,7 @@ public abstract class ConnectionFactory {
* @return the new, initialized, connection
* @throws SQLException if the connection could not be established.
*/
- public static ProtocolConnection openConnection(InetSocketAddress[] address, String user, String database, Properties info, Logger logger) throws SQLException {
+ public static ProtocolConnection openConnection(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException {
String protoName = info.getProperty("protocolVersion");
for (int i = 0; i < versions.length; ++i)
@@ -62,7 +61,7 @@ public abstract class ConnectionFactory {
continue;
ConnectionFactory factory = (ConnectionFactory) versions[i][1];
- ProtocolConnection connection = factory.openConnectionImpl(address, user, database, info, logger);
+ ProtocolConnection connection = factory.openConnectionImpl(hostSpecs, user, database, info, logger);
if (connection != null)
return connection;
}
@@ -75,8 +74,7 @@ public abstract class ConnectionFactory {
* Implementation of {@link #openConnection} for a particular protocol version.
* Implemented by subclasses of {@link ConnectionFactory}.
*
- * @param host the host to connect to
- * @param port the port to connect to
+ * @param hostSpecs at least one host and port to connect to; multiple elements for round-robin failover
* @param user the username to authenticate with; may not be null.
* @param database the database on the server to connect to; may not be null.
* @param info extra properties controlling the connection;
@@ -87,5 +85,5 @@ public abstract class ConnectionFactory {
* @throws SQLException if the connection could not be established for a reason other
* than protocol version incompatibility.
*/
- public abstract ProtocolConnection openConnectionImpl(InetSocketAddress[] address, String user, String database, Properties info, Logger logger) throws SQLException;
+ public abstract ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException;
}
diff --git a/org/postgresql/core/PGStream.java b/org/postgresql/core/PGStream.java
index 3c75ee5..fad4c12 100644
--- a/org/postgresql/core/PGStream.java
+++ b/org/postgresql/core/PGStream.java
@@ -19,6 +19,7 @@ import java.net.Socket;
import java.sql.SQLException;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLException;
@@ -31,7 +32,7 @@ import org.postgresql.util.PSQLException;
*/
public class PGStream
{
- private final InetSocketAddress address;
+ private final HostSpec hostSpec;
private final byte[] _int4buf;
private final byte[] _int2buf;
@@ -48,16 +49,15 @@ public class PGStream
* Constructor: Connect to the PostgreSQL back end and return
* a stream connection.
*
- * @param host the hostname to connect to
- * @param port the port number that the postmaster is sitting on
+ * @param hostSpec the host and port to connect to
* @exception IOException if an IOException occurs below it.
*/
- public PGStream(InetSocketAddress address) throws IOException
+ public PGStream(HostSpec hostSpec) throws IOException
{
- this.address = address;
+ this.hostSpec = hostSpec;
Socket socket = new Socket();
- socket.connect(address);
+ socket.connect(new InetSocketAddress(hostSpec.getHost(), hostSpec.getPort()));
changeSocket(socket);
setEncoding(Encoding.getJVMEncoding("US-ASCII"));
@@ -65,8 +65,8 @@ public class PGStream
_int4buf = new byte[4];
}
- public InetSocketAddress getAddress() {
- return address;
+ public HostSpec getHostSpec() {
+ return hostSpec;
}
public Socket getSocket() {
diff --git a/org/postgresql/core/ProtocolConnection.java b/org/postgresql/core/ProtocolConnection.java
index 153c277..62c0f1b 100644
--- a/org/postgresql/core/ProtocolConnection.java
+++ b/org/postgresql/core/ProtocolConnection.java
@@ -9,8 +9,8 @@
package org.postgresql.core;
import org.postgresql.PGNotification;
+import org.postgresql.util.HostSpec;
-import java.net.InetSocketAddress;
import java.sql.*;
import java.util.Set;
@@ -40,9 +40,9 @@ public interface ProtocolConnection {
static final int TRANSACTION_FAILED = 2;
/**
- * @return the address this connection is connected to.
+ * @return the host and port this connection is connected to.
*/
- InetSocketAddress getAddress();
+ HostSpec getHostSpec();
/**
* @return the user this connection authenticated as.
diff --git a/org/postgresql/core/v2/ConnectionFactoryImpl.java b/org/postgresql/core/v2/ConnectionFactoryImpl.java
index 90523a1..a0cfc96 100644
--- a/org/postgresql/core/v2/ConnectionFactoryImpl.java
+++ b/org/postgresql/core/v2/ConnectionFactoryImpl.java
@@ -15,7 +15,6 @@ import java.sql.SQLException;
import java.sql.SQLWarning;
import java.io.IOException;
import java.net.ConnectException;
-import java.net.InetSocketAddress;
import org.postgresql.core.*;
import org.postgresql.util.PSQLException;
@@ -23,6 +22,7 @@ import org.postgresql.util.PSQLState;
import org.postgresql.util.UnixCrypt;
import org.postgresql.util.MD5Digest;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
/**
* ConnectionFactory implementation for version 2 (pre-7.4) connections.
@@ -38,7 +38,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
private static final int AUTH_REQ_MD5 = 5;
private static final int AUTH_REQ_SCM = 6;
- public ProtocolConnection openConnectionImpl(InetSocketAddress[] addresses, String user, String database, Properties info, Logger logger) throws SQLException {
+ public ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException {
// Extract interesting values from the info properties:
// - the SSL setting
boolean requireSSL;
@@ -70,10 +70,10 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
// - the TCP keep alive setting
boolean requireTCPKeepAlive = (Boolean.valueOf(info.getProperty("tcpKeepAlive")).booleanValue());
- for (int addr = 0; addr < addresses.length; ++addr) {
- InetSocketAddress address = addresses[addr];
+ for (int whichHost = 0; whichHost < hostSpecs.length; ++whichHost) {
+ HostSpec hostSpec = hostSpecs[whichHost];
if (logger.logDebug())
- logger.debug("Trying to establish a protocol version 2 connection to " + address);
+ logger.debug("Trying to establish a protocol version 2 connection to " + hostSpec);
//
// Establish a connection.
@@ -83,7 +83,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
PGStream newStream = null;
try
{
- newStream = new PGStream(address);
+ newStream = new PGStream(hostSpec);
// Construct and send an ssl startup packet if requested.
if (trySSL)
@@ -127,7 +127,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -146,7 +146,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -165,7 +165,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -199,7 +199,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
// We have to reconnect to continue.
pgStream.close();
- return new PGStream(pgStream.getAddress());
+ return new PGStream(pgStream.getHostSpec());
case 'N':
if (logger.logDebug())
diff --git a/org/postgresql/core/v2/ProtocolConnectionImpl.java b/org/postgresql/core/v2/ProtocolConnectionImpl.java
index 567ad3e..204ad9f 100644
--- a/org/postgresql/core/v2/ProtocolConnectionImpl.java
+++ b/org/postgresql/core/v2/ProtocolConnectionImpl.java
@@ -11,12 +11,12 @@ package org.postgresql.core.v2;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Set;
import org.postgresql.PGNotification;
import org.postgresql.core.*;
+import org.postgresql.util.HostSpec;
/**
* V2 implementation of ProtocolConnection.
@@ -32,8 +32,8 @@ class ProtocolConnectionImpl implements ProtocolConnection {
this.executor = new QueryExecutorImpl(this, pgStream, logger);
}
- public InetSocketAddress getAddress() {
- return pgStream.getAddress();
+ public HostSpec getHostSpec() {
+ return pgStream.getHostSpec();
}
public String getUser() {
@@ -87,7 +87,7 @@ class ProtocolConnectionImpl implements ProtocolConnection {
if (logger.logDebug())
logger.debug(" FE=> CancelRequest(pid=" + cancelPid + ",ckey=" + cancelKey + ")");
- cancelStream = new PGStream(pgStream.getAddress());
+ cancelStream = new PGStream(pgStream.getHostSpec());
cancelStream.SendInteger4(16);
cancelStream.SendInteger2(1234);
cancelStream.SendInteger2(5678);
diff --git a/org/postgresql/core/v3/ConnectionFactoryImpl.java b/org/postgresql/core/v3/ConnectionFactoryImpl.java
index d50c07d..95eaa43 100644
--- a/org/postgresql/core/v3/ConnectionFactoryImpl.java
+++ b/org/postgresql/core/v3/ConnectionFactoryImpl.java
@@ -14,7 +14,6 @@ import java.util.TimeZone;
import java.sql.SQLException;
import java.io.IOException;
import java.net.ConnectException;
-import java.net.InetSocketAddress;
import org.postgresql.core.*;
import org.postgresql.util.PSQLException;
@@ -24,6 +23,7 @@ import org.postgresql.util.ServerErrorMessage;
import org.postgresql.util.UnixCrypt;
import org.postgresql.util.MD5Digest;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
/**
* ConnectionFactory implementation for version 3 (7.4+) connections.
@@ -46,7 +46,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
private static class UnsupportedProtocolException extends IOException {
}
- public ProtocolConnection openConnectionImpl(InetSocketAddress[] addresses, String user, String database, Properties info, Logger logger) throws SQLException {
+ public ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database, Properties info, Logger logger) throws SQLException {
// Extract interesting values from the info properties:
// - the SSL setting
boolean requireSSL;
@@ -85,11 +85,11 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
//
// Change by Chris Smith <cdsmith@twu.net>
- for (int addr = 0; addr < addresses.length; ++addr) {
- InetSocketAddress address = addresses[addr];
+ for (int whichHost = 0; whichHost < hostSpecs.length; ++whichHost) {
+ HostSpec hostSpec = hostSpecs[whichHost];
if (logger.logDebug())
- logger.debug("Trying to establish a protocol version 3 connection to " + address);
+ logger.debug("Trying to establish a protocol version 3 connection to " + hostSpec);
//
// Establish a connection.
@@ -98,7 +98,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
PGStream newStream = null;
try
{
- newStream = new PGStream(address);
+ newStream = new PGStream(hostSpec);
// Construct and send an ssl startup packet if requested.
if (trySSL)
@@ -170,7 +170,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
sendStartupPacket(newStream, params, logger);
// Do authentication (until AuthenticationOk).
- doAuthentication(newStream, address.getHostName(), user, info, logger);
+ doAuthentication(newStream, hostSpec.getHost(), user, info, logger);
// Do final startup.
ProtocolConnectionImpl protoConnection = new ProtocolConnectionImpl(newStream, user, database, info, logger);
@@ -200,7 +200,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -218,7 +218,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
{
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -236,7 +236,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
{
}
}
- if (addr+1 < addresses.length) {
+ if (whichHost + 1 < hostSpecs.length) {
// still more addresses to try
continue;
}
@@ -296,7 +296,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
// We have to reconnect to continue.
pgStream.close();
- return new PGStream(pgStream.getAddress());
+ return new PGStream(pgStream.getHostSpec());
case 'N':
if (logger.logDebug())
diff --git a/org/postgresql/core/v3/ProtocolConnectionImpl.java b/org/postgresql/core/v3/ProtocolConnectionImpl.java
index 94214b4..6c40204 100644
--- a/org/postgresql/core/v3/ProtocolConnectionImpl.java
+++ b/org/postgresql/core/v3/ProtocolConnectionImpl.java
@@ -10,11 +10,11 @@ package org.postgresql.core.v3;
import org.postgresql.PGNotification;
import org.postgresql.core.*;
+import org.postgresql.util.HostSpec;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
@@ -37,8 +37,8 @@ class ProtocolConnectionImpl implements ProtocolConnection {
this.standardConformingStrings = false;
}
- public InetSocketAddress getAddress() {
- return pgStream.getAddress();
+ public HostSpec getHostSpec() {
+ return pgStream.getHostSpec();
}
public String getUser() {
@@ -89,7 +89,7 @@ class ProtocolConnectionImpl implements ProtocolConnection {
if (logger.logDebug())
logger.debug(" FE=> CancelRequest(pid=" + cancelPid + ",ckey=" + cancelKey + ")");
- cancelStream = new PGStream(pgStream.getAddress());
+ cancelStream = new PGStream(pgStream.getHostSpec());
cancelStream.SendInteger4(16);
cancelStream.SendInteger2(1234);
cancelStream.SendInteger2(5678);
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
index d5e38c1..2fb37f4 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
@@ -13,17 +13,13 @@ import java.sql.*;
import java.util.*;
import org.postgresql.core.*;
-import java.net.InetSocketAddress;
import org.postgresql.Driver;
import org.postgresql.PGNotification;
import org.postgresql.fastpath.Fastpath;
import org.postgresql.largeobject.LargeObjectManager;
-import org.postgresql.util.PGBinaryObject;
-import org.postgresql.util.PSQLState;
-import org.postgresql.util.PGobject;
-import org.postgresql.util.PSQLException;
-import org.postgresql.util.GT;
+import org.postgresql.util.*;
+import org.postgresql.util.HostSpec;
import org.postgresql.copy.*;
/**
@@ -86,7 +82,7 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
//
// Ctor.
//
- protected AbstractJdbc2Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException
+ protected AbstractJdbc2Connection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException
{
this.creatingURL = url;
@@ -137,7 +133,7 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
logger.info(Driver.getVersion());
// Now make the initial connection and set up local state
- this.protoConnection = ConnectionFactory.openConnection(address, user, database, info, logger);
+ this.protoConnection = ConnectionFactory.openConnection(hostSpecs, user, database, info, logger);
this.dbVersionNumber = protoConnection.getServerVersion();
this.compatible = info.getProperty("compatible", Driver.MAJORVERSION + "." + Driver.MINORVERSION);
diff --git a/org/postgresql/jdbc3/AbstractJdbc3Connection.java b/org/postgresql/jdbc3/AbstractJdbc3Connection.java
index da11958..c7738a0 100644
--- a/org/postgresql/jdbc3/AbstractJdbc3Connection.java
+++ b/org/postgresql/jdbc3/AbstractJdbc3Connection.java
@@ -7,10 +7,10 @@
*/
package org.postgresql.jdbc3;
-import java.net.InetSocketAddress;
import java.util.Properties;
import java.sql.*;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
import org.postgresql.util.GT;
@@ -25,8 +25,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
private int rsHoldability = ResultSet.CLOSE_CURSORS_AT_COMMIT;
private int savepointId = 0;
- protected AbstractJdbc3Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ protected AbstractJdbc3Connection(HostSpec[] hostSpec, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpec, user, database, info, url);
}
/**
diff --git a/org/postgresql/jdbc3/Jdbc3Connection.java b/org/postgresql/jdbc3/Jdbc3Connection.java
index 7be70fb..470f04c 100644
--- a/org/postgresql/jdbc3/Jdbc3Connection.java
+++ b/org/postgresql/jdbc3/Jdbc3Connection.java
@@ -7,11 +7,12 @@
*/
package org.postgresql.jdbc3;
-import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
+
/**
* This class implements the java.sql.Connection interface for JDBC3.
* However most of the implementation is really done in
@@ -19,8 +20,8 @@ import java.sql.SQLException;
*/
public class Jdbc3Connection extends org.postgresql.jdbc3.AbstractJdbc3Connection implements java.sql.Connection
{
- public Jdbc3Connection(InetSocketAddress[] address,, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public Jdbc3Connection(HostSpec[] hostSpecs,, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
}
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
diff --git a/org/postgresql/jdbc3g/AbstractJdbc3gConnection.java b/org/postgresql/jdbc3g/AbstractJdbc3gConnection.java
index 61e58b6..1b42c33 100644
--- a/org/postgresql/jdbc3g/AbstractJdbc3gConnection.java
+++ b/org/postgresql/jdbc3g/AbstractJdbc3gConnection.java
@@ -7,18 +7,18 @@
*/
package org.postgresql.jdbc3g;
-import java.net.InetSocketAddress;
import java.sql.SQLException;
import java.util.Properties;
import org.postgresql.core.Oid;
import org.postgresql.core.TypeInfo;
+import org.postgresql.util.HostSpec;
public abstract class AbstractJdbc3gConnection extends org.postgresql.jdbc3.AbstractJdbc3Connection
{
- public AbstractJdbc3gConnection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public AbstractJdbc3gConnection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
TypeInfo types = getTypeInfo();
if (haveMinimumServerVersion("8.3")) {
diff --git a/org/postgresql/jdbc3g/Jdbc3gConnection.java b/org/postgresql/jdbc3g/Jdbc3gConnection.java
index 4ff2dbc..b8dfe00 100644
--- a/org/postgresql/jdbc3g/Jdbc3gConnection.java
+++ b/org/postgresql/jdbc3g/Jdbc3gConnection.java
@@ -7,11 +7,12 @@
*/
package org.postgresql.jdbc3g;
-import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
+
/**
* This class implements the java.sql.Connection interface for JDBC3.
* However most of the implementation is really done in
@@ -19,8 +20,8 @@ import java.sql.SQLException;
*/
public class Jdbc3gConnection extends org.postgresql.jdbc3g.AbstractJdbc3gConnection implements java.sql.Connection
{
- public Jdbc3gConnection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public Jdbc3gConnection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
}
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
diff --git a/org/postgresql/jdbc4/AbstractJdbc4Connection.java b/org/postgresql/jdbc4/AbstractJdbc4Connection.java
index 444a582..8a89a80 100644
--- a/org/postgresql/jdbc4/AbstractJdbc4Connection.java
+++ b/org/postgresql/jdbc4/AbstractJdbc4Connection.java
@@ -7,7 +7,6 @@
*/
package org.postgresql.jdbc4;
-import java.net.InetSocketAddress;
import java.sql.*;
import java.util.Map;
import java.util.HashMap;
@@ -19,6 +18,7 @@ import org.postgresql.core.Oid;
import org.postgresql.core.Utils;
import org.postgresql.core.TypeInfo;
import org.postgresql.util.GT;
+import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLException;
import org.postgresql.jdbc2.AbstractJdbc2Array;
@@ -27,8 +27,8 @@ abstract class AbstractJdbc4Connection extends org.postgresql.jdbc3g.AbstractJdb
{
private final Properties _clientInfo;
- public AbstractJdbc4Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public AbstractJdbc4Connection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
TypeInfo types = getTypeInfo();
if (haveMinimumServerVersion("8.3")) {
diff --git a/org/postgresql/jdbc4/Jdbc4Connection.java b/org/postgresql/jdbc4/Jdbc4Connection.java
index 06fd289..209b970 100644
--- a/org/postgresql/jdbc4/Jdbc4Connection.java
+++ b/org/postgresql/jdbc4/Jdbc4Connection.java
@@ -7,11 +7,12 @@
*/
package org.postgresql.jdbc4;
-import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;
import java.sql.SQLException;
+import org.postgresql.util.HostSpec;
+
/**
* This class implements the java.sql.Connection interface for JDBC4.
* However most of the implementation is really done in
@@ -19,8 +20,8 @@ import java.sql.SQLException;
*/
public class Jdbc4Connection extends AbstractJdbc4Connection implements java.sql.Connection
{
- public Jdbc4Connection(InetSocketAddress[] address, String user, String database, Properties info, String url) throws SQLException {
- super(address, user, database, info, url);
+ public Jdbc4Connection(HostSpec[] hostSpecs, String user, String database, Properties info, String url) throws SQLException {
+ super(hostSpecs, user, database, info, url);
}
public java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
diff --git a/org/postgresql/ssl/jdbc3/AbstractJdbc3MakeSSL.java b/org/postgresql/ssl/jdbc3/AbstractJdbc3MakeSSL.java
index b968f17..a5ae634 100644
--- a/org/postgresql/ssl/jdbc3/AbstractJdbc3MakeSSL.java
+++ b/org/postgresql/ssl/jdbc3/AbstractJdbc3MakeSSL.java
@@ -59,7 +59,7 @@ public class AbstractJdbc3MakeSSL {
}
}
- Socket newConnection = factory.createSocket(stream.getSocket(), stream.getAddress().getHostName(), stream.getAddress().getPort(), true);
+ Socket newConnection = factory.createSocket(stream.getSocket(), stream.getHostSpec().getHost(), stream.getHostSpec().getPort(), true);
stream.changeSocket(newConnection);
}
diff --git a/org/postgresql/ssl/jdbc4/AbstractJdbc4MakeSSL.java b/org/postgresql/ssl/jdbc4/AbstractJdbc4MakeSSL.java
index aed726e..b4ebd89 100644
--- a/org/postgresql/ssl/jdbc4/AbstractJdbc4MakeSSL.java
+++ b/org/postgresql/ssl/jdbc4/AbstractJdbc4MakeSSL.java
@@ -114,7 +114,7 @@ public class AbstractJdbc4MakeSSL {
SSLSocket newConnection;
try
{
- newConnection = (SSLSocket)factory.createSocket(stream.getSocket(), stream.getAddress().getHostName(), stream.getAddress().getPort(), true);
+ newConnection = (SSLSocket)factory.createSocket(stream.getSocket(), stream.getHostSpec().getHost(), stream.getHostSpec().getPort(), true);
newConnection.startHandshake(); //We must invoke manually, otherwise the exceptions are hidden
}
catch (IOException ex) {
@@ -137,16 +137,16 @@ public class AbstractJdbc4MakeSSL {
{
throw new PSQLException(GT.tr("The HostnameVerifier class provided {0} could not be instantiated.", sslhostnameverifier), PSQLState.CONNECTION_FAILURE, e);
}
- if (!hvn.verify(stream.getAddress().getHostName(), newConnection.getSession()))
+ if (!hvn.verify(stream.getHostSpec().getHost(), newConnection.getSession()))
{
- throw new PSQLException(GT.tr("The hostname {0} could not be verified by hostnameverifier {1}.", new Object[]{stream.getAddress().getHostName(), sslhostnameverifier}), PSQLState.CONNECTION_FAILURE);
+ throw new PSQLException(GT.tr("The hostname {0} could not be verified by hostnameverifier {1}.", new Object[]{stream.getHostSpec().getHost(), sslhostnameverifier}), PSQLState.CONNECTION_FAILURE);
}
} else {
if ("verify-full".equals(sslmode) && factory instanceof LibPQFactory)
{
- if (!(((LibPQFactory)factory).verify(stream.getAddress().getHostName(), newConnection.getSession())))
+ if (!(((LibPQFactory)factory).verify(stream.getHostSpec().getHost(), newConnection.getSession())))
{
- throw new PSQLException(GT.tr("The hostname {0} could not be verified.", stream.getAddress().getHostName()), PSQLState.CONNECTION_FAILURE);
+ throw new PSQLException(GT.tr("The hostname {0} could not be verified.", stream.getHostSpec().getHost()), PSQLState.CONNECTION_FAILURE);
}
}
diff --git a/org/postgresql/util/HostSpec.java b/org/postgresql/util/HostSpec.java
new file mode 100644
index 0000000..42ce462
--- /dev/null
+++ b/org/postgresql/util/HostSpec.java
@@ -0,0 +1,34 @@
+/*-------------------------------------------------------------------------
+*
+* Copyright (c) 2012, PostgreSQL Global Development Group
+*
+*
+*-------------------------------------------------------------------------
+*/
+package org.postgresql.util;
+
+/**
+ * Simple container for host and port.
+ */
+public class HostSpec {
+ protected final String host;
+ protected final int port;
+
+ public HostSpec(String host, int port)
+ {
+ this.host = host;
+ this.port = port;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public String toString() {
+ return host + ":" + port;
+ }
+}
^ permalink raw reply [nested|flat] 25+ messages in thread
* Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 04:16 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 01:19 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
2012-10-19 06:36 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 07:22 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 13:24 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
2012-10-23 02:56 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Scott Harrington <scotth01@sns-usa.com>
2012-10-23 03:55 ` Re: Severe performance degradation when using the 9.2-1000 JDBC 4 driver Kris Jurka <books@ejurka.com>
@ 2012-10-23 15:00 ` Scott Harrington <scotth01@sns-usa.com>
0 siblings, 0 replies; 25+ messages in thread
From: Scott Harrington @ 2012-10-23 15:00 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
On Mon, 22 Oct 2012, Kris Jurka wrote:
> On 10/22/2012 7:56 PM, Scott Harrington wrote:
>> Hi everyone, please look over this patch.
>>
>> By introducing a simple org.postgresql.util.HostSpec to contain the
>> orignal caller-provided host and port, we never even need to call
>> InetSocketAddress.getHostName() or getHostString().
>
> I think this is exactly what we want. Attached is a slightly modified
> version that includes fixes to the MakeSSL classes.
Thanks Kris, not sure how I missed those.
^ permalink raw reply [nested|flat] 25+ messages in thread
end of thread, other threads:[~2012-10-23 15:00 UTC | newest]
Thread overview: 25+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-10-05 19:27 Severe performance degradation when using the 9.2-1000 JDBC 4 driver emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-05 20:12 ` Thomas Kellerer <spam_eater@gmx.net>
2012-10-06 00:43 ` Kris Jurka <books@ejurka.com>
2012-10-08 07:49 ` emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-08 07:54 ` emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-06 13:29 ` Dave Cramer <pg@fastcrypt.com>
2012-10-18 04:16 ` Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 09:03 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 09:17 ` Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-18 09:24 ` Dave Cramer <pg@fastcrypt.com>
2012-10-18 10:46 ` Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-18 12:18 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-18 12:43 ` Dave Cramer <pg@fastcrypt.com>
2012-10-18 12:48 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-22 22:06 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 01:15 ` Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
2012-10-18 13:10 ` emergency.shower@gmail.com <emergency.shower@gmail.com>
2012-10-18 13:18 ` Sérgio Saquetim <sergiosaquetim@gmail.com>
2012-10-19 01:19 ` Kris Jurka <books@ejurka.com>
2012-10-19 06:36 ` Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2012-10-19 07:22 ` Craig Ringer <ringerc@ringerc.id.au>
2012-10-19 13:24 ` Scott Harrington <scotth01@sns-usa.com>
2012-10-23 02:56 ` Scott Harrington <scotth01@sns-usa.com>
2012-10-23 03:55 ` Kris Jurka <books@ejurka.com>
2012-10-23 15:00 ` Scott Harrington <scotth01@sns-usa.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox