Click here to Skip to main content
14,453,689 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi ,
I am working on a monitoring project that it monitor different targets including (Switch,Router,PC ,…) in their specific interval(mostly 60 seconds) via SNMP . depending on the number of elements that is going to be monitored, some of the monitoring processes take long time maybe more than 30 seconds .the problem appear when the number of targets are more than 2000 and majority of the monitoring operations take long time .in this occasion monitoring operations is because apparently there is no available thread to allocate them while the cpu has four cores.i tried below options.
I found that there is gap between when monitor come into queue and when it really start to fact , ( startMonitoringOperation – startMonitoring ) = big interval
This big interavel could be more than 2 minute.
I want to know what is the best practice for synchronous long-running Process .How I can decrease the gap I have mentioned before.

for (int I = 0 ;MonitorsQueue.Count;i++) 
   Var startMonitoring = DateTime.Now;
   1.Threadpool.QueueUserWorkItem(new System.Threading.WaitCallback(DoMonitor),monitorObject);
   2.var task = new task(() => DoMonitor(monitorObject),TakeCreationOptions.LongRuning);
   3. var task = new task(() => DoMonitor(monitorObject));
Private void DoMonitor() //this Method take long in some occasions 
     Var startMonitoringOperation = DateTime.Now;
     //Monintoring Operation
Updated 16-Feb-15 21:31pm
It depends, but generally, the answer is: a separate thread. Isn't that pretty obvious?
BillWoodruff 17-Feb-15 6:58am
Seems obvious you have to a Thread Pool, and a queue, and manage them.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Sounds like threadpool starvation. There simply aren't enough threads.

But you have to ask, does it makes sense to have 2000 concurrent network operations? I would think without some sort of offloading arrangement that'd be enough to grind the CPU to a standstill just in the kernel, before you even get to your code. Maybe, depending on the flow of traffic.

Two ways to go. You could try to increase the number of threads in the threadpool but I find this idea quite scary.

The better approach would be to switch to asynchronous IO. The idea here is that you don't have threads which are blocked waiting for network activity. Instead the thread starts the network operation and then gets reused to do other stuff until such time that the response comes back which will then be handled by a different thread.

If you think about it, a network connection is an abstraction - what really happens is flows of packets of data out of and into your adapter.

Have a look at Port Completion threading. Use Begin/End methods and callbacks to implement the actual SNMP part.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100