[GRPC] Optimize gRPC perf by passing by reference#18303
[GRPC] Optimize gRPC perf by passing by reference#18303andrross merged 4 commits intoopensearch-project:mainfrom
Conversation
|
❌ 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? |
...ain/java/org/opensearch/plugin/transport/grpc/proto/response/common/ObjectMapProtoUtils.java
Outdated
Show resolved
Hide resolved
5cfc899 to
a062e83
Compare
...in/java/org/opensearch/plugin/transport/grpc/proto/response/search/SearchHitsProtoUtils.java
Show resolved
Hide resolved
|
❌ 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>
8114025 to
444f1ec
Compare
|
❕ 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 ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
...in/java/org/opensearch/plugin/transport/grpc/proto/response/common/FieldValueProtoUtils.java
Outdated
Show resolved
Hide resolved
...opensearch/plugin/transport/grpc/proto/response/document/common/DocumentFieldProtoUtils.java
Show resolved
Hide resolved
...ain/java/org/opensearch/plugin/transport/grpc/proto/response/search/SearchHitProtoUtils.java
Show resolved
Hide resolved
...ain/java/org/opensearch/plugin/transport/grpc/proto/response/common/ObjectMapProtoUtils.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Karen Xu <karenxyr@gmail.com>
fd0e65d to
9ee0743
Compare
Signed-off-by: Andrew Ross <andrross@amazon.com>
...in/java/org/opensearch/plugin/transport/grpc/proto/response/common/FieldValueProtoUtils.java
Show resolved
Hide resolved
|
I rebased and fixed the changelog conflict. This is ready to merge once all tests pass. |
|
❌ 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? |
…#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>
…#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>
…#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>
…#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>
…#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>
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
Results
Testing (using Ballast, an internal perf testing tool) shows a small but consistent latency and CPU reduction with this change
Latency

CPU usage

Raw data
[Before] GRPC without change
[After] GRPC with pass by reference
Conclusions
Latency reduction: GRPC with pass reference has consistently lower latency for both first and subsequent requests compared to GRPC no change.
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
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.