kingjamesid has asked for the wisdom of the Perl Monks concerning the following question:

Hello I have a list of clients to which I need to copy files from one single source. I need to perform this copy such a way that all "robocopy" happen at teh same time. That is, if there are 5 clients, I need 5 robocopy processes started at teh same time. How can I do this in Perl? I tried to use this, but its one-at-a-time only.
if ( @client > 1 ) { foreach my $client (@client) { print MYLOG "Working on Source: ",$srcMachine," and Client: " +,$client->[0], "\n"; if ( &isAlive( $client->[0] ) ) { print $$."\n"; my $job = Win32::Job->new(); print $job."\n"; my $job_result = $job->spawn(&startCopy( $srcMachine, $cli +ent->[0] )); die $^E unless (defined $job_result); #print $job_result; }

Replies are listed 'Best First'.
Re: Synchronous action
by SuicideJunkie (Vicar) on May 11, 2011 at 21:51 UTC

    Variations in ping time to each client means you can't send something to all of them simultaneously, regardless of the local hardware limitations. Multiple processes won't help you there.

    If you just want to make sure you're sending the same data to everyone from a rapidly changing source, copy the file(s) to a temp folder (or read into memory), then distribute that temp copy to the clients.

    A single threaded application can send single packets to each ready client in turn so no one of them will hog all the bandwidth or unduly delay the others. If your single app doesn't let any client get more than one packet ahead of the others, then you can keep them all in synch up to the last packet at the cost of having a bad client slowing everybody down.

Re: Synchronous action
by locked_user sundialsvc4 (Abbot) on May 12, 2011 at 11:53 UTC

    Another idea that pops into my head is ... “what about git?”   (The version-control package.)   Or maybe rsync?

    In other words:   what if, instead of having one central authority pushing a set of changes to a bunch of remotes, the remotes pull those changes to themselves, “synchronizing” what they have with what they have just now been informed is “the new authority,” but doing so under their own steam.   (Even good ol’ rsync already has the goodness to know how to compare files using digital signatures, compress transfers across a network, and so on.)   Your program would now orchestrate the process, but would not single-handedly do it.

Re: Synchronous action
by believer (Sexton) on May 12, 2011 at 12:37 UTC
    What is the underlying reason to copy at the same time?
    If the purpose is to cut down on run time because it's a huge amount of data, use fork().
    If it is a matter of concurrent synchronisation, you will need some kind of locking mechanism.
      Maybe I used wrong terminology. Not to make it complicated, I just wanted all robocopy to be started at teh same time from one source to multilple machines. PARALLEL. It saves time. If done in SERIAL, it takes a long time for the robocopy to finish. I shall research on FORK, meanwhile, I hope you get my idea, what am trying to do and using "synchronization" might have confused you all. oops.

        All you need is:

        for my $client ( @clients ) { ## Note: the '1' first parameter to system ## which means that the command will be executed asynchronously system 1, qq[ robocopy $srcmachine $client ]; }

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.