On Thu, 2008-04-24 at 16:23 -0700, Wong, Danny H. wrote: > Hi GURUS, Thanks for the compliment :)
> I'm trying to implement a threaded program using work crew model. I > was wondering if someone can provide an example. I'm trying to copy some > files to say 100 machines ( for this example... 100 directories would be > work as well) as I'm looking for a real example of how to use the work > crew model thread. thanks. > A while back I worked on a program that did heartbeat monitoring (PING) to about 20 machines. Now the logical thing to do would be create a list and work the list in a single thread. The problem here is if 5 of those machine were down then you would be delayed getting to the end of the list. I needed a method to guarantee that each machine would be tested every 60s. I did it with threads. I created a thread for each machine that would send the ping and wait for its return. I then created a manager thread whose job it was to send alerts. I did all this in C but it can be done in Perl. In C I basically had a shared memory segment where the workers could write values. The manager would lock a semaphore and then look at the memory seeing any changes. It would then send a message to a program that handle notifications. After this it would unlock the semaphore. In Perl you could attack this type of idea many ways. You could create shared objects that store info like state, last ping, etc and then the manager would look at those objects ever 60s and act. You could create pipes and have the child threads send message back to the manager on state changes and then he acts. The whole idea of threads here is that each thread is responsible for one machine and can hit that machine easily every 60 seconds. Now it does not scale well. If you wanted to do 100 machines then I would not execute 100 threads. I would probably do 10 threads with 10 machines each. In reality a host should take no longer than 5s to respond to a ping. Use Net::Ping and specify a timeout of 5 seconds. 5x10 is 50 so you should still be able to hit the 60s requirement even if all 10 are down. Chris