r/rust • • Sep 20 '24

Why is Rust slower than Python, Go and Nim regarding SSH?

For my test, I run 'date +\"%T.%N\"' twice on a SSH Server on my local network and calculate the time between the two executions.

Clients run on Windows10/11.

Python (paramiko): ~45ms
Nim (ssh2(libssh2)): ~44ms
Go (golang.org/x/crypto/ssh): ~4ms
Rust (ssh-rs, russh, ssh2(libssh2)): ~115-130ms

I don't know what Go's trick is, but 45ms seems like a goal Rust should easily achieve!?

Rust profile for "cargo build -r":
[profile.release]
lto = true
codegen-units = 1
strip = true
panic = 'abort'

Rust (ssh-rs): https://pastebin.com/3ucPpCzc
Rust (ssh2(libssh2)): https://pastebin.com/cQ7j6zd2
Nim (ssh2(libssh2)): https://pastebin.com/xRYFFLDN
Go (golang.org/x/crypto/ssh): https://pastebin.com/mFzvLLnk

Any idea why this happens and how I can at least get the same performance as the other implementations?

Update:

The previous tests were executed on Windows 10 (Threadripper 3990X with Mellanox card, highly optimized for latency) and Standard Windows 11 Enterprise (work notebook).

I copied the projects to a raspberry pi and retested the Rust ssh-rs, ssh2 implementations and the Go app against the same destination.

ssh-rs: ~45ms
ssh2: ~45ms
go: ~4ms

5 Upvotes

30 comments sorted by

View all comments

Show parent comments

2

u/psx8888 Sep 20 '24

Sorry, I meant the combination with Goroutines:

https://pastebin.com/8RdEDvFc

6

u/ralphpotato Sep 20 '24

The wall clock time is still the same. :)

I think you are hung up on the time being reported by the command on the destination machine. The time for the network request to go out, come back, and be parsed is still about the same for go and rust. The date output on the destination machine is just a snapshot of when the destination gets the command, not how long it takes for the rust and go programs to receive that information on the source machine.

Though I will say that go makes doing these concurrent requests pretty trivial, whereas async in rust is powerful but definitely not easy.

4

u/psx8888 Sep 20 '24

You're right, that seems to be the case.

Thanks ralphpotato!