Mehdi Akiki

Posts tagged "linux"

  • 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.
  • Published on

    Article · Through the layers

    WebSockets From the Wire Up

    Most WebSocket tutorials start at the API. This one starts at the wire — electrons, NIC interrupts, kernel socket buffers, the TCP state machine, the HTTP upgrade handshake, the binary frame format — and works up to what ws.send() actually does.