Search in sources :

Example 1 with TableSnapshotScanner

use of org.apache.hadoop.hbase.client.TableSnapshotScanner in project hbase by apache.

the class ScanPerformanceEvaluation method testSnapshotScan.

public void testSnapshotScan() throws IOException {
    Stopwatch snapshotRestoreTimer = Stopwatch.createUnstarted();
    Stopwatch scanOpenTimer = Stopwatch.createUnstarted();
    Stopwatch scanTimer = Stopwatch.createUnstarted();
    Path restoreDir = new Path(this.restoreDir);
    snapshotRestoreTimer.start();
    restoreDir.getFileSystem(conf).delete(restoreDir, true);
    snapshotRestoreTimer.stop();
    Scan scan = getScan();
    scanOpenTimer.start();
    TableSnapshotScanner scanner = new TableSnapshotScanner(conf, restoreDir, snapshotName, scan);
    scanOpenTimer.stop();
    long numRows = 0;
    long numCells = 0;
    scanTimer.start();
    while (true) {
        Result result = scanner.next();
        if (result == null) {
            break;
        }
        numRows++;
        numCells += result.rawCells().length;
    }
    scanTimer.stop();
    scanner.close();
    ScanMetrics metrics = scanner.getScanMetrics();
    long totalBytes = metrics.countOfBytesInResults.get();
    double throughput = (double) totalBytes / scanTimer.elapsed(TimeUnit.SECONDS);
    double throughputRows = (double) numRows / scanTimer.elapsed(TimeUnit.SECONDS);
    double throughputCells = (double) numCells / scanTimer.elapsed(TimeUnit.SECONDS);
    System.out.println("HBase scan snapshot: ");
    System.out.println("total time to restore snapshot: " + snapshotRestoreTimer.elapsed(TimeUnit.MILLISECONDS) + " ms");
    System.out.println("total time to open scanner: " + scanOpenTimer.elapsed(TimeUnit.MILLISECONDS) + " ms");
    System.out.println("total time to scan: " + scanTimer.elapsed(TimeUnit.MILLISECONDS) + " ms");
    System.out.println("Scan metrics:\n" + metrics.getMetricsMap());
    System.out.println("total bytes: " + totalBytes + " bytes (" + StringUtils.humanReadableInt(totalBytes) + ")");
    System.out.println("throughput  : " + StringUtils.humanReadableInt((long) throughput) + "B/s");
    System.out.println("total rows  : " + numRows);
    System.out.println("throughput  : " + StringUtils.humanReadableInt((long) throughputRows) + " rows/s");
    System.out.println("total cells : " + numCells);
    System.out.println("throughput  : " + StringUtils.humanReadableInt((long) throughputCells) + " cells/s");
}
Also used : Path(org.apache.hadoop.fs.Path) TableSnapshotScanner(org.apache.hadoop.hbase.client.TableSnapshotScanner) Stopwatch(org.apache.hbase.thirdparty.com.google.common.base.Stopwatch) Scan(org.apache.hadoop.hbase.client.Scan) ScanMetrics(org.apache.hadoop.hbase.client.metrics.ScanMetrics) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

Path (org.apache.hadoop.fs.Path)1 Result (org.apache.hadoop.hbase.client.Result)1 Scan (org.apache.hadoop.hbase.client.Scan)1 TableSnapshotScanner (org.apache.hadoop.hbase.client.TableSnapshotScanner)1 ScanMetrics (org.apache.hadoop.hbase.client.metrics.ScanMetrics)1 Stopwatch (org.apache.hbase.thirdparty.com.google.common.base.Stopwatch)1