日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HBase 1.1.2 优化插入 Region预分配

發(fā)布時間:2025/7/25 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HBase 1.1.2 优化插入 Region预分配 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
??秒插入 ? 并且蛋疼的是相當于人為制造的網(wǎng)絡(luò)風暴。
  • 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 分裂情況如下:
    ? ?= =! 多分了一個 Region 因為HBase 在分裂創(chuàng)建時候是拿到asscii 碼的 0 到 數(shù)字[10]


    來自為知筆記(Wiz)

    轉(zhuǎn)載于:https://www.cnblogs.com/rocky24/p/7aaebae69fcabb134be725d57378d581.html

    總結(jié)

    以上是生活随笔為你收集整理的HBase 1.1.2 优化插入 Region预分配的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。