C
Cliff
I've got a number of SNMP devices scattered around the globe that I
want to get some information off..
I've got a couple of classes whcih get a quite complex table together
from SQL and SNMP devices and return a DataTable Object.
but as the devices are all in totally different locations (we have
about 20) and the main time lag is due to latency I want to go and get
the data simultaniuously from all the resources.
Each individual table get takes between .25 and 2 seconds so
sequentially, the process takes about 8-10 seconds for 10 devices.
Having converted it to be multi threaded, it now takes 10-15 seconds.
(even when compiled as release code)
I've added some timing code to make sure it is running, but it seems
to take ages to get the threads started. I need to get this down to
2/3 seconds or it won't work.
Is there any way to speed up actually creating the threads, as that
seems to be taking 3 seconds alone!
Any help appreciated!
Cliff Dabbs
Here's the code
ArrayList arr = new ArrayList();
DateTime StartTime = DateTime.Now;
Debug.WriteLine("Starting To Launch Threads");
foreach (ASAVPN avpn in asavpns)
{
Debug.WriteLine("Launching Thread " +
avpn.DeviceName);
Thread th = new Thread(GetTable);
arr.Add(th);
th.Start(avpn);
}
foreach (VPN3000 kvpn in v3kvpns)
{
Debug.WriteLine("Launching Thread " +
kvpn.DeviceName);
Thread th = new Thread(GetTable);
arr.Add(th);
th.Start(kvpn);
}
TimeSpan ts = DateTime.Now.Subtract(StartTime);
Debug.WriteLine("Launch of Threads " + ts.ToString());
//Wait until the threads end;
bool moveon = true;
do
{
Thread.Sleep(100);
moveon = true;
foreach (Thread th in arr)
if (th.ThreadState ==
System.Threading.ThreadState.Running)
moveon = false;
}
while (moveon == false);
DataView dv = new DataView(dt1);
this.dataGridView1.DataSource = dv;
}
public void GetTable(object data)
{
lock (data)
{
DataTable dt;
string devicename = ((SNMPDevice)(data)).DeviceName;
DateTime StartTime = DateTime.Now;
Debug.WriteLine("Starting Thread Work: " +
devicename);
if (data.GetType() == typeof(ASAVPN))
dt = ((ASAVPN)(data)).SessionTable;
else
dt = ((VPN3000)(data)).SessionTable;
TimeSpan ts = DateTime.Now.Subtract(StartTime);
Debug.WriteLine("Ending Thread Work " + devicename + "
" + ts.ToString());
lock (this.ds.Tables["vpninfo"])
{
this.ds.Tables["vpninfo"].Merge(dt, true,
MissingSchemaAction.Add);
}
}
}
want to get some information off..
I've got a couple of classes whcih get a quite complex table together
from SQL and SNMP devices and return a DataTable Object.
but as the devices are all in totally different locations (we have
about 20) and the main time lag is due to latency I want to go and get
the data simultaniuously from all the resources.
Each individual table get takes between .25 and 2 seconds so
sequentially, the process takes about 8-10 seconds for 10 devices.
Having converted it to be multi threaded, it now takes 10-15 seconds.
(even when compiled as release code)
I've added some timing code to make sure it is running, but it seems
to take ages to get the threads started. I need to get this down to
2/3 seconds or it won't work.
Is there any way to speed up actually creating the threads, as that
seems to be taking 3 seconds alone!
Any help appreciated!
Cliff Dabbs
Here's the code
ArrayList arr = new ArrayList();
DateTime StartTime = DateTime.Now;
Debug.WriteLine("Starting To Launch Threads");
foreach (ASAVPN avpn in asavpns)
{
Debug.WriteLine("Launching Thread " +
avpn.DeviceName);
Thread th = new Thread(GetTable);
arr.Add(th);
th.Start(avpn);
}
foreach (VPN3000 kvpn in v3kvpns)
{
Debug.WriteLine("Launching Thread " +
kvpn.DeviceName);
Thread th = new Thread(GetTable);
arr.Add(th);
th.Start(kvpn);
}
TimeSpan ts = DateTime.Now.Subtract(StartTime);
Debug.WriteLine("Launch of Threads " + ts.ToString());
//Wait until the threads end;
bool moveon = true;
do
{
Thread.Sleep(100);
moveon = true;
foreach (Thread th in arr)
if (th.ThreadState ==
System.Threading.ThreadState.Running)
moveon = false;
}
while (moveon == false);
DataView dv = new DataView(dt1);
this.dataGridView1.DataSource = dv;
}
public void GetTable(object data)
{
lock (data)
{
DataTable dt;
string devicename = ((SNMPDevice)(data)).DeviceName;
DateTime StartTime = DateTime.Now;
Debug.WriteLine("Starting Thread Work: " +
devicename);
if (data.GetType() == typeof(ASAVPN))
dt = ((ASAVPN)(data)).SessionTable;
else
dt = ((VPN3000)(data)).SessionTable;
TimeSpan ts = DateTime.Now.Subtract(StartTime);
Debug.WriteLine("Ending Thread Work " + devicename + "
" + ts.ToString());
lock (this.ds.Tables["vpninfo"])
{
this.ds.Tables["vpninfo"].Merge(dt, true,
MissingSchemaAction.Add);
}
}
}