I want to establish an API server with a load balancer. I will use one machine as the master which will assign tasks in a round robin manner to 2 slave machines. All machines are hosted in AWS.
In order to process the request, I need to run a python script. When the master receives the request, it can trigger the command on one of the slaves using ssh but this adds an extra couple of seconds delay to the processing time.
Is there a way to reduce/remove the ssh delay?
Not sure if you have something implemented or you just collect the thoughts.
The basic use case is described on wikibooks, but the easiest is to set up public key authentication and
ssh_config
(config formachine2
would be almost the same):And then call the remote script like this:
First
ssh
call will initiate the connection (and will take a bit longer), every other script call will use the existing connection and will be almost immediate.If you are using Python, the similar behaviour you can achieve using
paramiko
or evenansible
if you want to step one level up (but really depends on use case).