Hbase之缓存扫描加快读取速度
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics; import java.io.IOException; /**
* Created by similarface on 16/8/23.
*/
public class ScanDataUseCache {
private static Table table=null;
public static Table getTable() {
if(table==null){
try {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
//建立表的连接
return connection.getTable(TableName.valueOf("testtable"));
}catch (IOException e){
return table;
}
}
return table;
}
private static void scan(int caching,int batch,boolean small) {
int count=0;
//setCaching 设置的值为每次rpc的请求记录数,默认是1;cache大可以优化性能,但是太大了会花费很长的时间进行一次传输。
//setBatch 设置每次取的column size;有些row特别大,所以需要分开传给client,就是一次传一个row的几个column。
//setSmall 是否为小扫描
//setScanMetricsEnabled 使用了集合
Scan scan = new Scan().setCaching(caching).setBatch(batch).setSmall(small).setScanMetricsEnabled(true);
ResultScanner scanner=null;
try {
scanner = getTable().getScanner(scan);
}catch (IOException e){
System.out.println(e);
}
if (scanner!=null){
for (Result result:scanner){
count++;
}
scanner.close();
ScanMetrics metrics = scan.getScanMetrics();
System.out.println("Caching: " + caching + ", Batch: " + batch + ", Small: " + small + ", Results: " + count + ", RPCs: " + metrics.countOfRPCcalls);
}
else {
System.out.println("Error");
}
} public static void main(String[] args) throws IOException {
// Caching: 1, Batch: 1, Small: false, Results: 9, RPCs: 12
scan(1, 1, false); //Caching: 1, Batch: 0, Small: false, Results: 4, RPCs: 7
scan(1, 0, false); // Caching: 1, Batch: 0, Small: true, Results: 4, RPCs: 0
scan(1, 0, true); //Caching: 200, Batch: 1, Small: false, Results: 9, RPCs: 3
scan(200, 1, false); //Caching: 200, Batch: 0, Small: false, Results: 4, RPCs: 3
scan(200, 0, false); //Caching: 200, Batch: 0, Small: true, Results: 4, RPCs: 0
scan(200, 0, true); // Caching: 2000, Batch: 100, Small: false, Results: 4, RPCs: 3
scan(2000, 100, false); // Caching: 2, Batch: 100, Small: false, Results: 4, RPCs: 5
scan(2, 100, false); // Caching: 2, Batch: 10, Small: false, Results: 4, RPCs: 5
scan(2, 10, false); // Caching: 2, Batch: 10, Small: false, Results: 4, RPCs: 5
scan(5, 100, false); // Caching: 5, Batch: 100, Small: false, Results: 4, RPCs: 3
scan(5, 20, false); // Caching: 10, Batch: 10, Small: false, Results: 4, RPCs: 3
scan(10, 10, false);
}
} /**
Caching: 1, Batch: 0, Small: false, Results: 5, RPCs: 8
Caching: 1, Batch: 0, Small: true, Results: 5, RPCs: 0
Caching: 200, Batch: 1, Small: false, Results: 1009, RPCs: 8
Caching: 200, Batch: 0, Small: false, Results: 5, RPCs: 3
Caching: 200, Batch: 0, Small: true, Results: 5, RPCs: 0
Caching: 2000, Batch: 100, Small: false, Results: 14, RPCs: 3
Caching: 2, Batch: 100, Small: false, Results: 14, RPCs: 10
Caching: 2, Batch: 10, Small: false, Results: 104, RPCs: 55
Caching: 5, Batch: 100, Small: false, Results: 14, RPCs: 5
Caching: 5, Batch: 20, Small: false, Results: 54, RPCs: 13
Caching: 10, Batch: 10, Small: false, Results: 104, RPCs: 13
**/
这是一个9行数据的表
每行包含一些列
使用缓存为6 批量为3的扫描器
需要3个RPC
3个列装入一个Result实例
6个result到缓存中 组成一个RPC
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics; import java.io.IOException; /**
* Created by similarface on 16/8/24.
*/
public class ScanWithOffsetAndLimit {
private static Table table = null; public static Table getTable() {
if (table == null) {
try {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
//建立表的连接
return connection.getTable(TableName.valueOf("testtable"));
} catch (IOException e) {
return table;
}
}
return table;
} /**
* 遍历访问数据
* @param num 运行次序
* @param caching
* @param batch
* @param offset
* @param maxResults
* @param maxResultSize
* @param dump
* @throws IOException
*/
private static void scan(int num, int caching, int batch, int offset, int maxResults, int maxResultSize, boolean dump
) throws IOException {
int count = 0;
Scan scan = new Scan().setCaching(caching).setBatch(batch)
.setRowOffsetPerColumnFamily(offset)
.setMaxResultsPerColumnFamily(maxResults)
.setMaxResultSize(maxResultSize)
.setScanMetricsEnabled(true);
ResultScanner scanner = getTable().getScanner(scan);
System.out.println("Scan #" + num + " running...");
for (Result result : scanner) {
count++;
if (dump)
System.out.println("Result [" + count + "]:" + result);
}
scanner.close();
ScanMetrics metrics = scan.getScanMetrics();
System.out.println("Caching: " + caching + ", Batch: " + batch +
", Offset: " + offset + ", maxResults: " + maxResults +
", maxSize: " + maxResultSize + ", Results: " + count +
", RPCs: " + metrics.countOfRPCcalls);
} public static void main(String[] args) throws IOException {
//偏移为0 最大2个cell 所以会扫描到列1 和列2
scan(1, 11, 0, 0, 2, -1, true);
//偏移为4 最大2个cell 所以会扫描到列5 和列6
scan(2, 11, 0, 4, 2, -1, true);
//
scan(3, 5, 0, 0, 2, -1, false);
scan(4, 11, 2, 0, 5, -1, true);
scan(5, 11, -1, -1, -1, 1, false);
scan(6, 11, -1, -1, -1, 10000, false);
}
} /**
Caching: 11, Batch: 0, Offset: 0, maxResults: 2, maxSize: -1, Results: 5005, RPCs: 458
Caching: 11, Batch: 0, Offset: 4, maxResults: 2, maxSize: -1, Results: 1, RPCs: 3
Caching: 5, Batch: 0, Offset: 0, maxResults: 2, maxSize: -1, Results: 5005, RPCs: 1004
Caching: 11, Batch: 2, Offset: 0, maxResults: 5, maxSize: -1, Results: 5009, RPCs: 458
Caching: 11, Batch: -1, Offset: -1, maxResults: -1, maxSize: 1, Results: 5005, RPCs: 11012
Caching: 11, Batch: -1, Offset: -1, maxResults: -1, maxSize: 10000, Results: 5005, RPCs: 469
**/
Hbase之缓存扫描加快读取速度的更多相关文章
- ASP.NET状缓存Cache的应用-提高数据库读取速度
原文:ASP.NET状缓存Cache的应用-提高数据库读取速度 一. Cache概述 既然缓存中的数据其实是来自数据库的,那么缓存中的数据如何和数据库进行同步呢?一般来说,缓存中应该存放改 ...
- 优化SQLServer数据库加快查询速度
查询速度慢的原因很多,常见如下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列导致查询不优化. 4.内存不足 ...
- 使用Openresty加快网页速度
新年快乐~~~ 上一篇文章讲到使用多级缓存来减少数据库的访问来加快网页的速度,只是,仍旧没有"嗖"一下就加载出来的感觉,想再优化一下,优化代码什么的已经到了极限.上周无意中看到了o ...
- mysql千万级数据库插入速度和读取速度的调整记录
一般情况下mysql上百万数据读取和插入更新是没什么问题了,但到了上千万级就会出现很慢,下面我们来看mysql千万级数据库插入速度和读取速度的调整记录吧. 1)提高数据库插入性能中心思想:尽量将数据一 ...
- 数据读取速度达1.5G/s,UFS 2.1存储技术曝光
目前最快的是苹果NVME,当然UFS2.1也不差 iPhone6s与iPhone6s Plus在硬件的规格上有了很大的提升,但是它们身上的变化远没有苹果在发布会上所提到的A9处理器.1200万摄像头以 ...
- 160304-01、mysql数据库插入速度和读取速度的调整记录
需求:由于项目变态,需要在一个比较短时间段急剧增加数据库记录(两三天内,由于0增加至5亿).在整个过程调优过程非常艰辛 思路: (1)提高数据库插入性能中心思想:尽量将数据一次性写入到Data Fil ...
- mysql千万级数据库插入速度和读取速度的调整
mysql上百万数据读取和插入更新一般没什么问题,但上千万后速度会很慢,如何调整配置,提高效率.如下: 1.尽量将数据一次性写入DataFile和减少数据库的checkpoint操作,调整如下参数: ...
- Linux检测硬盘读取速度
1. 清空缓存 > /proc/sys/vm/drop_caches 2. 测试读取速度 a. 将/dev/zero中数据按1M的数据单位写入testfile,共写512个单位,并不通过缓存 c ...
- Android开发之制作圆形头像自定义View,直接引用工具类,加快开发速度。带有源代码学习
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 博客园主页:http://www.cnblogs.com/mcxiaobing ...
随机推荐
- JAVA基础知识之JVM-——反射和泛型
泛型和Class类 在反射中使用泛型Class<T>可以避免强制类型转换,下面是一个简单例子,如果不使用泛型的话,需要显示转换, package aop; import java.util ...
- android post请求
参考文章:http://blog.csdn.net/lotusyangjun/article/details/22292445 http://blog.csdn.net/withiter/articl ...
- Codeforces Round #368 (Div. 2) B
Description Masha wants to open her own bakery and bake muffins in one of the n cities numbered from ...
- ContentProvider官方教程(9)定义一个provider完整示例:实现方法,定义权限等
Creating a Content Provider In this document Designing Data Storage Designing Content URIs Implement ...
- 为什么需要main函数,及其参数的用法
首先,需要明确main函数是什么? 答:main函数是C语言约定的入口函数 C99标准里面是这样描述的: Program startup The function called at program ...
- log4j中文乱码解决方案
项目中log4j在英文版linux下输出中文日志为乱码. 由于log4j配置文件中没有设置编码格式(encoding),所以log4j就使用系统默认编码.导致乱码. 解决方法是设置编码格式UTF-8, ...
- 【leetcode❤python】13. Roman to Integer
#-*- coding: UTF-8 -*-#从前向后遍历罗马数字,#如果某个数比前一个数小,则加上该数.反之,减去前一个数的两倍然后加上该数###-----技术规则-----#----------- ...
- PowerShell 4 on win7 sp1
https://www.microsoft.com/en-hk/download/details.aspx?id=40855 文件太多了,按照这个http://stackoverflow.com/qu ...
- WdatePicker.js 日历点击时,触发自定义方法 ,可以调用自己的函数。
问题: 在选择日期后,没有提交按钮,得到日期后,就可以把日期传到后台,然后就可以得到数据. 方法: 在input 标签中加入onfocus ,就可以了. wdatePicker();可以自定义事件函数 ...
- 从输入 URL 到页面加载完的过程中都发生了什么事情?
1) 把URL分割成几个部分:协议.网络地址.资源路径.其中网络地址指示该连接网络上哪一台计算机,可以是域名或者IP地址,可以包括端口号:协议是从该计 算机获取资源的方式,常见的是HTTP.FTP,不 ...