Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^7: Program Design Around Threads

by BrowserUk (Pope)
on Mar 06, 2013 at 23:17 UTC ( #1022115=note: print w/ replies, xml ) Need Help??


in reply to Re^6: Program Design Around Threads
in thread Program Design Around Threads

I am trying to further wrap my head around why saving a possible 30 seconds per device in this scenario was a less than optimal approach. That is other than the fact that it causes me a lot of synchronization issues.

Okay. Using your numbers: 100 machines; 3 commands; 15 seconds per command; and 10 concurrent threads.

  • Your way;

    You process 10 commands (3 1/3 machines) every 15 seconds: 100 / 3.333 * 15 / 60 = 7.5 minutes.

  • My way:

    I process 10 machines every 45 seconds: 100 / 10 * 45 / 60 = 7.5 minutes.

But: I've spawned 100 threads and made 100 connections. No locking, nor waiting, nor syncing to slow things down.

You've spawned 300 threads and made 300 connections. And you had to acquire locks and wait for them.

Given the IO bound nature of the problem, the locking might not slow you down too much -- assuming that you can get it right without creating dead-locks; live locks or priority inversions et al. -- but you've definitely consumed 2 or 3 times as much cpu; caused 3 times as much network traffic; 3 times the load on the remote machines; and consumed more memory; to achieve the same overall elapsed time.

It just isn't worth the hassle.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^7: Program Design Around Threads
Re^8: Program Design Around Threads
by aeaton1843 (Acolyte) on Mar 07, 2013 at 00:21 UTC

    Heh :-) I should have put the math down on paper first in those terms. I didn't believe it until I saw it. Even if I spawn all 300 threads to your 100 I only save 30 seconds on your code. For all those processes and resources, you're right, not worth it. For some reason, it didn't click until now. My myopic vision has been cleared. I am grateful for your time, many thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-09-23 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (219 votes), past polls