You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by James Taylor <ja...@apache.org> on 2014/02/06 19:11:11 UTC

Fwd: Long DB Connect Times

A good one for you HBase committers to help with. I'd appreciate it if
folks could subscribe to the user group and help answer questions. My model
for excellence here is based off of what I've seen in the HBase community
which is absolutely fantastic.
Thanks!
James

---------- Forwarded message ----------
From: Justin Workman <ju...@gmail.com>
Date: Thu, Feb 6, 2014 at 10:04 AM
Subject: Long DB Connect Times
To: "user@phoenix.incubator.apache.org" <us...@phoenix.incubator.apache.org>


I am using this following java code to make my DB connection and I am
seeing what seems like long connect times to the database. We see similar
connect times opening a connection with sqlline. Are there any options to
speed up the connection? The query is returning in roughly 500-700ms once
the connection is made.

Timing of the Java client around the db connection statement
DB Connection Time: 17.09 s
DB Connection Time: 6.888 s
DB Connection Time: 2.007 s
DB Connection Time: 6.894 s
DB Connection Time: 12.05 s

This is all running the same query, and reconnecting to the DB everytime.
We are using Kerberos, but I am starting my timer after authenticating.

Sample code

*DB Connection:*
public static Connection getPhoenixConnection() throws Exception {
    Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");
    String connectionURL = "jdbc:phoenix:" + zkQuorum;
    LOGGER.warn("Making Phoenix Connection Now To Zookeeper: " + zkQuorum);

    Connection r = DriverManager.getConnection (connectionURL);
    r.setAutoCommit(true);
    return r;
  }

*Call to connect to DB:*
UserGroupInformation ugi =
UserGroupInformation.loginUserFromKeytabAndReturnUGI(RUNTIME_USER,
KEYTAB_PATH);
    LOGGER.info("Logged in from keytab as: " + ugi.getUserName());
    // Create connection as privileged user
    Stopwatch connectionTimer = new Stopwatch().start();
    conn = ugi.doAs(new PrivilegedExceptionAction<Connection>() {
        public Connection run() throws Exception {
           try {
              conn = getPhoenixConnection();
           } catch (Exception e) {
              LOGGER.warn("Failed to make secure Phoenix connection. " + e);
              throw e;
           }
           return conn;
        }
     });
    connectionTimer.stop();

Re: Long DB Connect Times

Posted by alex kamil <al...@gmail.com>.
why would you want to reconnect to the DB every time

do it only once at startup, something along the lines:


public class PhoenixDB{

private static PhoenixDB dbReader= null;

private static Connection conn = null;

private static String zkQuorum = "localhost";


 public static PhoenixDB getInstance() {

 if(dbReader == null)

 dbReader = new PhoenixDB ();

 return dbReader;

}

public PhoenixDB(){

 try{

 if (conn == null)

  conn =getPhoenixConnection();

 } catch (Exception e) {

  System.out.println("Exception when connecting to hbase");

  e.printStackTrace();

 }

}

..

public static void main(String[] args){

 PhoenixDB db = PhoenixDB.getInstance();

 //db.select("select * from table1");

//db.select("select * from table2");

}

}


> ---------- Forwarded message ----------
> From: Justin Workman <ju...@gmail.com>
> Date: Thu, Feb 6, 2014 at 10:04 AM
> Subject: Long DB Connect Times
> To: "user@phoenix.incubator.apache.org" <user@phoenix.incubator.apache.org
> >
>
>
> I am using this following java code to make my DB connection and I am
> seeing what seems like long connect times to the database. We see similar
> connect times opening a connection with sqlline. Are there any options to
> speed up the connection? The query is returning in roughly 500-700ms once
> the connection is made.
>
> Timing of the Java client around the db connection statement
> DB Connection Time: 17.09 s
> DB Connection Time: 6.888 s
> DB Connection Time: 2.007 s
> DB Connection Time: 6.894 s
> DB Connection Time: 12.05 s
>
> This is all running the same query, and reconnecting to the DB everytime.
> We are using Kerberos, but I am starting my timer after authenticating.
>
> Sample code
>
> *DB Connection:*
> public static Connection getPhoenixConnection() throws Exception {
>     Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");
>     String connectionURL = "jdbc:phoenix:" + zkQuorum;
>     LOGGER.warn("Making Phoenix Connection Now To Zookeeper: " + zkQuorum);
>
>     Connection r = DriverManager.getConnection (connectionURL);
>     r.setAutoCommit(true);
>     return r;
>   }
>
> *Call to connect to DB:*
> UserGroupInformation ugi =
> UserGroupInformation.loginUserFromKeytabAndReturnUGI(RUNTIME_USER,
> KEYTAB_PATH);
>     LOGGER.info("Logged in from keytab as: " + ugi.getUserName());
>     // Create connection as privileged user
>     Stopwatch connectionTimer = new Stopwatch().start();
>     conn = ugi.doAs(new PrivilegedExceptionAction<Connection>() {
>         public Connection run() throws Exception {
>            try {
>               conn = getPhoenixConnection();
>            } catch (Exception e) {
>               LOGGER.warn("Failed to make secure Phoenix connection. " +
> e);
>               throw e;
>            }
>            return conn;
>         }
>      });
>     connectionTimer.stop();
>