hashicorp/yamux

What about the performance of yamux? It seems yamux speed down a lot of bandwidth.

liudanking opened this issue · 5 comments

I write a simple tcp tunnel with yamux, and test the speed:

  • Direct link (client --> server): 64mbps ~ 75mbps
  • yamux (default config) as a tunnel with 1 stream (client --> yamux client --stream--> yamux server --> server) : 24mbps ~ 28mbps

From the rough test above, we may conclude that yamux speed down a lot of bandwidth. Is there any methods that can improve throughtput yamux?

Hi @liudanking can you share any of your benchmarking code? There are a lot of things that could affect performance such as your payload size relative to the default window size, as well as how your receiver was performing (there's back pressure on the sender through the window mechanism). Yamux itself is pretty lightweight, but it is a TCP-style implementation so can have complex behavior in some cases.

@slackpad Thank you for your attention. The test I wrote is not a real benchmark. It is simple:

  • client opens a local listener, then copies data betweem yamux stream and local connection:
go io.Copy(localConn, yamuxStream)
io.Copy(yamuxStream, localConn)
// test only, we do not handle error and close
  • server also opens a listener, which accepts yamux session, for each yamux stream, it opens a connection to local :80 port. Then it copies data between yamux stream and connection of server :80 port:
go io.Copy(yamuxStream, local80Conn)
io.Copy(local80Conn, yamuxStream)

All yamux related code uses the default config.

The ping between client and server is about 60~80ms.

I run the test with 2 streams. And every stream reaches 24mbps ~ 28mbps. So I think yamux does NOT cost a lot of bandwidth, it just falls back to a safe speed to avoid stream congestion.

One thing that is strange: the stream speed is always 28mbps when speed becomes stable.

The problem to speed up stream speed is converted to how to optimize yamux stream window control algorithm just at @slackpad mentioned.

I try to set the yamux session with config of MaxStreamWindowSize = 2 * initialStreamWindow, but nothing is changed. Any ideas to optimize stream window control.

xtaci commented

highly concern on this

Just to chime in here a bit, ipfs uses yamux as the default stream multiplexer for all connections, on LAN connections i've seen some pretty impressive speeds (>100mbps). We do use many streams per transfer though, not just sending data over a single stream.