Repository navigation
crypto/tls: write the records of one write together - #2
Merged
Merged
Conversation
A write of more than one record sent every record with its own write to the connection, and the network stack is paid per write. The records of one write are now encrypted in place one behind the other and written together, up to eight full-sized records (about 128 KiB) at a time. Nothing is held back: all of it is written before the call returns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
writeRecordLockedsent every record of a write with a write of its own to the connection. A server's download writes 32–64 KiB at a time, i.e. 2–4 records, and the network stack is paid per write: on a loaded server most of the download time went towrite(2).The records of one write are now encrypted in place one behind the other and written together, up to eight full-sized records (about 128 KiB) per write. Nothing is held back: everything is written before the call returns, so latency is unchanged. A write of one record is still one write of that record; record sizes (including dynamic record sizing) are unchanged; handshake buffering (
c.buffering) still applies, since the group goes throughc.write. If encryption cannot work in place (the REALITY handshake padding in utls can grow a record past the reserve), the record is appended instead.Tests:
TestWriteCoalescesRecords(TLS 1.3, AEAD, CBC, stream ciphers, with and without dynamic record sizing: data intact, at most one write per ~8 records, no write over the limit),TestWriteSmallRecordsUnchanged.Used by Citrus (getmikan/Citrus perf/download-batching), with 64 KiB download reads. 4-core Docker bench, Citrus server, medians of 3, MB/s (CPU s/GB):