Optimize CPU usage when creating short connections frequently
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 73
- Forks
- 41
- Avg merge
- 21h 3m
- Merged PRs (30d)
- 21
Description
Development Task
When the client creates and destroys 300 connections per second, the CPU usage of TiProxy is up to 30%.
The main overhead is dialing the backend and forwarding messages during handshake. We may need a connection multiplex to optimize it.
However, we can do some minor optimizations without touching the architecture:
- Reuse memory in
bufio.NewReaderSize(),bufio.NewWriterSize(), andreadOnePacket. - Save on-stack memory to avoid allocating a new stack in
handshakeFirstTime.
The overall frame graph:
Allocate duplicate memory:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by profiling the short-connection path around handshakeFirstTime, readOnePacket, and the bufio.NewReaderSize()/NewWriterSize() calls, using the supplied CPU and allocation graphs as context. Measure the current allocation and CPU costs, then verify that memory reuse and reduced stack allocation improve frequent connection creation without changing handshake behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, networking, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100