Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lazy initialization for priority queue of hits and scores to improve latencies by 20% #746

Conversation

martin-gaievski
Copy link
Member

@martin-gaievski martin-gaievski commented May 10, 2024

Description

In this change we're improving hybrid query latencies by changing allocation of query hits objects for hybrid scores. Currently those objects are pre-populated, then for new element top of the priority queue is updated and heap is rebalanced. We're changing this to lazy initialization - priority queue is initially empty, for each hit we're inserting element. If we reach the capacity then element with low score is pushed out of the heap. As per benchmark results this alone gives 10% improvement.

With several other minor changes like pre calculate and store size instead of calling size() for each doc and each sub-query we can get 10% percent.

Below are metrics for hybrid query latency that I've collected after this change. There are based on 2.x (2.14) version and noaa OSB workload, all times are in ms:

One sub-query that selects 11M documents

Bool: p50 76.5531 | p90 77.8108
Hybrid: p50 133.644 | p90 151.903

One sub-query that selects 1.6K documents

Bool: p50 69.9585 | p90 70.2855
Hybrid: p50 70.1703 | p90 70.5498

Three sub-query that select 15M documents

Bool: p50 87.1001 | p90 87.7131
Hybrid: p50 234.802 | p90 262.876

following are the baseline results

One sub-query that selects 11M documents

Bool: p50 77.8893 | p90 78.1916
Hybrid: p50 186.709 | p90 197.739

One sub-query that selects 1.6K documents

Bool: p50 71.0947 | p90 71.691
Hybrid: p50 71.5156 | p90 72.8801

Three sub-query that select 15M documents

Bool: p50 87.0556 | p90 90.9105
Hybrid: p50 287.255 | p90 313.868

Following framegraph has been captured after this change:

profile_hybrq_step4v2_59_1610

Issues Resolved

#745
#704

Check List

  • All tests pass
  • Commits are signed as per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@martin-gaievski martin-gaievski changed the title Use lazy initialization for priority queue of hits and scores to improve latencies by 10% Use lazy initialization for priority queue of hits and scores to improve latencies by 20% May 10, 2024
@martin-gaievski martin-gaievski force-pushed the hybridq_optimization_replace_pq_updatetop_by_insertwithoverflow branch from 32a620a to 8ccee40 Compare May 10, 2024 00:21
Copy link

codecov bot commented May 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.86%. Comparing base (7c54c86) to head (4d0c69d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #746      +/-   ##
============================================
- Coverage     85.02%   84.86%   -0.16%     
- Complexity      790      792       +2     
============================================
  Files            60       60              
  Lines          2430     2425       -5     
  Branches        410      409       -1     
============================================
- Hits           2066     2058       -8     
- Misses          202      207       +5     
+ Partials        162      160       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@martin-gaievski martin-gaievski force-pushed the hybridq_optimization_replace_pq_updatetop_by_insertwithoverflow branch from 98b588b to 4d0c69d Compare May 21, 2024 16:37
@martin-gaievski martin-gaievski added backport 2.x Label will add auto workflow to backport PR to 2.x branch v2.15.0 hybrid search hybrid query performance optimization labels May 21, 2024
@martin-gaievski martin-gaievski added the performance Make it fast! label May 21, 2024
@martin-gaievski martin-gaievski merged commit 940a7ea into opensearch-project:main May 21, 2024
82 of 83 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 21, 2024
…ove latencies by 20% (#746)

* Optimize PQ for hybrid scores

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit 940a7ea)
martin-gaievski added a commit that referenced this pull request May 21, 2024
…ove latencies by 20% (#746) (#755)

* Optimize PQ for hybrid scores

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit 940a7ea)

Co-authored-by: Martin Gaievski <gaievski@amazon.com>
VijayanB pushed a commit that referenced this pull request May 29, 2024
…ove latencies by 20% (#746)

* Optimize PQ for hybrid scores

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Label will add auto workflow to backport PR to 2.x branch hybrid query performance optimization hybrid search performance Make it fast! v2.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants