Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: A question of fork efficiency

by Tanktalus (Canon)
on Aug 05, 2019 at 19:07 UTC ( [id://11103984]=note: print w/replies, xml ) Need Help??


in reply to A question of fork efficiency

At first glance, nothing significant is standing out to me. I mean, I'd not pass in the \%threads reference to forkportcheck, but handle that in the caller, and I'm not seeing why you have the inner while, unless it's to force the output in the same order as the input (which seems odd), but those are relatively minor.

The only thing I can think of that would improve this is to use event-based sockets. Which would be much easier if you were using AnyEvent, Coro, POE, or one of a myriad of other event systems available for Perl. This would eliminate the fork, allowing it all to be done in a single process. If you're connecting to systems on the internet, I doubt this will be much of a gain, and even if it's all on your intranet, it may be too little of a gain to be noticeable (though only one way to be sure!).

Of course, this would require some CPAN modules. Which, for some odd reason, you said you can't do. Since as I already responded to that, I'm not going to go into great detail here again. Just seems odd. I never see anyone say "I'm doing this in C# and I can't use nuget" or "I'm doing this in Javascript, and I can't use npm/bower/etc." Why is it just Perl that gets this treatment?

Replies are listed 'Best First'.
Re^2: A question of fork efficiency
by synless (Acolyte) on Aug 05, 2019 at 19:45 UTC

    You are correct in assuming the while statement is to force output order. This part of the function was taken from the function that actually runs commands on the remote servers. When multiple lines of output are returned simultaneously we want the output to be grouped together instead of intertwined.

    I've never used event-based sockets for anything as I'm still relatively new to the programming in general. Any suggestions on where to get started would be appreciated.

    I should clarify the CPAN modules statement. Generally I can use anything from CPAN that is already prepackaged in an rpm for CENTOS7/RHEL7 and is in their default repositories. I can also grab modules that can be easily packaged using cpanspec. This tool is to be used internally by teams I support and other teams. Corporate policy forbids quite a few of these teams from having CPAN access so I'm limiting what I can use based on that. If it is a module with very little dependencies I'll consider it. Thanks for your input so far!

      Generally speaking, I would print out the return values as I received them, but then, at the end, print out a nice pretty, ordered list. This allows for systems that respond quickly to show up quickly, and systems with lag responding to not delay the quick ones, at least during the running.

      Where to get started - that is a matter of preference. I had someone here recommend AnyEvent and Coro to me ages ago, and that's what I'm using for the CB stats and last hour of cb updates (it's all in a single process and a single thread, making http calls to Perlmonks, both for downloading and uploading, and updating databases, and actually having a built-in chatterbox client as well). There's a pretty good chance that Coro won't be available in an RPM on RHEL/CentOS. However, Yes, even you can use CPAN might still be worth a read for your situation.

        Thanks! I'll check those out soon. If they don't have too many other dependencies I can probably get cpanspec to build them. Though so far it is choking on common::sense so we'll see on that one. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11103984]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found