Count the number of rows in an HBase table

更新时间:
复制 MD 格式

This topic describes how to count the number of rows in an ApsaraDB for HBase table.

The method that you use to count rows depends on the service type of your ApsaraDB for HBase table.
  • If you use ApsaraDB for HBase Enhanced Edition, see Count the number of rows in a table.
  • For ApsaraDB for HBase Standard Edition, two methods are available to accurately count the number of rows in a table. First, you must connect to your ApsaraDB for HBase Standard Edition instance using HBase Shell. For more information, see Use HBase Shell to access clusters.
    • You can use the COUNT command in the HBase Shell tool to accurately count the number of rows in an HBase table. The COUNT command works by scanning all table data in batches. Run the COUNT command on an ECS client that is in the same private network. If you run the COUNT command over the public network, network usage is high and counting efficiency is reduced. The scan speed varies depending on the table schema. When you use the COUNT command to scan a full table, the speed can reach up to 100,000 rows per second.
      Run the following statement to count the total number of rows in the table.
      COUNT 'table'
      The following result is returned:统计结果显示
    • RowCounter starts a pseudo-distributed MapReduce (MR) job locally to perform the COUNT operation. By default, this method runs on a single thread, and the counting speed is similar to that of the COUNT command in HBase Shell. To increase the counting speed, you can use multi-threaded concurrent execution by specifying Dmapreduce.local.map.tasks.maximum=<number_of_threads>. Note the following:
      • The number of threads must be less than or equal to the number of regions in the table.
      • An increased number of threads can cause a high cluster load, which may affect your online services. Set the number of threads based on your requirements.
      In HBase Shell, run the following code to count the number of rows in a Lindorm wide table.
      • Count the total number of rows in the target table.
        ./alihbase-2.0.18/bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter  "table"
      • Count the total number of rows in the target table using 16 concurrent threads.
        ./alihbase-2.0.18/bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter -Dmapreduce.local.map.tasks.maximum=16 "table"
      • Count the total number of rows in the target table in the ns namespace.
        ./alihbase-2.0.18/bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter  "ns:table"
      The results are saved to the hbase.log file in the Log folder.统计结果显示