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 <[email protected]>
> Date: Thu, Feb 6, 2014 at 10:04 AM
> Subject: Long DB Connect Times
> To: "[email protected]" <[email protected]
> >
>
>
> 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();
>