Mohamed El masri
Mohamed El masri

Reputation: 107

c# TCP exhaustion in multithreaded app

I’ve developed a c# .net 4 application which performs a WMI query on every computer in the organization (70,000+) on a daily basis. For reasons that are irrelevant to this thread I cannot run the app from a server, but rather from my Windows XP SP3 box. The app uses the threadpool with a new thread for each computer to query. My issue is that after the app is running for a short while I am exhausting all the available tcp connections resulting in “RPC errors”. One way I’ve been able to work around this is to put each thread to sleep for 120seconds after the query has been run. This particular solution is frustrating me as in most cases the query is performed and results processed within 5 – 10 seconds but I have to intentionally throttle each thread. The app is running for 15+ hours as apposed to the fraction of that time if each thread was not throttled. Any better ideas or advice on how to get around this problem?

Upvotes: 1

Views: 80

Answers (1)

TomTom
TomTom

Reputation: 62157

The app uses the threadpool with a new thread for each computer to query.

Bad design. I would switch if over to a queue with a specifi number of threads working off items here. THis is how for example IIS does it.

You likely expose the number of open connections somewhere (XP screams 32 bit to me - that is very limited).

Using a queue and less threads would avoid ressource exhaustion.

Upvotes: 1

Related Questions