HBase 1.1.2 优化插入 Region预分配
2016-03-01 11:32
399 查看
预分Region 与 不预分Region 的测试:
1 不预分Region:
23~29秒插入100W数据 并且蛋疼的是每次都写入一个 RegionServer 且 只在一个 Region 相当于人为制造的网络风暴。
2 预分Region(3节点分了3个Region) 写入 18~19秒 100W 数据。 55555 每秒。(本机网络请求已满。否则应该线性增长)
下面是代码;
(注释部分为不分 Region 的情况)
package com.rocky.util;
import com.rocky.dao.HBaseFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
/**
* Created by rocky_24 on 2016/2/25.
*/
public class putData {
public static void main(String[] args) throws IOException {
// /**
// * 分16
// */
// byte[][] preforkRegions = new byte[10+6][];
// int k=0;
// System.out.println(preforkRegions.length);
// for(char i='0';i<='9';i++){
// preforkRegions[k++]=(""+i).getBytes();
//}
// for(char i='a';i<='f';i++){
// preforkRegions[k++]=(""+i).getBytes();
//}
byte[][] preforkRegions = new byte[3][];
preforkRegions [0] = ("5").getBytes();
preforkRegions [1] = ("10").getBytes();
preforkRegions [2] = ("z").getBytes();
createTable("access_logs","f",preforkRegions);
System.out.println(TimeUtils.getIntradayDateAndTime());
String [] pages = {"/","/a.html","/b.html","/c.html"};
Configuration con = HBaseFactory.getConf();
HTable table = new HTable(con,"access_logs");
// Table table = HBaseFactory.getHBaseConnection().getTable(TableName.valueOf("access_logs"));
table.setWriteBufferSize(1024 * 1024 * 6);
table.setAutoFlushTo(false);
int totalRecords = 10000;
Random rand = new Random();
System.out.println("importing " + totalRecords + " records ....");
List<Put> list = new ArrayList<Put>();
for (int i=0; i < totalRecords * 100; i++) {
String rowkey = UUID.randomUUID().toString();
String randomPage = pages[rand.nextInt(pages.length)];
Put put = new Put(rowkey.getBytes());
put.addColumn(Bytes.toBytes("f"), null, Bytes.toBytes(randomPage));
list.add(put);
}
System.out.println("put数据装载完毕:"+list.size());
System.out.println(TimeUtils.getIntradayDateAndTime());
table.put(list);
table.flushCommits();
table.close();
System.out.println("done");
System.out.println(TimeUtils.getIntradayDateAndTime());
}
/**
* 创建表
* @param tableName
* @param columnFamily
* @param spilts
* @throws IOException
*/
public static void createTable(String tableName, String columnFamily, byte[][] spilts) throws IOException {
Connection connection = HBaseFactory.getHBaseConnection();
Admin admin = connection.getAdmin();
if (admin.tableExists(TableName.valueOf(tableName))) {
admin.disableTable(TableName.valueOf(tableName));
admin.deleteTable(TableName.valueOf(tableName));
}
HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tableName));
tableDesc.addFamily(new HColumnDescriptor(columnFamily));
if (spilts == null) {
admin.createTable(tableDesc);
} else {
admin.createTable(tableDesc, spilts);
}
admin.close();
}
}
[/code]
观察 16010端口 查看 Region 分裂情况如下:
= =! 多分了一个 Region 因为HBase 在分裂创建时候是拿到asscii 码的 0 到 数字[10]
来自为知笔记(Wiz)
相关文章推荐
- 大话设计模式之简单的工厂模式
- 关于IE6、IE7、IE8实现盒子阴影shadow的几个注意点
- SAXREADER读取xml文件,报字节 UTF-8 序列的无效字节 1。 Nested exception: 1 字节 UTF-8 序列的无效字节 1。
- mysql 事务
- Ext基础1 -- Ext中 getDom、get、getCmp的区别
- 【leetcode】【54】Spiral Matrix
- 学习算法导论——堆排序
- iframe跨域上传图片
- Mac 已经安装多个版本的XCode,现又安装了XCode7.2.1报错
- syslog-ng解析dns,引起dhcpd 工作失效!
- UITabBarController
- 纪录一下最近被微信坑的事情
- iOS开发之Runloop
- MapServer 之 发布网络覆盖数据服务(WCS-Web Coverage Service)
- oracle监听理解 命名理解
- 简单的封装继承多态
- Adobe Dreamweaver CC 2014 代码颜色目录
- 兼容ie6及以上的阴影滤镜的写法
- 字符串对象(NSString)常用方法
- PHP学习(一):对PHP的理解