Today’s issue is a weird one that I don’t really understand.
First let’s begin with the code:
let tcp = TcpStream::connect("127.0.0.1:22").unwrap(); let mut sess = Session::new().unwrap(); sess.handshake(&tcp).unwrap(); sess.userauth_password("account", "password").unwrap(); let sftp = sess.sftp().unwrap();
Library used: ssh2
This code works fine.
BUT the goal of using Rust for my own server as a backend was to learn Rust and gain or have the same performance as PHP.
The issue is:
- PHP does the connection in 0.03 seconds (which seems fine as it is on the same computer)
- Rust does the connection in 0.3 seconds (Yes, 10 times slower)
I guess this either comes from the wrapper or from libssh2 itself (which I don’t know how to test)
Does any of you could guide on what is going on here ? Maybe someone knows how to use libssh2 in C and calculate the time it takes on Rust and on C ?
I have tried to see if it was optimization so I ran it with “cargo run --release” but nothing changed.
My idea to go around this issue was to keep the user connected for as long as he is connected to the website (this means that the connection is not drop at all between request, which I don’t really like)
I manly wanted to use the ssh2 library because it has sftp functions and I wanted to use those.
I will try out thrussh to see if it works better but I have no idea yet on how I will manage file transfer with thrussh…
Thanks in advance!
EDIT: Just tested out with my laptop. same exact result (almost). I got 0.2 seconds. Still way too much compared to the 0.03 of PHP (tested with a local rust and local ssh server, just like my server/website setup)