HBase 1.1.2 优化插入 Region预分配
生活随笔
收集整理的這篇文章主要介紹了
HBase 1.1.2 优化插入 Region预分配
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
??秒插入 ? 并且蛋疼的是相當(dāng)于人為制造的網(wǎng)絡(luò)風(fēng)暴。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數(shù)據(jù)裝載完畢:"+list.size()); System.out.println(TimeUtils.getIntradayDateAndTime()); table.put(list); table.flushCommits(); table.close(); System.out.println("done"); System.out.println(TimeUtils.getIntradayDateAndTime()); } /** * 創(chuàng)建表 * @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(); } }
觀察 16010端口 查看 Region 分裂情況如下:
? ?= =! 多分了一個(gè) Region 因?yàn)镠Base 在分裂創(chuàng)建時(shí)候是拿到asscii 碼的 0 到 數(shù)字[10]
來(lái)自為知筆記(Wiz)
觀察 16010端口 查看 Region 分裂情況如下:
? ?= =! 多分了一個(gè) Region 因?yàn)镠Base 在分裂創(chuàng)建時(shí)候是拿到asscii 碼的 0 到 數(shù)字[10]
來(lái)自為知筆記(Wiz)
轉(zhuǎn)載于:https://www.cnblogs.com/rocky24/p/7aaebae69fcabb134be725d57378d581.html
總結(jié)
以上是生活随笔為你收集整理的HBase 1.1.2 优化插入 Region预分配的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 标准CSV解析
- 下一篇: Android性能优化系列总篇