I was reading a proposal written by Roger and Nick about the 2nd Generation onion router and noticed that they mentioned in the previous design, onion routing could only build a circuit for every application-level request whereas in the new design, tor is able to multiplex multiple TCP streams along each circuit. So I was wondering how does tor build circuits? Does tor build a circuit for every cell? every SOCKS proxy?
Tor builds circuits and then attaches "streams" to those circuits. For example tor might create a circuit "TorProxy -> A -> B -> C" (where A/B/C are relays), and then later can attach multiple streams to those circuits, for example "Firefox -> TorProxy -> A -> B -> C -> ServerA" and "Git -> TorProxy -> A -> B -> C -> ServerB". This is what is meant by "multiplex multiple TCP streams along each circuit". Each stream is an application connection (a TCP connection). There are rules specifying which streams get attached to which circuits.
Does tor build a circuit for every cell? every SOCKS proxy?
Neither; tor builds circuits ahead-of-time and assigns streams to those circuits as needed. If tor runs out of circuits and there's a new incoming application connection, tor will build a circuit for it and assign this stream to the circuit.