hbase 开启缓冲和不开启缓冲 比较
来源:互联网 发布:js中sleep怎么使用 编辑:程序博客网 时间:2024/06/06 05:31
hbase 中的put 一个put相当于是一个rpc,如果循环的次数过多 则绝大部分时间都消耗在rpc的网路传输过程中 而不是用于传输数据的时间占比高
如果开启个缓冲 一次性提交批量数据 则会提高效率
得了 话就说那么多,直接上代码
package com.hit.test;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.client.HTableInterface;import org.apache.hadoop.hbase.client.Put;import org.apache.hadoop.hbase.util.Bytes;/** * Created by zh on 2017/10/25. */public class TestPut { private byte[] f = Bytes.toBytes("mycf"); private byte[] q = Bytes.toBytes("q1"); private byte[] q2 = Bytes.toBytes("q2"); public static void main(String[] args) throws Exception { TestPut t = new TestPut(); HTableInterface mytable = HbaseUtils.getTable("sku:mytable"); t.put1000(mytable); t.put100Cache(mytable); } public void put1000( HTableInterface mytable)throws Exception{ Long l = System.currentTimeMillis(); for (int i =0;i<100000;i++){ Put put = new Put(Bytes.toBytes("row1_"+i)); put.add(f,q,Bytes.toBytes("row1_q1_value1_"+i)); put.add(f,q2,Bytes.toBytes("row1_q2_value1_"+i)); mytable.put(put); } System.out.println("put1000消耗时间为 "+ (System.currentTimeMillis() - l)+"ms"); } public void put100Cache(HTableInterface mytable)throws Exception{ Long l = System.currentTimeMillis(); mytable.setAutoFlush(false); for (int i =0;i<100000;i++){ Put put = new Put(Bytes.toBytes("row1_"+i)); put.add(f,q,Bytes.toBytes("row1_q1_value1_"+i)); put.add(f,q2,Bytes.toBytes("row1_q2_value1_"+i)); mytable.put(put); } System.out.println("put100Cache消耗时间为 "+ (System.currentTimeMillis() - l)+"ms"); }}
put1000消耗时间为 164039ms
put100Cache消耗时间为 1895ms
差距简直大到惊人
可以手动去强制写缓冲 不过不推荐 推荐直接设置缓冲池的大小 让hbase客户端自动去提交数据
不过有一点得注意一下 我写的这个代码也没有注意到 最后得进行一个手动强制flash缓冲区域 不然会出现需要等待下次缓冲区域满了才会进行刷写hbase,出现数据丢失的情况
阅读全文
0 0
- hbase 开启缓冲和不开启缓冲 比较
- C# Winform ListView 双缓冲开启
- 关于PHP开启缓冲函数系列函数
- 双缓冲页面和后备缓冲页面比较
- 不带缓冲IO和带缓冲IO
- 不带缓冲IO和带缓冲IO
- 带缓冲的IO和不带缓冲的IO
- 不带缓冲IO和带缓冲IO
- 不带缓冲IO和带缓冲IO
- 不带缓冲IO和带缓冲IO
- 标准IO缓冲详解 全缓冲 行缓冲 不缓冲
- 标准IO缓冲详解全缓冲、行缓冲、不缓冲
- 标准IO缓冲详解全缓冲、行缓冲、不缓冲
- 标准IO缓冲详解全缓冲、行缓冲、不缓冲
- 缓冲
- 缓冲
- 缓冲
- 缓冲
- Java
- 移动端左右滑动阻止触发上一页下一页操作
- 引导页基本实现方式
- 顺序表集合的交并差操作
- MATLAB中filter函数的C代码实现
- hbase 开启缓冲和不开启缓冲 比较
- C# Console.WriteLine()函数中{}输出格式详解
- mybatis分页查询之sql server--mysql
- c#执行cmd命令创建服务
- 怎麽去掉Xcode工程中的某種類型的警告
- Android 源码解析-LruCache 缓存工具类
- 【AGC014E】Blue and Red Tree 并查集 启发式合并
- Nginx(5)---使用nginx作为负载均衡器
- 微信公众号开发后台基本搭建(基于NodeJs的express框架)