Batch Connection to SSH servers problem

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
h_yardimci
Posts: 3
Joined: Mon 31 Mar 2008 07:11

Batch Connection to SSH servers problem

Post by h_yardimci » Mon 31 Mar 2008 08:37

Hi,

I wrote a simple program that connects to thousands of mikrotik RouterOS devices one by one.

Code: Select all

for i:=0 to count(device) do
 begin
   sshClient.hostname := device(i); // ip address
   sshClient.connect;

   sshShell.connect;
   sshShell.WriteString('ls'+#13#10);// or some other commands
   sshShell.disconnect;

   sshClient.disconnect;
 end;
Couple of problems occured;
1. after 80 or 100 connections, my cpu usage hits %100.. and i had to close and reopen the program. then everything is fine until another 80-100 connection. csrss.exe and my program shares the cpu usage. i read that csrss.exe file is used to establish the communication by windows.
it is like the disconnect statements dont close the actual connection and i get many connections open at the same time. and after some, my cpu can handle all of them. therefore i hit the maximum cpu usage. what should i do? is there anything to do with memory? any suggestions please?

2. i get the following error sometimes.. "A call to an OS function failed". i have no idea which fuction is that. it is unpredictable. i get it sometimes, but sometimes don't.

Please help.. thanks a lot.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Batch Connection to SSH servers problem

Post by Dimon » Mon 31 Mar 2008 12:45

We can not reproduce the problem.
Please let us know the version of your SSH server.

Try to execute the application without using TSSHShell, calling only sshClient.Connect and sshClient.Disconnect.
Also check if the problem appeas without calling sshShell.WriteString.

h_yardimci wrote:it is like the disconnect statements dont close the actual connection and i get many connections open at the same time.
The Disconnect method closes the connection and the used socket. It may be a problem on SSH server.

h_yardimci
Posts: 3
Joined: Mon 31 Mar 2008 07:11

Post by h_yardimci » Mon 31 Mar 2008 14:30

I dont know the version of the ssh server. They are Mikrotik RouterOS. they use SSH 2.0 protocol.

I tried to execute the program without TSSHShell, there were no errors..

then i tried to execute it with TSSHShell with sshShell.connect and sshShell.disconnect but without sshShell.WriteString. no errors again.

it seems that the error occurs when i try to send command (or write something) to server by using "WriteString".

i tried again with nonblocking := false; then executeCommand didnt work at all.

btw, i noticed that the error sometimes occurs after couple of connections, such as 5 or 10. I guess, that means it is not releated with system resources.

i am confused, i have no idea what really cause to that error.

what if i create the client and shell dynamic? do you think it helps?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 01 Apr 2008 07:29

h_yardimci wrote:I tried to execute the program without TSSHShell, there were no errors..
then i tried to execute it with TSSHShell with sshShell.connect and sshShell.disconnect but without sshShell.WriteString. no errors again.
If you try to connect to thousands of Mikrotik RouterOS devices one by one without calling sshShell.WriteString, does your application hit the maximum cpu usage?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 01 Apr 2008 07:29

h_yardimci wrote:btw, i noticed that the error sometimes occurs after couple of connections, such as 5 or 10. I guess, that means it is not releated with system resources.
Try to do a short pause after working with every device, like this:

Code: Select all

for i:=0 to count(device) do 
begin 
  ...

  sshClient.disconnect; 
  sleep(100);
end;
h_yardimci wrote:what if i create the client and shell dynamic? do you think it helps?
It is possible, you can try. But note that it may result in decreasing performance.

h_yardimci
Posts: 3
Joined: Mon 31 Mar 2008 07:11

Post by h_yardimci » Tue 01 Apr 2008 09:38

If you try to connect to thousands of Mikrotik RouterOS devices one by one without calling sshShell.WriteString, does your application hit the maximum cpu usage?
i solved the cpu problem with sleep and application.processmessages;
sshClient.disconnect;
sleep(100);
i already do that sleep and application.processmessages at the same time. Only sleep doesnt work at all. i had to use application.processmessages.

i noticed something. There were few writestring one after other. i modified the code a bit and now i have only one writestring statement for each ssh server. i tested like that, no error occured. it worked fine.

but i need to run more than one writestring for each device.. maybe i should wait little bit more betwwen each writestring

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 01 Apr 2008 10:59

Try to increase the waiting time after working with each device or increase the waiting time between each call to WriteString.
Also you can combine a few commands in one WriteString method.

Post Reply