[rust-dev] net::tcp::TcpSocket slow?
banderson at mozilla.com
Thu Dec 20 18:12:22 PST 2012
On 12/20/2012 05:58 PM, Michael Neumann wrote:
> I am writing a redis client  for rust but somehow TCP performance
> seems to be veery slow. I basically just sent a string
> to redis and read the response (I commented out parsing). Doing this
> 10_000 times takes about 4.5 seconds, while doing the same in Ruby
> takes just 0.7 seconds.
> Is there anything I can do about it, or is this a known issue?
Thanks for doing that test. I've been curious. Your results don't
suprise me though - std::net needs a lot of work still. I can imagine
what some of the problems are.
First, stack switching. Switching between Rust and C code has bad
performance due to bad branch prediction. Some workloads can spend 10%
of their time stalling in the stack switch.
Second, working with uv involves sending a bunch of little work units to
a dedicated uv task. This is because callbacks from uv into Rust *must
not fail* or the runtime will crash. Where typical uv code runs directly
in the event callbacks, Rust dispatches most or all of that work to
other tasks. This imposes significant context switching and locking
On top of that, all the uv-based code is using the old,
lower-performance communication primitives in `core::oldcomm`. These
need to be converted to `core::pipes`, but there are some additional
blockers preventing it.
If anybody wants to improve std::net I can help point out the various
More information about the Rust-dev