Hi, Fellow Monks. Im writing an application to do something quite simple. Lets say there is a large network of servers that are all disconnected, or are grouped together in smaller subnets. They are all reachable from one another, but choose not to connect (irc for example). On all of these servers, there are various channels (also like irc). On almost all of these servers there is a #linux. Since I got tired of finding my linux-using friends, I devised a simple script to simply connect to all the servers, join the #linux channel, and mirror it to the server I am on.

Before anyone tells me thats an annoying thing to do, lets just tackle the code part of it. There are, at the moment, 201 of these servers. Lets say it takes only two seconds to connect to these servers. Thats still just shy of seven minutes to connect to all of them.

Lincoln Stein's Napster.pm is doing the actual connecting here, and the module requires a threading perl, which I've got. I shouldn't have to wait for a response from each server after I send my login request, some of them will be slower than others. I'd like to read down the list (keys %client_servers_host_info), and just send a login request to all of them, and then deal with them as they get back to me, or, if necessary, destroy the connection. Instead, it takes 10 minutes to get to only 60 of the servers because I am waiting for every one of them. So my question is, then, is there some way I can do this like I would in bash (i.e., dothis & dothis & dothis)? Furthermore, since the module itself already makes use of threads, is it possible to thread a threaded sub?

So here is the code. $host_server_config{foo} is the relevant data for the server I am mirroring all the other servers to. It's a one-way mirror. %client_servers_host_info is basically just a long hash that looks like "server port". "dacts" is just a sub that interfaces with the connect method in the module. Sorry if the variable names are a little confusing.

foreach my $client_server (keys %client_servers_host_info) { srand; my $extra = int(rand(256)); warn $host_server_config{username} . $extra . "\n"; $client_servers{$client_server} = dacts ( $host_server_config{username} . $extra, $host_server_config{password}, $client_server, $client_servers_host_info{$client_server} ); $counter++ ; warn $counter; }

Of course there is one other question here. I have gotten lots of people telling me how stupid it is to be using perl-threads at all. I know the threading implementations changed between 5.005 and 5.6.0, I know that in the 5.6 version there are two different flavors even of threads. People on dalnet #perl think its idiotic for me to use threads, but I am using threads because of the module. It seems to work very well for me when I have less than 400 threads running (yes, perl segfaults for me up higher than that). I just read the interview with Larry in Opensource Developers Journal, and it sounds like perl 6 is going to be a drastic departure. How can I write more portable, more stable, and long-lasting code that appears and behaves threadedly in perl?

I know its kind of a dense post. Thanks guys, gals.

deprecated

--
i am not cool enough to have a signature.


In reply to Simultaneous writes and as-needed reads from sockets (or The State of Perl Threads...) by deprecated

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.