- Packets and Streams
- Connections and Circuits
- Moving Networks
- New Socket Interfaces
- Summary
Connections and Circuits
SCTP provides some other more useful abstractions. Unlike TCP, which provides a single stream, SCTP introduces the idea of virtual circuits within each connection. These are independent and the protocol handles multiplexing for you.
The documentation refers to these as streams, but that's somewhat confusing because it also refers to TCP connections as streams. Unlike TCP streams, these send sequences of messages, rather than bytes.
Each virtual circuit is used to send messages with an order independent of the other connections. This is useful for improving throughput because it reduces the need for retransmission in cases of packet loss. If a TCP packet is dropped, then the packets after it need to be buffered at the receiving end until it has been retransmitted. If this buffer becomes full before the packet is retransmitted, then other packets will be dropped, and so on. Even if they aren't, then the increased round trip time will cause the rate limiting to reduce the transmit speed.
With SCTP, if one packet is dropped, then other packets in the same connection[md]but different streams[md]can be delivered to the receiving application without buffering. Take a web server as an example. When you open a web page, you generally load a single HTML document and a variety of other resources (images, scripts, and so on) from the server. There are three ways of doing this:
- Multiple TCP connections
- A single TCP connection, requesting each resource in turn
- A single SCTP connection, requesting each resource in a separate stream
The first option is quite expensive. Each TCP connection needs a separate handshake, which can take a good fraction of a second. It then needs resources in the server's kernel and userspace. If you add TLS on top, then you need to negotiate a separate TLS session for each connection, and you need to send things like headers in every single connection.
With a single connection, you avoid all of this overhead, but you don't necessarily get the best throughput and you can't so easily take advantage of parallelism at either end.
With SCTP, you get to interleave the streams for good performance and only have a single handshake. With some minor tweaks to the HTTP protocol, you can avoid sending cookies and other information that is the same with every request more than once. If you want TLS, then you only need to do an abbreviated handshake on the streams after the first one.