deprecated has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simultaneous writes and as-needed reads from sockets (or The State of Perl Threads...)
by Fastolfe (Vicar) on Jan 13, 2001 at 01:15 UTC | |
by deprecated (Priest) on Jan 13, 2001 at 03:38 UTC | |
by Fastolfe (Vicar) on Jan 13, 2001 at 04:59 UTC | |
|
Re: Simultaneous writes and as-needed reads from sockets (or The State of Perl Threads...)
by repson (Chaplain) on Jan 13, 2001 at 11:48 UTC |