大数据应用之HBase数据插入性能优化实测教程
引言:
大家在使用HBase的过程中,总是面临性能优化的问题,本文从HBase客户端参数设置的角度,研究HBase客户端数据批量插入性能优化的问题。事实胜于雄辩,数据比理论更有说服力,基于此,作者设计了这么一个HBase数据插入性能优化实测实验,希望大家用自己的服务器跑出的结果,给自己一个值得信服的结论。
一、客户单优化参数
1.Put List Size
HBase的Put支持单条插入,也支持批量插入。
2. AutoFlush
AutoFlush指的是在每次调用HBase的Put操作,是否提交到HBase Server。 默认是true,每次会提交。如果此时是单条插入,就会有更多的IO,从而降低性能
3.Write Buffer Size
Write Buffer Size在AutoFlush为false的时候起作用,默认是2MB,也就是当插入数据超过2MB,就会自动提交到Server
4.WAL
WAL是Write Ahead Log的缩写,指的是HBase在插入操作前是否写Log。默认是打开,关掉会提高性能,但是如果系统出现故障(负责插入的Region Server 挂掉),数据可能会丢失。
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
|
参数 |
默认值 |
说明 |
|
JVM Heap Size |
平台不同值不同自行设置 |
|
|
AutoFlush |
True |
默认逐条提交 |
|
Put List Size |
1 |
支持逐条和批量 |
|
Write Buffer Size |
2M |
与autoflush配合使用 |
|
Write Ahead Log |
True |
默认开启,需要手动关闭 |
|
… |
||
|
… |
二、源码程序
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes; /*
* -------优化案例说明------------
* 1.优化参数1:Autoflush 默认关闭,需要手动开启
* 2.优化参数2:put list size 支持单条与批量
* 3.优化参数3:JVM heap size 默认值是平台而不同,需要手动设置
* 4.优化参数4:Write Buffer Size 默认值2M
* 5.优化参数5:Write Ahead Log 默认开启,需要手动关闭
* */ public class TestInsert {
static Configuration hbaseConfig = null; public static void main(String[] args) throws Exception {
Configuration HBASE_CONFIG = new Configuration();
HBASE_CONFIG.set("hbase.master", "192.168.230.133:60000");
HBASE_CONFIG.set("hbase.zookeeper.quorum", "192.168.230.133");
HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");
hbaseConfig = HBaseConfiguration.create(HBASE_CONFIG);
//关闭wal,autoflush,writebuffer = 24M
insert(false,false,1024*1024*24);
//开启AutoFlush,writebuffer = 0
insert(false,true,0);
//默认值,全部开启
insert(true,true,0);
} private static void insert(boolean wal,boolean autoFlush,long writeBuffer)
throws IOException {
String tableName="etltest";
HBaseAdmin hAdmin = new HBaseAdmin(hbaseConfig);
if (hAdmin.tableExists(tableName)) {
hAdmin.disableTable(tableName);
hAdmin.deleteTable(tableName);
} HTableDescriptor t = new HTableDescriptor(tableName);
t.addFamily(new HColumnDescriptor("f1"));
t.addFamily(new HColumnDescriptor("f2"));
t.addFamily(new HColumnDescriptor("f3"));
t.addFamily(new HColumnDescriptor("f4"));
hAdmin.createTable(t);
System.out.println("table created"); HTable table = new HTable(hbaseConfig, tableName);
table.setAutoFlush(autoFlush);
if(writeBuffer!=0){
table.setWriteBufferSize(writeBuffer);
}
List<Put> lp = new ArrayList<Put>();
long all = System.currentTimeMillis(); System.out.println("start time = "+all);
int count = 20000;
byte[] buffer = new byte[128];
Random r = new Random();
for (int i = 1; i <= count; ++i) {
Put p = new Put(String.format("row d",i).getBytes());
r.nextBytes(buffer);
p.add("f1".getBytes(), null, buffer);
p.add("f2".getBytes(), null, buffer);
p.add("f3".getBytes(), null, buffer);
p.add("f4".getBytes(), null, buffer);
p.setWriteToWAL(wal);
lp.add(p);
if(i%1000 == 0){
table.put(lp);
lp.clear();
}
} System.out.println("WAL="+wal+",autoFlush="+autoFlush+",buffer="+writeBuffer+",count="+count);
long end = System.currentTimeMillis();
System.out.println("total need time = "+ (end - all)*1.0/1000+"s"); System.out.println("insert complete"+",costs:"+(System.currentTimeMillis()-all)*1.0/1000+"ms");
}
}
三、集群配置
3.1 服务器硬件配置清单
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
|
序号 |
节点名称 |
CUP |
内存 |
硬盘 |
带宽 |
|
1 |
HMaster |
||||
|
2 |
HregionServer1 |
||||
|
3 |
HregionServer2 |
||||
|
4 |
… |
||||
|
5 |
|||||
|
6 |
|||||
|
7 |
3.2 客户端硬件配置清单
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
|
设备 |
节点名称 |
|
|
Cpu |
||
|
内存 |
||
|
硬盘 |
||
|
带宽 |
四、测试报告
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
|
数据量 |
JVM |
AutoFlush |
Put List Size |
WriteBufferSize |
WAL |
耗时 |
|
1000 |
512m |
false |
1000 |
1024*1024*24 |
false |
|
|
2000 |
||||||
|
5000 |
||||||
|
10000 |
||||||
|
20000 |
||||||
|
50000 |
||||||
|
100000 |
||||||
|
200000 |
||||||
|
500000 |
||||||
|
100000 |
备注:该技术专题讨论正在群Hadoop高级交流群:293503507同步直播中,敬请关注。
大数据应用之HBase数据插入性能优化实测教程的更多相关文章
- TODOList 多线程交互、RCP、事物控制、数据倾斜、HBase数据同步性
TODOList 多线程交互.RCP.事物控制.数据倾斜.HBase数据同步性 TODO List thread.join()如何互相之间通知? 线程池何时最后运行完成? MemCache性能要优于R ...
- 【转载】HBase 数据库检索性能优化策略
转自:http://www.ibm.com/developerworks/cn/java/j-lo-HBase/index.html 高性能 HBase 数据库 本文首先介绍了 HBase 数据库基本 ...
- HBase 数据库检索性能优化策略--转
https://www.ibm.com/developerworks/cn/java/j-lo-HBase/index.html HBase 数据表介绍 HBase 数据库是一个基于分布式的.面向列的 ...
- HBase 数据库检索性能优化策略
HBase 数据表介绍 HBase 数据库是一个基于分布式的.面向列的.主要用于非结构化数据存储用途的开源数据库.其设计思路来源于 Google 的非开源数据库"BigTable" ...
- MySQL插入性能优化
目录 MySQL插入性能优化 代码优化 values 多个 一个事务 插入字段尽量少,尽量用默认值 关闭 unique_checks bulk_insert_buffer_size 配置优化 inno ...
- 《Spark大数据处理:技术、应用与性能优化 》
基本信息 作者: 高彦杰 丛书名:大数据技术丛书 出版社:机械工业出版社 ISBN:9787111483861 上架时间:2014-11-5 出版日期:2014 年11月 开本:16开 页码:255 ...
- 《Spark大数据处理:技术、应用与性能优化》【PDF】 下载
内容简介 <Spark大数据处理:技术.应用与性能优化>根据最新技术版本,系统.全面.详细讲解Spark的各项功能使用.原理机制.技术细节.应用方法.性能优化,以及BDAS生态系统的相关技 ...
- 《Spark大数据处理:技术、应用与性能优化》【PDF】
内容简介 <Spark大数据处理:技术.应用与性能优化>根据最新技术版本,系统.全面.详细讲解Spark的各项功能使用.原理机制.技术细节.应用方法.性能优化,以及BDAS生态系统的相关技 ...
- 大数据应用之HBase数据插入性能优化之多线程并行插入测试案例
一.引言: 上篇文章提起关于HBase插入性能优化设计到的五个参数,从参数配置的角度给大家提供了一个性能测试环境的实验代码.根据网友的反馈,基于单线程的模式实现的数据插入毕竟有限.通过个人实测,在我的 ...
随机推荐
- python自动化运维之路06
python中面向对象编程 编程范式: 编程是 程序 员 用特定的语法+数据结构+算法组成的代码来告诉计算机如何执行任务的过程 , 一个程序是程序员为了得到一个任务结果而编写的一组指令的集合,正所谓条 ...
- hdu4333
题解: EX_KMP 先把串复制一遍放到后面 这样旋转就是每一个前缀了 然后做一个EX_KMP 然后看一下后一个字符谁大谁小 代码: #include<cstdio> #include&l ...
- Oracle 11g 在audit_file_dest目录下产生大量的aud文件
一.adump目录数据暴增现象 发现某台数据库服务器的根目录的使用率在暴涨,发现Oracle数据库的adump目录,每秒生成一个dump文件.数据库并未开通审计外部记录.为什么adump目录会生成那么 ...
- DBGRID 拖动滚动条 和 鼠标滚轮的问题
滚动条拖动问题 默认是,拖动时,网格内数据不变,等放开鼠标后才会变. 方法 拖动时同时变,当前记录也变,不用新控件 http://wenwen.sogou.com/z/q185291591.htm 鼠 ...
- 玩转X-CTR100 | STM32F4 l Malloc内存管理
我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] 内存管理技术,即内存的申请和释放,使用X- ...
- 亚马逊Kindle正式进入中国
6月7日下午消息,亚马逊Kindle今天下午4点正式发售.其中,Kindle电子阅读器和Kindle Fire平板电脑同步销售.Paperwhite售价最低849元,Kindle Fire HD售价最 ...
- zabbix 爆高危 SQL 注入漏洞,可获系统权限(profileIdx 2 参数)
漏洞概述 zabbix是一个开源的企业级性能监控解决方案.近日,zabbix的jsrpc的profileIdx2参数存在insert方式的SQL注入漏洞,攻击者无需授权登陆即可登陆zabbix管理系统 ...
- SecureCRT来上传和下载文件
引用:https://www.cnblogs.com/zhengyihan1216/p/6260667.html Linux--用SecureCRT来上传和下载文件 SecureCRT下的文件传输协议 ...
- HDU 3364
http://acm.hdu.edu.cn/showproblem.php?pid=3364 经典高斯消元解开关问题 m个开关控制n个灯,开始灯全灭,问到达目标状态有几种方法(每个开关至多一次操作,不 ...
- C高级第一次PTA作业 要求三
要求一.要求二 内容链接:http://www.cnblogs.com/X-JY/p/8550457.html 一.PTA作业中的知识点总结 1.6-1 计算两数的和与差(10 分) (1)*在程序中 ...