Yury Korobkin
Yury Korobkin

Reputation: 115

Concurrent and interruptible DNS name resolution of multiple names seems impossible

I need to quickly test a list of ~100 web servers for connectivity. Quickly means around 5 seconds for the whole bunch. If a server is inaccessible for about 2-3 seconds, it should be skipped. If there's no internet connection - the test should fail quickly - 2-3 seconds. It should run on XP (SP2) and up.

I decided to run a test procedure for each server in a separate thread.

Synchronous test procedure does the following:

This is no good:

Asynchronous test procedure:

This one is also no good because WSAAsyncGetHostByName() "is not designed to provide parallel resolution of several names" (MSDN). And so, it does sequential resolution even when called from multiple threads. This makes the threads run sequentially defeating their purpose.

Hence my problem: either blocking calls that cannot be interrupted or asynchronous calls that can't be paralellized.

Seems to me that the only option is to do the blocking calls in separate threads, and if a thread does not finish quickly enough - murder it with TerminateThread().

Anything better than that?!

Upvotes: 2

Views: 287

Answers (1)

Yam Marcovic
Yam Marcovic

Reputation: 8141

I'm not sure this fits your model, but maybe you can resolve the IP addresses of the hostnames once, as a cold start kind of thing, and then cache them.

That way, you avoid having to use WSAAsyncGetHostByName which is the bottleneck, and you only need to test out the HTTP communication.

Now, assuming you have reason to suspect that a certain host has changed its IP address since you last resolved it (say, the destination was unreachable, or the connection refused), you can simply run a query again for that host.

Upvotes: 1

Related Questions