[ 
https://issues.apache.org/jira/browse/HBASE-28043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17776456#comment-17776456
 ] 

Becker Ewing commented on HBASE-28043:
--------------------------------------

In the most recent commit, I've updated this PR to not apply the reverse 
seeking to RIV1 DBE encodings to fix the regression when doing small reverse 
scans over the hbase:meta table. The optimization added in this PR is strictly 
a regression to reverse scans over RIV1 DBE storefiles as it adds an additional 
seek. Seeks are fixed-cost in RIV1, but in encodings like prefix or fast-diff a 
seek + reseek can be substantially cheaper than two seeks. 

 

I've benchmarked this approach and it performs approximately equally to the 
current master branch for random meta scans, while preserving the 50% 
performance benefit on reverse scans over dense, prefix/diff encoded tables. 

 
||Benchmark||Revision||Avg Latency (us)||Avg Throughput (rows / sec)||
|metaRandomRead #1|master|839|11898|
|metaRandomRead #2|master|789|12656|
|metaRandomRead #3|master|785|12714|
|metaRandomRead #1|patch w/ RIV1 disabled|822|12149|
|metaRandomRead #2|patch w/ RIV1 disabled|809|12339|

 

I've collected the raw output logs of the "patch w/ RIV1 disabled" performance 
tests in [this 
gist|https://gist.github.com/jbewing/ab59fb271b7079109e73bb4dc9129cfe].

> Reduce seeks from beginning of block in StoreFileScanner.seekToPreviousRow
> --------------------------------------------------------------------------
>
>                 Key: HBASE-28043
>                 URL: https://issues.apache.org/jira/browse/HBASE-28043
>             Project: HBase
>          Issue Type: Improvement
>            Reporter: Becker Ewing
>            Assignee: Becker Ewing
>            Priority: Major
>         Attachments: Current_SeekToPreviousRowBehavior.png, 
> Proposed_SeekToPreviousRowBehavior.png
>
>
> Currently, for non-RIV1 DBE encodings, each call to 
> [StoreFileScanner.seekToPreviousRow|https://github.com/apache/hbase/blob/89ca7f4ade84c84a246281c71898543b6161c099/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java#L493-L506]
>  (a common operation in reverse scans) results in two seeks: 
>  # Seek from the beginning of the block to before the given row to find the 
> prior row
>  # Seek from the beginning of the block to the first cell of the prior row
> So if there are "N" rows in a block, a reverse scan through each row results 
> in seeking past 2(N-1)! rows.
>  
> This is a particularly expensive operation for tall tables that have many 
> rows in a block.
>  
> By introducing a state variable "previousRow" to StoreFileScanner, I believe 
> that we could modify the seeking algorithm to be:
>  # Seek from the beginning of the block to before the given row to find the 
> prior row
>  # Seek from the beginning of the block to before the row that is before the 
> row that was just seeked to (i.e. 2 rows back). _Save_ this as a hint for 
> where the prior row is in "previousRow"
>  # Reseek from "previousRow" (2 rows back from start) to 1 row back from 
> start (to the actual previousRow)
> Then the rest of the calls where a "previousRow" is present, you just need to 
> seek to the beginning of the block once instead of twice, i.e. 
>  # seek from the beginning of the block to right before the beginning of your 
> "previousRow" marker. Save this as the new "previousRow" marker
>  # Reseek to the next row (i.e. your previous "previousRow" marker)
>  
> If there are "N" rows in a block, a reverse scan from row N to row 0 results 
> in seeking past approximately (N-1)! rows i.e. 50% less than the current 
> behavior.
>  
> See the attached diagrams for the current and proposed behavior. 
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to