Hbase1.1.2的HTablePool已经被弃用,用什么来代替HTablePool呢?

理由
举报 取消

需要多线程的网hbase插入数据,网上有很多实用htablepool的例子,但是我的hbase版本是1.1.2,HTablePool已经被弃用,请问有什么其他类可以用的?

2017年10月29日 7 条回复 1129 次浏览

发起人:坂本鱼子酱 初入职场

谁家的恶汪没拴好逃跑了?姐姐比妹妹好!

回复 ( 7 )

  1. Reid Chan
    理由
    举报 取消

    纠正

    准确而言不是被弃用 是不建议client用 都成了developers api

    所有client端被弃用的api都有相对应的interface 用那个就好

    这样做的好处是 将具体实现隔离 留给开发者更大的开发空间 以后随意抽换更好的实现 而不影响client端代码

    说白了就是bridge pattern

  2. 关力
    理由
    举报 取消

    I don’t know what version are you using.

    From HBase 0.98.x you don’t need to pool HTable object anymore.

    Just get Table object from Connection object when you need, all the resource caching and management is done internally by Connection class.

    Apache HBase ™ Reference Guide

    For example, in multi-threaded environment the standard method can be described like this:

    import org.apache.hadoop.conf.Configuration;

    import org.apache.hadoop.hbase.HBaseConfiguration;

    import org.apache.hadoop.hbase.client.ConnectionFactory;

    import org.apache.hadoop.hbase.client.Connection;

    import org.apache.hadoop.hbsae.client.Table;

    int main() {

    // create a new hbase configuration object. (singleton)

    Configuration conf = HBaseConfiguration.create();

    // create a new hbase connection object. (singleton)

    Connection connection = ConnectionFactory.createConnection(conf);

    try {

    while (true) {

    // create a table instance everytime you need.

    // you don’t have to pool this object, because hbase client implementation

    // do necessary resource caching & control internally.

    Table table = connection.getTable(TableName.valueOf(“table”));

    table.close();

    }

    } finally {

    // close the hbase connection on application shutdown.

    connection.close();

    }

    }

    机器配置太低了。

    首先hbase内存至少要12G以上开给JVM, CMS回收,解决JVM hang问题。

    台数得根据自己的业务需求压力测试,评估负载。用途不一样,优化方向不一向

    发生的问题第一个是memstore, 第二个是compaction. 第三个JVM hang.

    memstore, compaction优化后的参数。当然,环境不一样,参数不一定适合,以下给个思路。下面是一个高并发,数据本身小的参数优化。

    <!– memstore –>

    <property>

    <name>hbase.regionserver.global.memstore.upperLimit</name>

    <value>0.2</value><!– default:0.4 –>

    </property>

    <property>

    <name>hbase.regionserver.global.memstore.lowerLimit</name>

    <value>0.15</value><!– default:0.38 –>

    </property>

    <property>

    <name>hbase.regionserver.optionalcacheflushinterval</name>

    <value>3600000</value><!– 1 hour, default: 1 hour –>

    </property>

    <property>

    <name>hbase.hregion.memstore.mslab.chunksize</name>

    <value>2097152</value>

    </property>

    <property>

    <name>hbase.hregion.memstore.mslab.max.allocation</name>

    <value>1024768</value>

    </property>

    <property>

    <name>hbase.hregion.memstore.flush.size</name>

    <value>134217728</value><!– default: 128MB –>

    </property>

    <!– compaction –>

    <property>

    <name>hbase.hregion.majorcompaction</name>

    <value>86400000</value><!– 1 day, default:7 days –>

    </property>

    <property>

    <name>hbase.hstore.compaction.min</name>

    <value>3</value>

    </property>

    <property>

    <name>hbase.hstore.compaction.max</name>

    <value>10</value><!– default: 10 –>

    </property>

    <property>

    <name>hbase.hstore.blockingStoreFiles</name>

    <value>30</value><!– default: 10 –>

    </property>

    <property>

    <name>hbase.regionserver.thread.compaction.large</name>

    <value>2</value><!– default: 1 –>

    </property>

  3. 汪惺惺
    理由
    举报 取消

    98的 API 上有说明可以直接用

    // Create a connection to the cluster.
    HConnection connection = HConnectionManager.createConnection(Configuration);
    HTableInterface table = connection.getTable("myTable");
    // use table as needed, the table returned is lightweight
    table.close();
    // use the connection for other access to the cluster
    connection.close();
    
  4. 章志刚
    理由
    举报 取消

    1.1.2中HConnectionManager 也被 Deprecated

    /** @deprecated */
    @Public
    @Evolving
    @Deprecated
    public class HConnectionManager extends ConnectionFactory {
    /** @deprecated */
    }
    
  5. bi qu
    理由
    举报 取消

    直接用org.apache.hadoop.hbase.client.Connection;就可以

  6. vdocker
    理由
    举报 取消

    可以用hconnection代替,线程安全

我来回答

Captcha 点击图片更换验证码