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

ASF GitHub Bot commented on HDFS-17871:
---------------------------------------

XorSum opened a new pull request, #8179:
URL: https://github.com/apache/hadoop/pull/8179

   <!--
     Thanks for sending a pull request!
       1. If this is your first time, please read our contributor guidelines: 
https://cwiki.apache.org/confluence/display/HADOOP/How+To+Contribute
       2. Make sure your PR title starts with JIRA issue id, e.g., 
'HADOOP-17799. Your PR title ...'.
   -->
   
   ### Description of PR
   
   https://issues.apache.org/jira/projects/HDFS/issues/HDFS-17871
   
   The current implementation of 
`org.apache.hadoop.hdfs.server.federation.resolver.MountTableResolver#findDeepest`
 method in RBF has a performance issue: when the tree doesn't contain a parent 
path for the queried path, the `while` loop iterates through **all entries** in 
the TreeMap, resulting in `O(n)` time complexity instead of the expected `O(log 
n)`.
   
   ### How was this patch tested?
   
   
   ### For code changes:
   
   - [x] Does the title or this PR starts with the corresponding JIRA issue id 
(e.g. 'HADOOP-17799. Your PR title ...')?
   - [ ] Object storage: have the integration tests been executed and the 
endpoint declared according to the connector-specific documentation?
   - [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`, 
`NOTICE-binary` files?
   
   ### AI Tooling
   
   If an AI tool was used:
   
   - [ ] The PR includes the phrase "Contains content generated by <tool>"
         where <tool> is the name of the AI tool used.
   - [ ] My use of AI contributions follows the ASF legal policy
         https://www.apache.org/legal/generative-tooling.html




> Performance Issue: `findDeepest()` in RBF traverses entire tree when parent 
> path doesn't exist
> ----------------------------------------------------------------------------------------------
>
>                 Key: HDFS-17871
>                 URL: https://issues.apache.org/jira/browse/HDFS-17871
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: rbf
>            Reporter: xorsum
>            Priority: Minor
>         Attachments: BenchmarkFindDeepest.java
>
>
> h2. Problem
> The current implementation of 
> `org.apache.hadoop.hdfs.server.federation.resolver.MountTableResolver#findDeepest`
>  method in RBF has a performance issue: when the tree doesn't contain a 
> parent path for the queried path, the `while` loop iterates through *all 
> entries* in the TreeMap, resulting in `O(N)` time complexity instead of the 
> expected `O(log N)`.
> h2. Example
> Consider a mount table containing:
>  - `/user/hive/warehouse/db1.db/table1`
>  - `/user/hive/warehouse/db1.db/table2`
>  - `/user/hive/warehouse/db2.db/table3`
> When querying a path like `/xyz/random/path/file.txt`, the algorithm will:
>  - `floorEntry("/xyz/random/path/file.txt")` returns the largest entry in the 
> tree
>  - Check `isParentEntry()`: false
>  - Call `lowerEntry()` repeatedly until reaching the first entry in the tree
>  - Worst case: Iterates through ALL entries in `O(N)` time
> h2. Proposed Solution
> We can improve the `findDeepest` method by checking the parent path directly, 
> instead of using `floorEntry`.
> I benchmarked the performance of these two implementations.
> The benchmark results show that the improved method is 50x faster than the 
> original method.
> {quote}================================================================================
> BENCHMARK COMPARISON RESULTS
> ================================================================================
> 【Original Method - findDeepest】
> Total Execution Time: 1,924,288,819 ns (1924.29 ms)
> Total Lookup Count: 15,302,856
> Avg Time Per Query: 320,607.93 ns (0.32 ms)
> Avg Lookups Per Query: 2,549.63
> 【Improved Method - findDeepestImproved】
> Total Execution Time: 38,030,989 ns (38.03 ms)
> Total Lookup Count: 24,008
> Avg Time Per Query: 6,336.39 ns (0.01 ms)
> Avg Lookups Per Query: 4.00
> 【Performance Improvement】
> Time Saved: 98.02%
> Lookup Count Reduced: 99.84%
> Speedup Factor: 50.60x
> 【Correctness Verification】
> ✓ All results match! Both methods returned identical results.
> ================================================================================
> {quote}



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to