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

*: reduce memory allocation for plenty of idle connections #474

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

djshow832
Copy link
Collaborator

@djshow832 djshow832 commented Feb 7, 2024

What problem does this PR solve?

Issue Number: close #472

Problem Summary:
When there are many idle connections on a TiProxy instance, the CPU usage jitters every 2 minutes because of GC.

What is changed and how it works:

  • Replace time.After to time.Ticker
  • Replace sync.Map with map and sync.Lock
  • Other optimizations like header, salt

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Run and profile to see the frame graph and the overhead disappears.

alloc_objects:
alloc

inuse_objects:
inuse

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change
  • Has tiproxyctl change
  • Other user behavior changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

- Reduce GC CPU usage by 1% in the case of plenty of connections

@ti-chi-bot ti-chi-bot bot requested review from bb7133 and xhebox February 7, 2024 08:05
@ti-chi-bot ti-chi-bot bot added the size/L label Feb 7, 2024
@djshow832
Copy link
Collaborator Author

/retest

@ti-chi-bot ti-chi-bot bot removed the lgtm label Feb 20, 2024
Copy link

ti-chi-bot bot commented Feb 20, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xhebox

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the lgtm label Feb 20, 2024
Copy link

ti-chi-bot bot commented Feb 20, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-02-14 06:05:01.424832286 +0000 UTC m=+941626.991602177: ☑️ agreed by xhebox.
  • 2024-02-20 09:58:05.041829415 +0000 UTC m=+351173.789452525: ✖️🔁 reset by djshow832.
  • 2024-02-20 10:13:41.266714513 +0000 UTC m=+352110.014337625: ☑️ agreed by xhebox.

@codecov-commenter
Copy link

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@7443ce6). Click here to learn what that means.

Files Patch % Lines
pkg/proxy/net/packetio.go 0.00% 0 Missing and 2 partials ⚠️
pkg/proxy/net/packetio_mysql.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #474   +/-   ##
=======================================
  Coverage        ?   64.25%           
=======================================
  Files           ?       61           
  Lines           ?     5698           
  Branches        ?        0           
=======================================
  Hits            ?     3661           
  Misses          ?     1752           
  Partials        ?      285           
Flag Coverage Δ
unit 64.25% <84.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ti-chi-bot ti-chi-bot bot merged commit 5ca4fc1 into pingcap:main Feb 20, 2024
5 checks passed
@djshow832 djshow832 deleted the optimize_memory branch February 20, 2024 10:21
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.

Optimize memory usage of plenty idle connections
3 participants