Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Multi Threading help

by drip (Beadle)
on Feb 28, 2008 at 10:39 UTC ( #670878=perlquestion: print w/replies, xml ) Need Help??

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

Hullo need help again monks. =) i have a dhcpclient script which i need to run 1000 times simultaneously multi threading a good way to solve that problem? or would it be better to use fork()?

if threading is a good way of solving the problem please do give an example of multi threading

and if you think fork would be a good way to solve the problem please do give an example also..

i humbly need your wisdom on this...=)

Replies are listed 'Best First'.
Re: Multi Threading help
by moritz (Cardinal) on Feb 28, 2008 at 10:44 UTC
    If you just need to run the scripts, and don't do much with the result, you can use forking and Parallel::ForkManager. The documenation of that module contains a simple example that can be easily adapted for your purpose.
      thank you..most likely i would just need to run the client script simultaneously .
Re: Multi Threading help
by tirwhan (Abbot) on Feb 28, 2008 at 11:01 UTC

    The first question that comes to mind is, why on earth would you need to run a dhcpclient script a 1000 times simultaneously? Are you setting up a thousand virtual interfaces on your machine and need to assign them an address instantly?

    That being said, if your children do not need to share state use fork, if they do, investigate whether one of the IPC methods available are sufficient for your needs. If they're not, use threads. (This goes for *NIX, Windows apparently has its own issues with fork(), though I'm not knowledgeable enough about them to really comment).

    For examples see the documentation for perlipc and threads.

    All dogma is stupid.
      the answer to your question would be ...that i am testing a dhcp server(that's all i can say for now)...thank you for the reply ;)
        You didn't specify the type of testing, but, if it's simply a load test, then it would probably be easier and more efficient to put together a custom DCHP client app which simply blasts the server with a stream of requests at your chosen rate (1000/second or whatever) rather than setting up 1000 separate clients.
Re: Multi Threading help
by sundialsvc4 (Abbot) on Feb 28, 2008 at 18:31 UTC

    “A thousand threads or processes on one box” will not be a test-case that is actually comparable to what such a server will actually face in production. There is only one machine, only one network-card and so on. Since that hardware interface is by-definition a bottleneck, you're going to have to have lots of machines presenting load and doing so from a network that can actually handle it.

    The most important “testing” is going to consist of careful code-review of the server architecture, because that is really where the bottlenecks that you are looking-for are going to be.

    And that means that you can very effectively simulate the load. For example, make aggressive use of the "loopback" (software) device. One process on the machine (perhaps with affinity to a second CPU) pummels the server process with multiple random data-streams simulating 1,000 or more insane clients. The software device can present a much more-aggressive load pattern than hardware can do.

    Look carefully for any network-testing software and/or hardware that might be available off-the-shelf...

Re: Multi Threading help
by renodino (Curate) on Feb 28, 2008 at 19:12 UTC
    Piggybacking on sundialsvc4's comment:

    DHCP is a UDP based protocol. As such, its not really neccesary to open 1000 socket connections. Just fire off as many UDP packets as you can from N threads/processes, where N << 1000.

    But be prepared to lose a few packets... regardless which solution which choose.

    Perl Contrarian & SQL fanboy
      thank you for the reply...can you give a sample code for that please...just for the threading part..
        use the search

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://670878]
Approved by moritz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2021-01-27 05:28 GMT
Find Nodes?
    Voting Booth?