Shell latency
ValeKnappich opened this issue · 3 comments
Hi, I have started using this package and I think its great!
While working on the console, I noticed quite a bit of a latency (letters appear about 100-200ms after typing).
Is that normal? Do yo have an idea how to tackle it? I dont know if thats relevant, but im located in germany.
Cheers.
Hello @ValeKnappich,
Sorry for the inconvenience, unfortunately the latency is due to the fact that the SSH connection passes by the cloudflare servers (since we are using cloudflared). In other words, this is the route for the cloudflared SSH connection:
your machine <----------> cloudflare <----------> Google Colab Virtual Machine
While direct SSH connection has the following route:
your machine <----------> Google Colab Virtual Machine
The bad news
The bad news is that we don't officially support direct SSH connection yet because it's a bit delicate to use and has some security risks.
The good news
The good news, it's implemented already. There is no documentation on how to use it. But to solve your problem here's how I use it:
⚠️ Caution⚠️ : This may not reduce latency, because it depends on a lot of factors
⚠️ Caution⚠️ : Do not do these steps if you don't know what you are doing. Opening an SSH port and allowing passwords may expose you to security threats
- First open your SSH port through your router. For example from port
22
of your machine to port5000
of the router. the5000
is theYOUR_OPEN_PORT
Check if your port is open using this online tool
- Create a private/public key pair on the Google Colab VM
- Make sure you copy the public key that you generated to your
authorized_keys
files (This will allow Google Colab to access your machine through the open SSH port) - Put this code in your Google Colab notebook. This function will:
- Connect to your machine
- Copy your public key to the
authorized_keys
file on google colab - Start the SSH server
from colab_ssh.launch_direct_ssh import launch_direct_ssh
launch_direct_ssh("<YOUR_USERNAME>", "<YOUR_IP_ADDRESS", "<YOUR_OPEN_PORT>", reverse_ports=["6022:127.0.0.1:22"], public_key_path="<YOUR_PUBLIC_KEY_PATH_ON_YOUR_MACHINE>")
YOUR_IP_ADDRESS
This is ip address of your local machine (you can type "What is my ip" on Google)127.0.0.1:22
is the internal address and port of the SSH server on Google Colab6022
is the local port that will let you connect to Google Colab from your machineYOUR_PUBLIC_KEY_PATH_ON_YOUR_MACHINE
By default it's%USERPROFILE%/.ssh/id_rsa.pub
(supports windows by default). You can change this path to/root/.ssh/id_rsa.pub
for example to support Linux.
- Now, you just need to use the command ssh to test the connection by executing the following command
ssh root@127.0.0.1 -p 6022
or use this configuration in your ~/.ssh/config
file
Host GoogleColab
HostName 127.0.0.1
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
User root
Port 6022
This is called ssh reverse tunnel. I hope this helps :)
Hi @WassimBenzarti ,
thanks for the very detailed answer! I'll give it some consideration given the caveats and maybe try it.
Just one more, completely off-topic question:
It is a common problem that colab disconnects you quickly when being inactive and normally you would paste a js snippet in the console to click the connect button. Do you plan on including a function in the repo that automates this?
Cheers
I remember there was a discussion about this, I think it's in this issue #13. Check it out and tell me if you have any further questions or suggestions.
You can start a new discussion in the discussions page (on Github) if you feel that we missed something. And if you feel that we need to provide this feature you can share with us a working code snippet to see if it's still feasible.
I think I will close this issue for now, you can reopen it whenever you have a problem.
Thank you for your input and suggestions :)