Skip to content

[GRPC] Optimize gRPC perf by passing by reference#18303

Merged
andrross merged 4 commits intoopensearch-project:mainfrom
karenyrx:test-pass-reference
May 27, 2025
Merged

[GRPC] Optimize gRPC perf by passing by reference#18303
andrross merged 4 commits intoopensearch-project:mainfrom
karenyrx:test-pass-reference

Conversation

@karenyrx
Copy link
Copy Markdown
Contributor

@karenyrx karenyrx commented May 15, 2025

Description

In the response-side of the transport-grpc plugin, response protobuf construction is primarily done by passing around copies of the partially constructed protobuf objects, populating them in various methods, and finally returning the combined protobuf object. This is much less efficient than passing all the protobuf builders by reference, which reduces the number of unecessary objects created and copied.

Implementing a pass-by-reference approach should reduce memory usage, garbage collection, CPU usage, and latency slightly, which was validated in a benchmark test below.

This PR also makes some minor refactoring changes and Javadoc fixes for readability and modularity.

Benchmarking results

Setup

  • Payload for the test was a MatchAll query (with source=true), returning 30k docs (~2.27MB).
  • Single data node in cluster with 8 cores, 64GB memory
  • Ran 3 trials and took the average.

Results

Testing (using Ballast, an internal perf testing tool) shows a small but consistent latency and CPU reduction with this change

  • Latency
    output (6)

  • CPU usage
    output (5)

Raw data

[Before] GRPC without change
Metric Percentile Trial 1 Trial 2 Trial 3 Average
Latency - First Request (ms) P50 61.0 63.5 60.5 61.7
P95 666.7 666.7 666.7 666.7
P99 666.7 666.7 666.7 666.7
P99.9 666.7 666.7 666.7 666.7
Latency - Subsequent Requests (ms) P50 30.2 31.0 30.5 30.6
P95 34.7 36.2 35.0 35.3
P99 40.1 42.3 40.3 40.9
P99.9 47.3 50.0 48.1 48.5
CPU Usage Max 0.31 0.29 0.30 0.30
Avg 0.27 0.26 0.27 0.27
[After] GRPC with pass by reference
Metric Percentile Trial 1 Trial 2 Trial 3 Average
Latency - First Request (ms) P50 55.3 54.5 55.2 55.0
P95 500.0 500.0 520.0 506.7
P99 666.7 666.7 666.7 666.7
P99.9 666.7 666.7 666.7 666.7
Latency - Subsequent Requests (ms) P50 29.0 29.0 29.3 29.1
P95 31.0 32.0 31.7 31.6
P99 36.0 37.0 36.5 36.5
P99.9 43.7 45.1 44.3 44.4
CPU Usage Max 0.28 0.27 0.28 0.28
Avg 0.25 0.23 0.24 0.24

Conclusions

  1. Latency reduction: GRPC with pass reference has consistently lower latency for both first and subsequent requests compared to GRPC no change.

  2. CPU Usage reduction: GRPC with pass reference has lower max and average CPU usage compared to GRPC no change.

Related Issues

Partly resolves #18291

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

@github-actions github-actions bot added enhancement Enhancement or improvement to existing feature or request Search:Performance labels May 15, 2025
@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 835b0df: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@karenyrx karenyrx force-pushed the test-pass-reference branch from 5cfc899 to a062e83 Compare May 15, 2025 01:36
@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 8114025: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Karen Xu <karenxyr@gmail.com>
@karenyrx karenyrx force-pushed the test-pass-reference branch from 8114025 to 444f1ec Compare May 15, 2025 02:06
@github-actions
Copy link
Copy Markdown
Contributor

❕ Gradle check result for 444f1ec: UNSTABLE

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

@codecov
Copy link
Copy Markdown

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 85.18519% with 24 lines in your changes missing coverage. Please review.

Project coverage is 72.64%. Comparing base (aec3fe9) to head (9d3db04).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...rpc/proto/response/search/SearchHitProtoUtils.java 80.00% 9 Missing and 1 partial ⚠️
...oto/response/document/get/GetResultProtoUtils.java 46.66% 7 Missing and 1 partial ⚠️
...ponse/document/common/DocumentFieldProtoUtils.java 0.00% 4 Missing ⚠️
...pc/proto/response/common/FieldValueProtoUtils.java 90.90% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #18303      +/-   ##
============================================
+ Coverage     72.52%   72.64%   +0.11%     
- Complexity    67496    67615     +119     
============================================
  Files          5495     5495              
  Lines        311433   311489      +56     
  Branches      45249    45223      -26     
============================================
+ Hits         225867   226275     +408     
+ Misses        67179    66806     -373     
- Partials      18387    18408      +21     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@karenyrx karenyrx marked this pull request as ready for review May 15, 2025 03:16
@karenyrx karenyrx requested a review from a team as a code owner May 15, 2025 03:16
@karenyrx karenyrx force-pushed the test-pass-reference branch from fd0e65d to 9ee0743 Compare May 22, 2025 22:53
@github-actions
Copy link
Copy Markdown
Contributor

✅ Gradle check result for 9ee0743: SUCCESS

Signed-off-by: Andrew Ross <andrross@amazon.com>
@andrross
Copy link
Copy Markdown
Member

I rebased and fixed the changelog conflict. This is ready to merge once all tests pass.

@github-actions
Copy link
Copy Markdown
Contributor

❌ Gradle check result for 9d3db04: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Copy Markdown
Contributor

✅ Gradle check result for 9d3db04: SUCCESS

@andrross andrross merged commit b82ba83 into opensearch-project:main May 27, 2025
30 checks passed
Gagan6164 pushed a commit to Gagan6164/OpenSearch that referenced this pull request Jun 8, 2025
…#18303)

* [GRPC] Optimize gRPC perf by passing by reference

Signed-off-by: Karen Xu <karenxyr@gmail.com>

* Use pattern matching with switch expression

Signed-off-by: Karen Xu <karenxyr@gmail.com>

---------

Signed-off-by: Karen Xu <karenxyr@gmail.com>
Signed-off-by: Andrew Ross <andrross@amazon.com>
Co-authored-by: Andrew Ross <andrross@amazon.com>
Gagan6164 pushed a commit to Gagan6164/OpenSearch that referenced this pull request Jun 8, 2025
…#18303)

* [GRPC] Optimize gRPC perf by passing by reference

Signed-off-by: Karen Xu <karenxyr@gmail.com>

* Use pattern matching with switch expression

Signed-off-by: Karen Xu <karenxyr@gmail.com>

---------

Signed-off-by: Karen Xu <karenxyr@gmail.com>
Signed-off-by: Andrew Ross <andrross@amazon.com>
Co-authored-by: Andrew Ross <andrross@amazon.com>
neuenfeldttj added a commit to neuenfeldttj/OpenSearch that referenced this pull request Jun 26, 2025
…#18303)

* [GRPC] Optimize gRPC perf by passing by reference

Signed-off-by: Karen Xu <karenxyr@gmail.com>

* Use pattern matching with switch expression

Signed-off-by: Karen Xu <karenxyr@gmail.com>

---------

Signed-off-by: Karen Xu <karenxyr@gmail.com>
Signed-off-by: Andrew Ross <andrross@amazon.com>
Co-authored-by: Andrew Ross <andrross@amazon.com>Signed-off-by: TJ Neuenfeldt <tjneu@amazon.com>
neuenfeldttj pushed a commit to neuenfeldttj/OpenSearch that referenced this pull request Jun 26, 2025
…#18303)

* [GRPC] Optimize gRPC perf by passing by reference

Signed-off-by: Karen Xu <karenxyr@gmail.com>

* Use pattern matching with switch expression

Signed-off-by: Karen Xu <karenxyr@gmail.com>

---------

Signed-off-by: Karen Xu <karenxyr@gmail.com>
Signed-off-by: Andrew Ross <andrross@amazon.com>
Co-authored-by: Andrew Ross <andrross@amazon.com>
tandonks pushed a commit to tandonks/OpenSearch that referenced this pull request Aug 5, 2025
…#18303)

* [GRPC] Optimize gRPC perf by passing by reference

Signed-off-by: Karen Xu <karenxyr@gmail.com>

* Use pattern matching with switch expression

Signed-off-by: Karen Xu <karenxyr@gmail.com>

---------

Signed-off-by: Karen Xu <karenxyr@gmail.com>
Signed-off-by: Andrew Ross <andrross@amazon.com>
Co-authored-by: Andrew Ross <andrross@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement or improvement to existing feature or request Search:Performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] GRPC Performance Improvements

6 participants