python-trio / python-trio/trio
SSL: optimize handling of packets/framing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
There are (at least) two subtle ways that our current SSL code is slightly inefficient:
-
Sometimes, it may happen the side the finishes the handshake is also the first to speak, and in this case it's slightly less overhead if the first data frame goes out in the same packet as the end of the handshake. (When this actually happens is complicated; it depends on which side speaks first, whether we're starting a new session or resuming and old one, and which version of TLS is in use.) What we could do is to have a kind of "cork" option, where if
send_alltriggers the handshake then it tells_retryto leave the last set of bytes-to-send in the buffer (if any), where they'll immediately get flushed out by the next call to_retry. (Note: this doesn't help if callingdo_handshakeexplicitly; not sure there's much we can do about that.) -
Currently, the user hands
SSLStream.send_allchunks of data of whatever size, and then we let openssl break them into records. I believe that by default it will use the largest possible records (16 KiB). This is not necessarily the best approach. Even thoughssldoesn't expose any specific knobs for this, I think each call toSSLObject.writehas to generate a complete record, so we could do it by tracking the optimal record size and manually breaking data into pieces of that size before passing them towrite. (Maybe with a bit of trickiness if we want to rejoin it all before callingsend_allon the transport. Or maybe this doesn't really matter.)Also I guess if we're piggybacking on the end of a handshake, that should be taken into account when calculating the optimal size for the first record.
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 tracing SSLStream.send_all, _retry, do_handshake, and the SSLObject.write calls involved in handshake and record transmission. Establish how handshake output and application data are buffered, then define tests and completion criteria for handshake piggybacking and manually sized TLS records before attempting the optimization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100