You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by 김민석 <co...@gmail.com> on 2016/08/03 04:11:42 UTC

JDBC Connection time

Hello All,
I'm writing my own java source using JDBC to test my own scenario/

import java.sql.*;
import java.util.*;

public class phoenixTest {
  public static void main(String args[]) throws Exception {
    Connection conn;
    //Properties prop = new Properties();
    Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
    long startTime = System.currentTimeMillis();
    conn =
 DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase");
    long estimatedTime = System.currentTimeMillis() - startTime;
    System.out.format("got connection : %s ms\n",
Long.toString(estimatedTime));
    //System.out.format("got connection : %s \n", "test");
  }
}

The result of the source above...
log4j:WARN No appenders could be found for logger
(org.apache.hadoop.conf.Configuration.deprecation).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
got connection : 3162 ms

It takes over 3 seconds to create the new connection. Is it normal?
Can it be handled through connection pool in application server?

Any advice would be appreciated. Thanks in advance.

Re: JDBC Connection time

Posted by kim steve <co...@gmail.com>.
@william Thanks for your advice.

This is my source code to understand your reply.

import java.sql.*;
import java.util.*;

public class phoenixTest {
  public static void main(String args[]) throws Exception {
    Connection conn;
    //Properties prop = new Properties();
    Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
    long startTime = System.currentTimeMillis();
    conn =
 DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase");
    long estimatedTime = System.currentTimeMillis() - startTime;
    System.out.format("got connection1 : %s ms\n",
Long.toString(estimatedTime));
    conn.close();

    startTime = System.currentTimeMillis();
    conn =
 DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase");
    estimatedTime = System.currentTimeMillis() - startTime;
    System.out.format("got connection2 : %s ms\n",
Long.toString(estimatedTime));
    conn.close();


    startTime = System.currentTimeMillis();
    conn =
 DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase");
    estimatedTime = System.currentTimeMillis() - startTime;
    System.out.format("got connection3 : %s ms\n",
Long.toString(estimatedTime));
    conn.close();
  }
}

Result
log4j:WARN No appenders could be found for logger
(org.apache.hadoop.conf.Configuration.deprecation).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
got connection1 : 3431 ms
got connection2 : 0 ms
got connection3 : 1 ms

I'm re-writing my code as your advice.
It saved my time a lot.
Thanks again.

Re:JDBC Connection time

Posted by William <yh...@163.com>.
It will cost that much indeed. If you connect to an HBase cluster with HBase native API, it will cost that much too.
But this is only for the 'first' connection in current JVM process. You can modify your test code and check how long it takes for the second or third connection.
It will be less than 1 ms as phoenix connection is designed to be light weight and all connections that connected to the same hbase cluster will share 
the same low-level hbase connection.  


I hope this will help you out.


William.

At 2016-08-03 12:11:42, "김민석" <co...@gmail.com> wrote:
>Hello All,
>I'm writing my own java source using JDBC to test my own scenario/
>
>import java.sql.*;
>import java.util.*;
>
>public class phoenixTest {
>  public static void main(String args[]) throws Exception {
>    Connection conn;
>    //Properties prop = new Properties();
>    Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
>    long startTime = System.currentTimeMillis();
>    conn =
> DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase");
>    long estimatedTime = System.currentTimeMillis() - startTime;
>    System.out.format("got connection : %s ms\n",
>Long.toString(estimatedTime));
>    //System.out.format("got connection : %s \n", "test");
>  }
>}
>
>The result of the source above...
>log4j:WARN No appenders could be found for logger
>(org.apache.hadoop.conf.Configuration.deprecation).
>log4j:WARN Please initialize the log4j system properly.
>log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
>more info.
>got connection : 3162 ms
>
>It takes over 3 seconds to create the new connection. Is it normal?
>Can it be handled through connection pool in application server?
>
>Any advice would be appreciated. Thanks in advance.