hbase(main):017:0> help 'count'
Count the number of rows in a table. Return value is the number of rows.
This operation may take a LONG time (Run '$HADOOP_HOME/bin/hadoop jar
hbase.jar rowcount' to run a counting mapreduce job). Current count is shown every 1000 rows by default. Count interval may be optionally specified. Scan caching is enabled on count scans by default. Default cache size is 10 rows.If your rows are small in size, you may want to increase this
parameter. Examples:
hbase> count 'ns1:t1'
hbase> count 't1'
hbase> count 't1', INTERVAL => 100000
hbase> count 't1', CACHE => 1000
hbase> count 't1', INTERVAL => 10, CACHE => 1000
The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding commands would be:
hbase> t.count
hbase> t.count INTERVAL => 100000
hbase> t.count CACHE => 1000
hbase> t.count INTERVAL => 10, CACHE => 1000
可以看到「使用count查询表的数据条数」这个操作可能需要消耗过长时间
(运行’$HADOOP_HOME/bin/hadoop jar hbase.jar rowcount’ 来运行计数 mapReduce 作业)。
默认情况下,当前计数每 1000 行显示一次。可以选择指定计数间隔。默认情况下,对计数扫描启用扫描缓存。默认缓存大小为 10 行。
通过Java API的方式,使用scan
进行全表扫描,循环计数RowCount,速度较慢! 但快于第一种count方式!
基本代码如下:
public void rowCountByScanFilter(String tablename){
long rowCount = 0;
try {
// 计时
StopWatch stopWatch = new StopWatch();
stopWatch.start();
TableName name=TableName.valueOf(tablename);
// connection为类静态变量
Table table = connection.getTable(name);
Scan scan = new Scan();
// FirstKeyOnlyFilter只会取得每行数据的第一个kv,提高count速度
scan.setFilter(new FirstKeyOnlyFilter());
ResultScanner rs = table.getScanner(scan);
for (Result result : rs) {
rowCount += result.size();
}
stopWatch.stop();
System.out.println("RowCount: " + rowCount);
System.out.println("统计耗时:" +stopWatch.getTotalTimeMillis());
} catch (Throwable e) {
e.printStackTrace();
}
}
zhangsan@node01:/usr/local/hbase-1.1.5/bin$ ./hbase org.apache.hadoop.hbase.mapreduce.RowCounter ‘yourtablename’
这种方式效率比第一种要高,调用的HBase jar中自带的统计行数的类。
我们通过建立Hive和HBase关联表的方式,可以直接在Hive中执行sql语句统计出HBase表的行数。
zhangsan@node01:/usr/local/hadoop-2.7.2/sbin$ ./start-dfs.sh
zhangsan@node01:/usr/local/hbase-1.1.5/bin$ ./start-hbase.sh
zhangsan@node01:/usr/local/hbase/bin$ jps
3648 Jps
2737 DataNode
3555 HRegionServer
2948 SecondaryNameNode
3337 HQuorumPeer
2604 NameNode
3436 HMaster
zhangsan@node01:/usr/local/hive-2.1.0/bin$ hiveserver2
zhangsan@node01:/usr/local/hbase-1.1.5/bin$ hbase shell
# HBase 建表
create 'hbase_hive_test', 'cf1'
zhangsan@node01:/usr/local/hive-2.1.0/bin$ hive
hive>create table hive_hbase_test(key int,value string)
>stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
>with serdeproperties("hbase.columns.mapping"=":key,cf1:val")
>tblproperties("hbase.table.name"="hive_hbase_test");
OK
Time taken: 8.018 seconds
hbase(main):001:0> list
TABLE
hive_hbase_test
1 row(s) in 0.6800 seconds
=> ["hive_hbase_test"]
该方法是目前最快实现「查询一张表的数据条数」的方法
为什么利用协处理器后速度会如此之快?
Table注册了Coprocessor之后,在执行AggregationClient的时候,会将RowCount分散到Table的每一个Region上,Region内RowCount的计算,是通过RPC执行调用接口,由Region对应的RegionServer执行InternalScanner进行的。
因此,性能的提升有两点原因:
1.分布式统计
。将原来客户端按照Rowkey的范围单点进行扫描,然后统计的方式,换成了由所有Region所在RegionServer同时计算的过程。
2.使用了在RegionServer内部执行使用了InternalScanner
。这是距离实际存储最近的Scanner接口,存取更加快捷。
public void rowCountByCoprocessor(String tablename){
try {
//提前创建connection和conf
Admin admin = connection.getAdmin();
TableName name=TableName.valueOf(tablename);
//先disable表,添加协处理器后再enable表
admin.disableTable(name);
HTableDescriptor descriptor = admin.getTableDescriptor(name);
String coprocessorClass = "org.apache.hadoop.hbase.coprocessor.AggregateImplementation";
if (! descriptor.hasCoprocessor(coprocessorClass)) {
descriptor.addCoprocessor(coprocessorClass);
}
admin.modifyTable(name, descriptor);
admin.enableTable(name);
//计时
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Scan scan = new Scan();
AggregationClient aggregationClient = new AggregationClient(conf);
System.out.println("RowCount: " + aggregationClient.rowCount(name, new LongColumnInterpreter(), scan));
stopWatch.stop();
System.out.println("统计耗时:" +stopWatch.getTotalTimeMillis());
} catch (Throwable e) {
e.printStackTrace();
}
}
文章浏览阅读564次,点赞2次,收藏10次。CC, color conversion,色彩转换CC, color correction,色彩矫正CE, chroma enhancement,色度增强SNR,signal-to-noise ratio,信噪比SNR, skin noise reduce,肤色降噪STD, standard deviation,标准差OIS, optical image stabilization 光学稳像 PDAF,phase detection auto focus,相位对焦CPP: camera po_高通hjr是什么意思
文章浏览阅读1.3w次,点赞4次,收藏26次。原文:http://blog.csdn.net/wemedia/details.html?id=43211深度学习哪家强?吴恩达、Udacity和Fast.ai的课程我们替你分析好了原2017.08.20AI科技大本营翻译 | AI科技大本营(rgznai100)参与 | reason_W 引言_ai 深度学习
文章浏览阅读5.8k次。异步赠书:Kotlin领衔10本好书 SDCC 2017之区块链技术实战线上峰会 程序员9月书讯 每周荐书:Java Web、Python极客编程(评论送书) window.quickReplyflag = true; var isBole = false; var fasrc="htt_小波包能量的matlab代码
文章浏览阅读563次,点赞3次,收藏9次。基于openstack安装部署私有云详细图文教程 本文中作者通过自身基于OpenStack搭建私有云平台的实战经验,对OpenStack实施私有云落地的需求进行梳理,综合产生个人的观点和评价并和读者分享。本文主要分享的是云计算、openstack的使用、私有云平台建设、云服务器云硬盘的构建和使用。从基本概念入手到私有云建设,信息量非常大。对于openstack的安装部署都是从..._openstack云平台搭建 最新
文章浏览阅读1.2w次,点赞2次,收藏37次。项目中我们经常需要实现轮询-每隔几秒请求一次接口实现数据更新1:一般都会使用setInterval,但要注意单纯使用它会导致页面卡死方法1:new Vue({ el: '#app', data: {}, created: function() { var that = this; // setInterval不会清除定时器队列,每重复执行1次都会导致定时器叠加 \ window.setInterval(() =_vue中每两秒调用一次接口
文章浏览阅读7.5k次,点赞3次,收藏12次。GAUSS-51100:"Failed to verify SSH trust on these nodes: %s."SQLSTATE: 无错误原因:在各节点上核实SSH互信失败。解决办法:检查确保各节点互信必须创建。GAUSS-51101:"SSH exception: \n%s."SQLSTATE: 无错误原因:远程连接异常。解决办法:检查确保网络连接必须正常;检查确保远程机器的IP及登录用户和密码必须正确。GAUSS-51102:"Failed to exch_[gauss-50236] : the 192.168.40.130 does not exist or the permission on the u
文章浏览阅读2.8w次,点赞49次,收藏230次。 对于pytorch保存网络参数,大家一般可以看到有 .pkl文件 以及 .pth文件,对于这两者有什么区别,以及如何保存网络参数等,本文就好好讲述一下。 一、保存方式 首先我们知道不论是保存模型还是参数都需要用到torch.save()。_pytorch保存网络结构
文章浏览阅读1.2w次,点赞12次,收藏21次。yolov8遇到报错_modulenotfounderror: no module named 'ultralytics
文章浏览阅读961次,点赞20次,收藏24次。LeetCode刷题笔记;算法题:接雨水;核心思想是利用双指针在O(1)空间复杂度下解决【接雨水】问题。【双指针】【python】【困难】
文章浏览阅读3.3k次,点赞12次,收藏56次。行人跟踪统计是智能监控系统中的重要功能,可以广泛应用于人流控制、安全监控等领域。传统的行人跟踪算法往往受到光照、遮挡等因素的干扰,难以实现准确跟踪。随着深度学习技术的发展,目标检测模型逐渐成为行人跟踪的主流方案。本文介绍使用YOLOv8目标检测模型实现行人跟踪统计的方法。_yolov8人流量计算
文章浏览阅读5w次,点赞69次,收藏277次。Idea导入的项目不能运行Idea导入的项目不能运行Idea导入的项目不能运行其实这个错误是因为没有设置output的路径,只要修改两个地方的设置就可以了:在Modules设置里勾选”Inherit project compile path”2. 设置Project中的”Project compiler output” 选择”Project的路径”+”\out”,比如说我的就是 如..._idea 跑不起来是什么原因
文章浏览阅读2.9k次,点赞3次,收藏10次。计算机网络——数据链路层_为什么链路层不采用csma/ca