473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multithreading with DirectoryServices

I'm doing a standard AD query to retrieve a list of workstations that
match certain criteria. I would like to iterate through that list and
see if the workstations are still on the network and have correct dns
records. Part of the difficulty is that the ping & dns check takes
roughly 100ms. This makes my app take rather long as it needs to check
thousands of workstations. I'm hoping multithreading can boost the
speed.

I would like to create several threads (say 10), each that will take a
name off the master list (as a SearchResultCollection), run the
ping/dns check, then output to the main log (a textfile). I'm having
trouble even coming up with the logic on how to do such a thing. How do
I create 10 threads, take a name "off the top" of the result
collection, pass it to each new thread's sub (making sure to take a new
name off the top for each new thread), then fire a new thread as the
previous one completes so my maximum number of threads running
concurrently is 10?

Thank you kindly.
Jason

Dec 21 '06 #1
6 1208

if you can't rely on ping and dns.. you need to get a better DNS server
shit throw away windows if you're going to be that anal

-Aaron

Celldss wrote:
I'm doing a standard AD query to retrieve a list of workstations that
match certain criteria. I would like to iterate through that list and
see if the workstations are still on the network and have correct dns
records. Part of the difficulty is that the ping & dns check takes
roughly 100ms. This makes my app take rather long as it needs to check
thousands of workstations. I'm hoping multithreading can boost the
speed.

I would like to create several threads (say 10), each that will take a
name off the master list (as a SearchResultCollection), run the
ping/dns check, then output to the main log (a textfile). I'm having
trouble even coming up with the logic on how to do such a thing. How do
I create 10 threads, take a name "off the top" of the result
collection, pass it to each new thread's sub (making sure to take a new
name off the top for each new thread), then fire a new thread as the
previous one completes so my maximum number of threads running
concurrently is 10?

Thank you kindly.
Jason
Dec 21 '06 #2
I appreciate the constructive reply Aaron. I'll go tell the director
that we're doing away with Windows. Would anyone else mind offering
some advice?

Dec 21 '06 #3
i just don't understand; in the big scope of things-- why do you need
to go to each desktop and run a ping?

because you connection used to drop?

because you have underlying DNS failures?

I think that what you're trying to do is about 100 times more complex
than it needs to be.
if your DNS services aren't reliable; then bring in a expert to rebuild
your server

you're talking about all of this complexity; and I just think that it's
ridiculous that you're talking about making each box ping the central
server once every 10 mins or something?

I just think that if you suspect that you have DNS failures; then you
should go the other way.

if you want to ping 100 desktops from 1 central location; I could do it
in a DTS package in about 30 seconds without dealing with any of your
crap

-Aaron

Celldss wrote:
I appreciate the constructive reply Aaron. I'll go tell the director
that we're doing away with Windows. Would anyone else mind offering
some advice?
Dec 21 '06 #4
With carefully crafted threading and 10 workers, you will certainly get a
'speed' boost but it certainly will not be anything like 10 times as fast.
There are other factors involved, (network latency, machine load, etc.),
that are outside of the control of your program.

The first issue is how do you supply the data to each worker thread. A good
mechanism for this is a Queue object. Each item from your
SearchResultCollection can be Enqueued and then each worker thread can
Dequeue the next Queue item as it needs it.

The basic logic for the worker object would be something like:

Private Sub WorkerThread()

While True
Dim _o As Object = QueueObject.Dequeue();
' Do something with _o
End While

End Sub

Of course, it's a little more complex because you have to cater for
situations where there is nothing in the queue or 2 worker thread attempt to
dequeue an object at the same time, etc. In addition you have to worry about
things like when to stop a worker thread, how to determine when all the
worker threads have finished, etc.

I would use a couple of classes something like this:

Public Class Controller

Private m_lock As New Object

Private m_threads as ArrayList = Nothing
Private m_queue as Queue = Nothing

Public Sub DoTheStuff()

m_queue = New Queue

m_threads = New ArrayList

For _i As Integer = 1 to 10
m_threads.Add(New Worker(m_queue, m_lock))
Next

' Retrieve the SearchResultCollection ( _src )

For Each _sr As searchResult in _src
Synclock(m_lock)
m_queue.Enqueue(_sr)
End Synclock
Next

While m_queue.Count 0
Thread.Sleep(10)
End While

For Each _wt As Worker in m_threads
_wt.Stop()
Next

End Sub

End Class

Public Class Worker

Private m_queue as Queue = Nothing
Private m_lock as Object = Nothing
private m_thread As Thread = Nothing
private m_stop As Boolean = False

Public Sub New(queue As Queue, lock As Object)

m_queue = queue

m_lock = lock

m_thread = New Thread(AddressOf TheThread)

m_thread.Start()

End Sub

Public Sub [Stop]()

m_stop = True

m_thread.Join()

End Sub

Public Sub TheThread()

Dim _sr As SearchResult = Nothing

While Not m_stop
_sr = Nothing
Synclock(m_lock)
If m_queue.Count 0 Then _sr = CType(m_queue.Dequeue(),
SearchResult)
End Synclock

If _sr IsNot Nothing Then
' Do something with _sr
End If

Thread.Sleep(1)
End While

End Sub

End Class

The whole process then becomes a matter of:

Dim _controller As New Controller

_controller.DoTheStuff()

' The whole thing is now finished

"Celldss" <ce*****@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
I'm doing a standard AD query to retrieve a list of workstations that
match certain criteria. I would like to iterate through that list and
see if the workstations are still on the network and have correct dns
records. Part of the difficulty is that the ping & dns check takes
roughly 100ms. This makes my app take rather long as it needs to check
thousands of workstations. I'm hoping multithreading can boost the
speed.

I would like to create several threads (say 10), each that will take a
name off the master list (as a SearchResultCollection), run the
ping/dns check, then output to the main log (a textfile). I'm having
trouble even coming up with the logic on how to do such a thing. How do
I create 10 threads, take a name "off the top" of the result
collection, pass it to each new thread's sub (making sure to take a new
name off the top for each new thread), then fire a new thread as the
previous one completes so my maximum number of threads running
concurrently is 10?

Thank you kindly.
Jason

Dec 21 '06 #5

Be very, very carefully to only use the allocated constructs on the thread
which they were created. This caused us much wailing and gnashing of teeth
until we figured out what was going on.

As for the rest, just use the system threadpool. Don't post too many things
there, but QueueUserWorkItem is (in general) your friend.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins

"Celldss" <ce*****@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
I'm doing a standard AD query to retrieve a list of workstations that
match certain criteria. I would like to iterate through that list and
see if the workstations are still on the network and have correct dns
records. Part of the difficulty is that the ping & dns check takes
roughly 100ms. This makes my app take rather long as it needs to check
thousands of workstations. I'm hoping multithreading can boost the
speed.

I would like to create several threads (say 10), each that will take a
name off the master list (as a SearchResultCollection), run the
ping/dns check, then output to the main log (a textfile). I'm having
trouble even coming up with the logic on how to do such a thing. How do
I create 10 threads, take a name "off the top" of the result
collection, pass it to each new thread's sub (making sure to take a new
name off the top for each new thread), then fire a new thread as the
previous one completes so my maximum number of threads running
concurrently is 10?

Thank you kindly.
Jason

Dec 22 '06 #6
Thank you very much for your assistance!
Chris Mullins wrote:
Be very, very carefully to only use the allocated constructs on the thread
which they were created. This caused us much wailing and gnashing of teeth
until we figured out what was going on.

As for the rest, just use the system threadpool. Don't post too many things
there, but QueueUserWorkItem is (in general) your friend.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins

"Celldss" <ce*****@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
I'm doing a standard AD query to retrieve a list of workstations that
match certain criteria. I would like to iterate through that list and
see if the workstations are still on the network and have correct dns
records. Part of the difficulty is that the ping & dns check takes
roughly 100ms. This makes my app take rather long as it needs to check
thousands of workstations. I'm hoping multithreading can boost the
speed.

I would like to create several threads (say 10), each that will take a
name off the master list (as a SearchResultCollection), run the
ping/dns check, then output to the main log (a textfile). I'm having
trouble even coming up with the logic on how to do such a thing. How do
I create 10 threads, take a name "off the top" of the result
collection, pass it to each new thread's sub (making sure to take a new
name off the top for each new thread), then fire a new thread as the
previous one completes so my maximum number of threads running
concurrently is 10?

Thank you kindly.
Jason
Jan 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kovac | last post by:
The System.directoryservices.dll has an error, and this error was described in http://support.microsoft.com/default.aspx?scid=kb;en-us;839424 At the moment we have Framework version v1.0.3705 and...
12
by: hykim | last post by:
Hello, everyone. according to MSDN, there is any constructor of System.DirectoryServices.SearchResultCollection Class. if I implement DirectorySearcher.FindAll() method by myself, then how can I...
1
by: Jason Gleason | last post by:
I am using the following method in a web service that utilizes the system.directoryservices namespace: public ArrayList GetAllAppPools(){ System.DirectoryServices.DirectoryEntry apppools = new...
1
by: Enosh Chang | last post by:
Hi all, I encounter some problem in DirectoryServices, could someone help me? private void InitLoginUser() { DirectoryEntry objEntry = new DirectoryEntry(); DirectorySearcher objSearcher =...
9
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group...
2
by: Kelvin | last post by:
Hello I am using web matrix develop a login page through Active Directory but I cannot figure out why it is giving me an error when importing system.directoryServices. Any help will do! thank ...
5
by: Keith Jakobs, MCP | last post by:
Hi All.... I'm having a HECK of a time connecting to Active Directory using VB in Visual Studio.NET 2003. Can anyone PLEASE help me? All I am trying to do is list the current members of our...
7
by: turbon | last post by:
Hello, I am writing code, which will copy webServices from one IIS 6.0 webserver to another and using DirentoryServices to achieve this purpose. And I have problems with authentication - I get an...
7
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I am using this code to get groups for a user and getting a error (5) on the GetAuthorizationGroups() function . There are two domains. This function works on the local domain but does not work...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.