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

backend, net: optimize read/write connection by forwarding packets #391

Merged
merged 8 commits into from
Nov 2, 2023

Conversation

djshow832
Copy link
Collaborator

@djshow832 djshow832 commented Oct 30, 2023

What problem does this PR solve?

Issue Number: close #381

Problem Summary:
The performance is still not good enough. We can just forward the packets between connections and avoid allocating memory and copying data.

What is changed and how it works:

  • Add PacketIO.ForwardUntil and call it in CmdProcessor.forwardUntilResultEnd. ForwardUntil only allocates memory in the last packet. ForwardUntil mainly calls Writer.ReadFrom to copy data between reader and writer.
  • Copy Golang bufio.go to TiProxy because Writer.ReadFrom always calls TCPConn.ReadFrom, which calls sys calls and skips the buffer. We always need the buffer and I can't find a replacement of bufio.
  • Add ReadFrom for all the packetReadWriter implementations.
  • Modify the parameters of IsXXXPacket because we only know the length and first byte if we do the optimization.
  • Optimize compressedReadWriter.Peek to avoid allocating memory.
  • Add proxyReadWriter.Peek. It was a bug not to add this function.

Check List

Tests

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

Sysbench Result

Before this PR (with conn-buffer-size=131072):

Range size QPS TiProxy CPU QPS per 100% CPU
10 32818 150% 21878
100 22392 190% 11785
1000 4093 200% 2046
10000 449 200% 224

After this PR (with conn-buffer-size=131072):

Range size QPS TiProxy CPU QPS per 100% CPU
10 31430 130% 24176
100 23680 150% 15786
1000 6281 160% 3925
10000 707 140% 505

Flame Graph

image

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.

None

@ti-chi-bot ti-chi-bot bot added size/XXL and removed size/L labels Nov 1, 2023
@djshow832 djshow832 marked this pull request as ready for review November 1, 2023 07:58
Copy link

ti-chi-bot bot commented Nov 2, 2023

[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 Nov 2, 2023
Copy link

ti-chi-bot bot commented Nov 2, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-11-02 03:25:31.109708043 +0000 UTC m=+3096328.696818187: ☑️ agreed by xhebox.

@ti-chi-bot ti-chi-bot bot added the approved label Nov 2, 2023
@ti-chi-bot ti-chi-bot bot merged commit c7ea81a into pingcap:main Nov 2, 2023
9 checks passed
@djshow832 djshow832 deleted the optimize_readwrite branch November 2, 2023 03:30
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.

Performance gap between TiProxy and HAProxy grows as the dataset size grows
2 participants