pingcap/tidb

Avoid double-copy buffer when responding MySQL packets

Open

#32.097 geöffnet am 3. Feb. 2022

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Go (6.186 Forks)batch import
help wantedtype/enhancementtype/performance

Repository-Metriken

Stars
 (40.090 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 14T 4h) (346 gemergte PRs in 30 T)

Beschreibung

Enhancement

When we want to return the packages to the client, our logic is:

  1. Prepare the packet and serialize it to a buffer allocated by the area.Allocator
  2. Write this data through packetIO.WritePacket, in the WritePacket, the data will be cached in a buffer writer
  3. Flush the buffer writer to the connection

Mostly, e.g, for write ok https://github.com/pingcap/tidb/blob/0c19f927419f6b043a345e4a2af5336272830229/server/conn.go#L1442, we can see that we don't need to double copy the buffer, we can serialize the data and write it directly to the connection.

Contributor Guide