8000 chore: reduce memory allocation on handling http response by fscnick · Pull Request #3800 · ray-project/kuberay · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: reduce memory allocation on handling http response #3800

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fscnick
Copy link
Contributor
@fscnick fscnick commented Jun 18, 2025

Why are these changes needed?

After getting response from ProxyActorHealth, the body is not used if the status is 200. It causes an unnecessary allocation.

Here are the simulation of code from benchmark.
before:
before

after:
after

Related issue number

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

Signed-off-by: fscnick <fscnick.dev@gmail.com>
@@ -57,10 +57,13 @@ func (r *RayHttpProxyClient) CheckProxyActorHealth(ctx context.Context) error {
if err != nil {
return err
}
defer resp.Body.Close()
defer func() {
io.Copy(io.Discard, resp.Body)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Read to EOF before closing it according to client.Do.

// If the returned error is nil, the [Response] will contain a non-nil
// Body which the user is expected to close. If the Body is not both
// read to EOF and closed, the [Client]'s underlying [RoundTripper]
// (typically [Transport]) may not be able to re-use a persistent TCP
// connection to the server for a subsequent "keep-alive" request.

Signed-off-by: fscnick <fscnick.dev@gmail.com>
@fscnick fscnick marked this pull request as ready for review June 20, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0