Mehdi Akiki

Posts tagged "following a tcp connection"

  • Published on

    Investigation · Part 5 of 10 · Following a TCP connection

    What a Full Socket Buffer Does to the Sender

    My sender wrote 2.6 MB to a peer that never read anything, and every send() said success. I looked where these bytes waited, what setsockopt really does to the buffer sizes, how a blocking sender is slowed down for free, and how an unbounded queue breaks this.
  • Published on

    Investigation · Part 4 of 10 · Following a TCP connection

    Why recv() Returns Less Than You Asked: TCP Is a Byte Stream

    Three send() calls arrived in one recv(), and one send() of 1 MiB arrived in seventeen. TCP keeps the bytes and their order, not the boundaries between your writes. I broke a small JSON reader with two inputs and fixed it with a length prefix and with lines.
  • Published on

    Investigation · Part 3 of 10 · Following a TCP connection

    Why a Small Write Can Wait 40 Milliseconds: Nagle and Delayed ACK

    My client wrote each request in two small pieces, and almost every request took 43 ms or more on loopback, where a round trip costs microseconds. I followed it with strace, ss and the kernel counters to see how Nagle's algorithm and delayed ACK wait for each other.
  • Published on

    Investigation · Part 2 of 10 · Following a TCP connection

    The Accept Queue: What Happens When a Server Accepts Too Slowly

    A successful connect() does not mean that the server program saw you. I filled the accept queue of a local server and watched clients connect, send data and wait, while the kernel kept their connections in a queue, half open, or nowhere at all.
  • Published on

    Investigation · Part 1 of 10 · Following a TCP connection

    What Happens When Your Program Calls connect()

    On my laptop connect() returns in about 8 microseconds, and the same call can also block for 133 seconds. I followed it with strace and ss: the handshake that the kernel does alone, a port where nobody listens, and a server that never answers.