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
 **/
时间: 2024-08-12 13:47:19

Hbase之缓存扫描加快读取速度的相关文章

利用Squid反向代理搭建CDN缓存服务器加快Web访问速度

2011年11月26日 ? Web服务器架构 ? 评论数 2 案例:Web服务器:域名www.abc.com IP:192.168.21.129 电信单线路接入访问用户:电信宽带用户.移动宽带用户出现问题:电信用户打开www.abc.com正常,移动用户打开www.abc.com很慢,甚至打不开解决方案:在移动机房放置一台CDN代理服务器,通过智能DNS解析,让电信用户直接访问Web服务器.让移动用户访问CDN代理服务器,解决移动用户访问Web服务器慢的问题具体操作:CDN代理服务器:系统:Ce

m2014-architecture-imgserver->利用Squid反向代理搭建CDN缓存服务器加快Web访问速度

案例:Web服务器:域名www.abc.com IP:192.168.21.129 电信单线路接入访问用户:电信宽带用户.移动宽带用户出现问题:电信用户打开www.abc.com正常,移动用户打开www.abc.com很慢,甚至打不开解决方案:在移动机房放置一台CDN代理服务器,通过智能DNS解析,让电信用户直接访问Web服务器.让移动用户访问CDN代理服务器,解决移动用户访问Web服务器慢的问题具体操作:CDN代理服务器:系统:CentOS 5.5 主机名:cdn.abc.com IP:192

如何使用浏览器缓存来加快站点的访问速度 转载

当我们想尽办法提高服务器负载能力的时候,是否曾想过,其实浏览器也有缓存功能,我们也可以利用浏览器的缓存功能来减少服务器的负载,提高网站吞吐量?        当我们使用抓包工具查看http状态时,我们可以看到200,304,from cache之类的标识,也许你也早已注意到了他们,并明白他们的意思.但是,你是否想过在你的程序中加入代码主动告诉浏览器,更好地利用浏览器缓存. 备注:本章所有案例都是使用chrome 17.0.963.79 m浏览器,测试方式为每次打开浏览器新窗口的方式测试,而不是F

[转载]SQL数据库如何加快查询速度

[转载:http://www.3lian.com/edu/2013/12-30/120014.html] 1.升级硬件 2.根据查询条件,建立索引,优化索引.优化访问方式,限制结果集的数据量. 3.扩大服务器的内存 4.增加服务器CPU个数 5.对于大的数据库不要设置数据库自动增长,它会降低服务器的性能 6.在查询Select语句中用Where字句限制返回的行数,避免表扫描,如果返回不必要的数据,浪费了服务器的I/O资源,加重了网络的负担降低性能.如果表很大,在表扫描的期间将表锁住,禁止其他的联

使用Openresty加快网页速度

新年快乐~~~ 上一篇文章讲到使用多级缓存来减少数据库的访问来加快网页的速度,只是,仍旧没有"嗖"一下就加载出来的感觉,想再优化一下,优化代码什么的已经到了极限.上周无意中看到了openresty,能够直接在nginx层直接对请求处理,而不需要每次都访问tomcat,特别是对于自己的首页http://www.wenzhihuai.com来说,由于首页内容广泛,需要涉及的方法太多,每次打开首页都得耗费大量的时间. 一.整体架构 目前本人总共有三个服务器: A:119.23.46.71(深

数据读取速度达1.5G/s,UFS 2.1存储技术曝光

目前最快的是苹果NVME,当然UFS2.1也不差 iPhone6s与iPhone6s Plus在硬件的规格上有了很大的提升,但是它们身上的变化远没有苹果在发布会上所提到的A9处理器.1200万摄像头以及3D Touch那么简单,内存升级到2GB LPDDR4苹果就只字没提到,其实这两台手机上有着更大的秘密,它们的存储设备既不是eMMC也不是UFS规范,而是NVMe. Anandtech透过深度发掘手机内的系统文件,发现iPhone 6s所用的是型号为AP0128K的苹果SSD,而2015版Mac

160304、mysql数据库插入速度和读取速度的调整记录

需求:由于项目变态,需要在一个比较短时间段急剧增加数据库记录(两三天内,由于0增加至5亿).在整个过程调优过程非常艰辛 思路: (1)提高数据库插入性能中心思想:尽量将数据一次性写入到Data File和减少数据库的checkpoint 操作.这次修改了下面四个配置项: 1)将 innodb_flush_log_at_trx_commit 配置设定为0:按过往经验设定为0,插入速度会有很大提高. 0: Write the log buffer to the log file and flush

hdparm命令 硬盘读取速度压力测试

准备工作: 知识点:硬盘在读写在过程中部分数据通过buffer和cache缓存在内存中从而提高读写速度,hdparm对两种缓存做了区分 -T cache 缓存 -t buffer 缓存 安装:hdparm yum install hdparm  //  直接yum安装即可138k的样子,很小巧 hdparm -h  查看帮助信息,此处演示最常用的压测命令 ------------------ # hdparm -t /dev/sda //测试buffer缓存情况下硬盘读速度 /dev/sda:

硬盘读取速度变慢 — 当前传送模式: PIO模式

网上搜索了一下,找到两篇文章: 标题:硬盘读取速度变慢 当前传输模式pio的解决方法 http://www.veryhuo.com/a/view/52786.html   (解决思路:先卸载驱动,重启电脑,再安装一次驱动) 标题:我也经常遇到硬盘为PIO模式的问题,现在算找到解决办法了. http://hi.baidu.com/hj_space/item/636684b718baaefb62388ead (解决思路: 先更新驱动,重启一次) 虽然说,PIO模式的问题解决了,但不可忽视硬盘确实出现