hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Enis Söztutar <enis....@gmail.com>
Subject Re: HTable or HConnectionManager, how a client connect to HBase?
Date Wed, 18 Feb 2015 04:34:43 GMT

You are right that the constructor new HTable(Configuration, ..) will share
the underlying connection if same configuration object is used. Connection
is a heavy weight object, that holds the zookeeper connection, rpc client,
socket connections to multiple region servers, master, and the thread pool,
etc. You definitely do not want to create multiple connections per process
unless you know what you are doing.

The model is changed, and the old way of HTable(Configuration, ..) is
deprecated because, we want to make the Connection lifecycle management
explicit. In the new model, an opened Connection is closed by the user
again, and light weight Table instances are obtained from the Connection.
Having HTable's share their connections implicitly makes reasoning about it
too hard. The new model should be pretty easy to follow.


On Sat, Feb 14, 2015 at 6:45 AM, Liu, Ming (HPIT-GADSC) <ming.liu2@hp.com>

> Hi,
> I am using HBase 0.98.6.
> I learned from this maillist before, that the recommended method to
> 'connect' to HBase from client is to use HConnectionManager like this:
>                                 HConnection
> con=HConnectionManager.createConnection(configuration);
>                                 HTableInterfacetable =
> con.getTable("hbase_table1");
> Instead of
>                                 HTableInterface table = new
> HTable(configuration, "hbase_table1");
> I don't quite understand the reason. I was thinking that each time I
> initialize a HTable instance, it needs to create a new HConnection. And
> that is expensive. But using the first method, multiple HTable instances
> can share the same HConnection. That is quite reasonable to me.
> However, I was reading from some articles on internet that , even if I use
> the 'new HTable(conf, tbl)' method, if the 'conf' object is the same one,
> all the HTable instances will still share the same HConnection. I was
> recently read yet another article and said when using 'new HTable(conf,
> tbl)', one don't need to use the exactly same 'conf' object (same one in
> memory). if two 'conf' objects, two different objects are all the same, I
> mean all attributes of these two are same (for example, created from the
> same hbase-site.xml and never change) then HTable objects can still share
> the same HConnection.  I also try to read the HTable src code, it is very
> hard, but it seems to me the last statement is correct: 'HTable will share
> HConnection, if configuration is all the same'.
> Sorry for so verbose. My question:
> If two 'configuration' objects are same, then two HTable object
> instantiated with them respectively can still share the same HConnection or
> not? Directly using the 'new HTable()' method.
> If the answer is 'yes', then why I still need the HConnectionManager to
> create a shared connection?
> I am talking about 0.98.6.
> I googled for days, and even try to read HBase src code, but still get
> really confused. I try to do some tests also, but since I am too newbie, I
> don't know how to verify the difference, I really don't know what a
> HConnection do under the hood. I counted the ZooKeeper client requests, and
> I found some difference. If this ZooKeeper requests difference is a correct
> metrics, it means to me that two HTable do not share HConnetion even using
> same 'configuration' in the constructor. So it confused me more and more....
> Please someone kindly help me for this newbie question and thanks in
> advance.
> Thanks,
> Ming

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message