Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Perl Multithreading

by chhe (Sexton)
on Mar 28, 2002 at 12:52 UTC ( #154942=perlquestion: print w/replies, xml ) Need Help??

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

Dear Perl Monks,

hopefully i am not too keen, if i ask bluntly and stupidly: How is concurrency and the execution of perl programms through perl supported....

No, crap, let's start again: with some background on my real problem...:

I have existing perl programms, which i want to automate (execute) thorugh a perl programm. Since the existing perl programms have very different requirements in terms of execution time and frequency, the executing perl programm must expect a high degree of concurrency. I can't use for instance cron, because the sheduling is done in a different system. Also if i just execute the perl programms through the sheduling system, i have a scalabilty problem ... like the cgi problem with httpd, addressed with mod_perl.

What are the options? How well is mulithreading supported? Fork versus system, is eval feasible for execution whole perl programms? Etc.?

I am aware, that this potentially a "big" and many questions, there fore i appreciate any hints, links to existing/similiar solutions.

Humble seeker of Perl wisdom

Chris

Replies are listed 'Best First'.
Re: Perl Multithreading
by RMGir (Prior) on Mar 28, 2002 at 13:35 UTC
    As far as I know, perl multithreading is still not ready for primetime. In any case, your description of the needs of the programs seems to argue against multithreading.

    Fork/exec work fine in perl, on all platforms, although on NT they rely on some of those experimental threading features, so you could have problems there.

    This sounds like a problem that's already been solved somewhere :) Unfortunately, a quick CPAN search didn't find anything that looks useful, apart from Proc::SyncExec.
    --
    Mike

Re: Perl Multithreading
by dhable (Monk) on Mar 28, 2002 at 14:21 UTC

    Multithreaded programming and Multiprocess programming are very similar.

  • Multithreaded programming places the responsibility of scheduling the thread with the program and not with the task scheduler in the kernel. Thus, your program needs to swap things around to simulate that both items are running at the same time.
  • Multithreaded programming uses a single set of instructions in memory, so you need to lock access to parts that update variable values to prevent a collision. Multiprocess programming gives each process its own memory space thus you don't need to worry about locking variables before updates.
  • Multithreaded programming can communicate with other threads using all sorts of global variables. Multiprocess programming needs to use IPC or pipes, etc. to communicate with other processes.
  • In general, I've almost always been able to write programs with nothing but fork. Since it sounds like you're working on a program to launch other programs, fork sounds like it would work. Just keep the parent process in an infinite loop and run it in the background.

Re: Perl Multithreading
by Stegalex (Chaplain) on Mar 28, 2002 at 13:42 UTC
    Looky here for starters: Perldoc fork or if you have the Perl Cookbook, check out Recipe 17.11 "Forking Servers". Best of luck! I like chicken.
Re: Perl Multithreading
by Fletch (Bishop) on Mar 28, 2002 at 15:08 UTC

    perldoc perlipc covers fork and other interprocess related topics.

    Also check out POE and http://poe.perl.org/ for another concurrency (or at least the illusion thereof :) option.

Re: Perl Multithreading
by perrin (Chancellor) on Mar 28, 2002 at 16:20 UTC
    I can't use for instance cron, because the sheduling is done in a different system.

    You lost me. Why can't you use cron? You can put a CGI or GUI frontend on it if you want, and have it write edits out to crontab (there's a module for that).

    Also if i just execute the perl programms through the sheduling system, i have a scalabilty problem ... like the cgi problem with httpd, addressed with mod_perl.

    mod_perl doesn't reduce concurrency. It elminates the need to fork at request time (by forking ahead of time) and allows persistent connections to databases. Both of those help performance a lot. If you think that would help your situation, you could try re-writing your programs as mod_perl modules, and calling them from cron via LWP.

Re: Perl Multithreading
by bluto (Curate) on Mar 28, 2002 at 16:52 UTC
    Not sure what you are implementing. If you are monitoring resources, machines, etc. which generally require better scheduling than cron, you may want to look into something like "mon" at http://www.kernel.org/software/mon/. It's in perl so even if you don't use it you may get some good ideas from it.

    bluto

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-06-25 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (81 votes). Check out past polls.

    Notices?