Put on the right path, tell me what can be done / read about it?
There is a list of objects of type IP.
class IP { public string host; public string login; public string password; }
And the method that iterates through this list in a parallel loop, in which there is a connection to SSH.
public void Cycle() { int port = 22; Parallel.ForEach(ipList, ipObject => { string ip = ipObject.host; string login = ipObject.login; string password = ipObject.password; SshConnect(ip, port, login, password); }); }
The SSHConnect
method SSHConnect
implemented using the Renci.SSHNet library. As follows:
private bool SshConnect(string host, int port, string login, string password) { bool flag = true; try { var client = new SshClient(host, port, login, password); client.Connect(); client.Disconnect(); } catch { flag = false; } return flag; }
Everything would be fine, but the speed of searching and connecting to SSH is terribly slow. What can be done to increase the speed?
PS I used to have an algorithm that worked at least 2 times faster than this.
In it, I used one thread in which there was a loop, iterating the list, and in the same thread a certain number of other threads were created, which in turn processed these list items.
At another forum, they said that it was undesirable to do this and read a little, I decided to try Paralel.ForEach
, but the result did not meet expectations.
SshConnect()
methodSshConnect()
have the ability to work in parallel threads? - The_Netos