mplex
On this page
What is mplex?
mplex is a simple stream multiplexer that was designed in the early days of libp2p. It is a simple protocol that does not provide many features offered by other stream multiplexers. Notably, mplex does not provide flow control, a feature which is now considered critical for a stream multiplexer.
mplex runs over a reliable, ordered pipe between two peers, such as a TCP connection. Peers can open, write to, close, and reset a stream. mplex uses a message-based framing layer like yamux, enabling it to multiplex different data streams, including stream-oriented data and other types of messages.
Drawbacks
mplex is currently in the process of being deprecated (to track progress please see this issue). mplex does not have any flow control.
Backpressure is a mechanism to prevent one peer from overwhelming a slow time consuming the data.
mplex also doesn’t limit how many streams a peer can open.
If you need a dedicated muxer, Yamux should be used (overall, QUIC should be preferred over TCP).. Yamux natively supports flow control, it is better suited for applications that require the transfer of large amounts of data.
Until recently, the reason mplex was still supported was compatibility with js-libp2p, which didn’t have yamux support. Now that js-libp2p has gained yamux support, mplex should only be used to provide backward-compatibility with legacy nodes.