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

[TT-12702] revert wrappedServeHTTP to use recordDetail #6654

Merged
merged 7 commits into from
Oct 23, 2024

Conversation

jeffy-mathew
Copy link
Contributor

@jeffy-mathew jeffy-mathew commented Oct 18, 2024

User description

TT-12702
Summary Regression in Gateway handling larger payloads (speed and memory usage)
Type Bug Bug
Status In Dev
Points N/A
Labels customer_bug, jira_escalated

Description

This PR reverts https://github.com/TykTechnologies/tyk/pull/5716/files#diff-e6e07722257f7e41691e471185ad6d84fd56dc9e5459526ea32e9a5e8fa1a01bL518 - causing high memory consumption when handling large response payloads even when detailed recording is not enabled.

Related Issue

https://tyktech.atlassian.net/browse/TT-12702

Motivation and Context

How This Has Been Tested

Benchmarks

Master

goos: darwin
goarch: arm64
pkg: github.com/TykTechnologies/tyk/gateway
BenchmarkLargeResponsePayload-12               1        1733155792 ns/op        6423694584 B/op   170266 allocs/op
BenchmarkLargeResponsePayload-12               1        1045400334 ns/op        6423182768 B/op   162467 allocs/op
BenchmarkLargeResponsePayload-12               2        1056169500 ns/op        6150103228 B/op    81801 allocs/op
BenchmarkLargeResponsePayload-12               2         582477250 ns/op        6150050508 B/op    81405 allocs/op
BenchmarkLargeResponsePayload-12               2         544049688 ns/op        6150056996 B/op    81414 allocs/op
BenchmarkLargeResponsePayload-12               3         406709014 ns/op        6059011672 B/op    54435 allocs/op
BenchmarkLargeResponsePayload-12               3         408792639 ns/op        6059018274 B/op    54438 allocs/op
BenchmarkLargeResponsePayload-12               3         409801597 ns/op        6059023178 B/op    54441 allocs/op
BenchmarkLargeResponsePayload-12               3         432873930 ns/op        6059030749 B/op    54524 allocs/op
BenchmarkLargeResponsePayload-12               3         419910931 ns/op        6059010736 B/op    54438 allocs/op
BenchmarkLargeResponsePayload-12               3         441840542 ns/op        6059018002 B/op    54440 allocs/op
BenchmarkLargeResponsePayload-12               3         404177667 ns/op        6059027448 B/op    54449 allocs/op
BenchmarkLargeResponsePayload-12               3         408969153 ns/op        6059020826 B/op    54435 allocs/op
BenchmarkLargeResponsePayload-12               3         442027917 ns/op        6059023066 B/op    54480 allocs/op
BenchmarkLargeResponsePayload-12               3         425106861 ns/op        6059018101 B/op    54432 allocs/op
BenchmarkLargeResponsePayload-12               3         532385903 ns/op        6059022578 B/op    54506 allocs/op
BenchmarkLargeResponsePayload-12               3         426969986 ns/op        6059023218 B/op    54440 allocs/op
BenchmarkLargeResponsePayload-12               3         413833320 ns/op        6059027762 B/op    54450 allocs/op
BenchmarkLargeResponsePayload-12               3         451929514 ns/op        6237968360 B/op    54447 allocs/op
BenchmarkLargeResponsePayload-12               3         397716597 ns/op        6059025890 B/op    54445 allocs/op
PASS
ok      github.com/TykTechnologies/tyk/gateway  49.175s

PR branch

goos: darwin
goarch: arm64
pkg: github.com/TykTechnologies/tyk/gateway
BenchmarkLargeResponsePayload-12               1        1356068083 ns/op        4557237568 B/op   169981 allocs/op
BenchmarkLargeResponsePayload-12               2         742401458 ns/op        4283642056 B/op    81542 allocs/op
BenchmarkLargeResponsePayload-12               4         317117062 ns/op        4147070728 B/op    40949 allocs/op
BenchmarkLargeResponsePayload-12               4         298472167 ns/op        4147074542 B/op    40935 allocs/op
BenchmarkLargeResponsePayload-12               4         294437177 ns/op        4147072386 B/op    40935 allocs/op
BenchmarkLargeResponsePayload-12               4         309100688 ns/op        4147068268 B/op    40904 allocs/op
BenchmarkLargeResponsePayload-12               4         297184354 ns/op        4147070226 B/op    40925 allocs/op
BenchmarkLargeResponsePayload-12               3         486690125 ns/op        4192594322 B/op    54475 allocs/op
BenchmarkLargeResponsePayload-12               4         294243364 ns/op        4147069956 B/op    40900 allocs/op
BenchmarkLargeResponsePayload-12               4         297884250 ns/op        4147069348 B/op    40902 allocs/op
BenchmarkLargeResponsePayload-12               4         278709729 ns/op        4147068876 B/op    40887 allocs/op
BenchmarkLargeResponsePayload-12               4         292365864 ns/op        4147069428 B/op    40895 allocs/op
BenchmarkLargeResponsePayload-12               4         313283802 ns/op        4147065954 B/op    40902 allocs/op
BenchmarkLargeResponsePayload-12               4         314389510 ns/op        4147065562 B/op    40907 allocs/op
BenchmarkLargeResponsePayload-12               4         302698010 ns/op        4147069650 B/op    40905 allocs/op
BenchmarkLargeResponsePayload-12               4         303036000 ns/op        4147068274 B/op    40929 allocs/op
BenchmarkLargeResponsePayload-12               4         298318542 ns/op        4147065250 B/op    40897 allocs/op
BenchmarkLargeResponsePayload-12               3         358369500 ns/op        4192571469 B/op    54383 allocs/op
BenchmarkLargeResponsePayload-12               3         400718208 ns/op        4192586336 B/op    54380 allocs/op
BenchmarkLargeResponsePayload-12               3         348493847 ns/op        4192581192 B/op    54387 allocs/op
PASS
ok      github.com/TykTechnologies/tyk/gateway  55.063s

Benchstat

benchstat master.txt pr.txt              
goos: darwin
goarch: arm64
pkg: github.com/TykTechnologies/tyk/gateway
                        │  master.txt  │                pr.txt                │
                        │    sec/op    │    sec/op     vs base                │
LargeResponsePayload-12   429.9m ± 24%   306.1m ± 14%  -28.81% (p=0.000 n=20)

                        │  master.txt  │                pr.txt                │
                        │     B/op     │     B/op      vs base                │
LargeResponsePayload-12   5.643Gi ± 2%   3.862Gi ± 1%  -31.56% (p=0.000 n=20)

                        │ master.txt  │                pr.txt                │
                        │  allocs/op  │  allocs/op    vs base                │
LargeResponsePayload-12   54.45k ± 0%   40.93k ± 33%  -24.83% (p=0.000 n=20)

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

Bug fix


Description

  • Reverted the WrappedServeHTTP function call to use the recordDetail function, addressing a regression issue in handling larger payloads.
  • This change is aimed at improving speed and memory usage in the Gateway.

Changes walkthrough 📝

Relevant files
Bug fix
reverse_proxy.go
Revert WrappedServeHTTP to use recordDetail function         

gateway/reverse_proxy.go

  • Reverted the WrappedServeHTTP function call to use recordDetail.
  • Modified the argument passed to WrappedServeHTTP for improved request
    handling.
  • +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @buger
    Copy link
    Member

    buger commented Oct 18, 2024

    Knock Knock! 🔍

    Just thought I'd let you know that your PR title and story title look quite different. PR titles that closely resemble the story title make it easier for reviewers to understand the context of the PR.

    An easy-to-understand PR title a day makes the reviewer review away! 😛⚡️
    Story Title Regression in Gateway handling larger payloads (speed and memory usage)
    PR Title [TT-12702] revert wrappedServeHTTP to use recordDetail

    Check out this guide to learn more about PR best-practices.

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Functionality Change
    The change from a hardcoded boolean to a function call recordDetail(req, p.TykAPISpec) might alter the behavior of WrappedServeHTTP. Ensure this change aligns with expected functionality and does not introduce side effects.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Handle potential errors from the recordDetail function to enhance reliability

    Consider handling the error returned by recordDetail function to prevent runtime
    panics or unintended behavior if the function fails.

    gateway/reverse_proxy.go [518]

    -resp := p.WrappedServeHTTP(rw, req, recordDetail(req, p.TykAPISpec))
    +detail, err := recordDetail(req, p.TykAPISpec)
    +if err != nil {
    +    // handle error, possibly log and return
    +}
    +resp := p.WrappedServeHTTP(rw, req, detail)
    Suggestion importance[1-10]: 9

    Why: The suggestion to handle potential errors from the recordDetail function is highly relevant as it addresses a possible runtime issue. By checking for errors, the code becomes more robust and prevents unintended behavior, which is crucial for maintaining reliability in production environments.

    9

    Copy link
    Contributor

    API Changes

    no api changes detected

    @jeffy-mathew jeffy-mathew force-pushed the fix/TT-12702/redundant-copy-buffer-invocation branch from b1f5e5b to 4ecb4aa Compare October 20, 2024 21:11
    @jeffy-mathew jeffy-mathew force-pushed the fix/TT-12702/redundant-copy-buffer-invocation branch from 4ecb4aa to 177015b Compare October 21, 2024 11:31
    @jeffy-mathew jeffy-mathew requested a review from a team as a code owner October 22, 2024 09:22
    @jeffy-mathew jeffy-mathew enabled auto-merge (squash) October 22, 2024 09:22
    Copy link

    sonarcloud bot commented Oct 22, 2024

    Quality Gate Failed Quality Gate failed

    Failed conditions
    0.0% Coverage on New Code (required ≥ 80%)

    See analysis details on SonarCloud

    @lghiur
    Copy link
    Member

    lghiur commented Oct 23, 2024

    API tests failure, and Otel e2e failures are not related to this PR

    @lghiur lghiur disabled auto-merge October 23, 2024 16:41
    @lghiur lghiur merged commit 1fcb4fd into master Oct 23, 2024
    27 of 40 checks passed
    @lghiur lghiur deleted the fix/TT-12702/redundant-copy-buffer-invocation branch October 23, 2024 16:41
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    5 participants