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

deserializeSafeFromHeader uses context.getHeader(headerName) instead of context.getHeaders() #2768

Merged
merged 2 commits into from
May 13, 2023

Conversation

parasjain1
Copy link
Contributor

@parasjain1 parasjain1 commented May 12, 2023

Description
Category: Performance Bug Fix

Why these changes are required?
HeaderHelper.deserializeSafeFromHeader is invoked O(segment) times during every search request and introduced a huge overhead. This optimisation has resulted in good gains with respect to search throughput and latency in our experiments.

Issues Resolved

Issues Resolved

Testing

  • Current test suite should pass.

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed 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.

Copy link
Contributor

@krishna-ggk krishna-ggk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are good - can you share the experiment results?

Comment on lines -60 to 62
String headerValue = null;

Map<String, String> headers = context.getHeaders();
if (!headers.containsKey(headerName) || (headerValue = headers.get(headerName)) == null) {
return null;
}

if (isInterClusterRequest(context) || isTrustedClusterRequest(context) || isDirectRequest(context)) {
return headerValue;
return context.getHeader(headerName);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is surprising that this small change makes a sizeable difference.

Copy link
Contributor Author

@parasjain1 parasjain1 May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are good - can you share the experiment results?

  • HeaderHelper.deserializeSafeFromHeader ‘s overall CPU usage dropped to 0.52% from 5%-12.5% seen across multiple CPU profiles obtained for prior runs.
  • Search Latency saw a drop of ~75%, Search Throughput increased by ~175%
  • Indexing Latency dropped by 70%, throughput increased by more than ~50%.

This was tested on a cluster running 3 m5.2xlarge data nodes with OS1.3

Results can vary based on the type of workload being executed.

@codecov
Copy link

codecov bot commented May 12, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@63aa098). Click here to learn what that means.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #2768   +/-   ##
=======================================
  Coverage        ?   61.33%           
  Complexity      ?     3409           
=======================================
  Files           ?      272           
  Lines           ?    18846           
  Branches        ?     3295           
=======================================
  Hits            ?    11560           
  Misses          ?     5686           
  Partials        ?     1600           
Impacted Files Coverage Δ
.../org/opensearch/security/support/HeaderHelper.java 60.00% <100.00%> (ø)

@cwperks
Copy link
Member

cwperks commented May 12, 2023

@parasjain1 Can you sign the commits?

@cwperks
Copy link
Member

cwperks commented May 12, 2023

@parasjain1 This change looks good to me. A lot less work is being done now by only reading a single header instead of reading all of the ThreadContext headers into memory on every request to deserializeSafeFromHeader. Great find! I approved the CI to let it run. Please sign the second commit when you get a chance.

@cwperks
Copy link
Member

cwperks commented May 12, 2023

Looking into the issue with plugin install. I suspect it could be related to this PR: opensearch-project/OpenSearch#7465

Edit: The minified distribution is outdated and does not include the change above yet. I will re-run the checks when updated artifacts are available.

Paras Jain added 2 commits May 12, 2023 20:26
…ead of `context.getHeaders()`

Signed-off-by: Paras Jain <parasjaz@amazon.com>
Signed-off-by: Paras Jain <parasjaz@amazon.com>
@parasjain1
Copy link
Contributor Author

@parasjain1 Can you sign the commits?

Done.

Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix @parasjain1 !!

@peternied peternied merged commit 7c4e06d into opensearch-project:main May 13, 2023
@peternied peternied added the backport 2.x backport to 2.x branch label May 13, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 13, 2023
…ead of `context.getHeaders()` (#2768)

(cherry picked from commit 7c4e06d)
peternied pushed a commit that referenced this pull request May 15, 2023
…ead of `context.getHeaders()` (#2768) (#2771)

(cherry picked from commit 7c4e06d)

Co-authored-by: Paras Jain <parasjain.jain@outlook.com>
stephen-crawford pushed a commit to stephen-crawford/security that referenced this pull request May 16, 2023
…ead of `context.getHeaders()` (opensearch-project#2768) (opensearch-project#2771)

(cherry picked from commit 7c4e06d)

Co-authored-by: Paras Jain <parasjain.jain@outlook.com>
sebastianmichalski pushed a commit to sebastianmichalski/security that referenced this pull request May 19, 2023
MaciejMierzwa pushed a commit to MaciejMierzwa/security that referenced this pull request Jun 13, 2023
…ead of `context.getHeaders()` (opensearch-project#2768)

Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
MaciejMierzwa pushed a commit to MaciejMierzwa/security that referenced this pull request Jun 13, 2023
…ead of `context.getHeaders()` (opensearch-project#2768)

Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
samuelcostae pushed a commit to samuelcostae/security that referenced this pull request Jun 19, 2023
samuelcostae pushed a commit to samuelcostae/security that referenced this pull request Jun 19, 2023
…ead of `context.getHeaders()` (opensearch-project#2768)

Signed-off-by: Sam <samuel.costa@eliatra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport to 2.x branch
Projects
None yet
5 participants