Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Design advice: Classic boss/worker program memory consumption (context switching is cheap)

by tye (Sage)
on May 21, 2014 at 00:55 UTC ( [id://1086887]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Design advice: Classic boss/worker program memory consumption
in thread Design advice: Classic boss/worker program memory consumption

if we let 56 processes run in parallel, the overall process takes much longer to execute than when we have 8 to 16 processes, and we strongly believe that this is due to context switches and memory usage.

Having to swap pages out and back in surely can make things run much, much longer. 56 processes talking to databases isn't really going to add enough overhead from context switching to cause the total run-time to be "much longer", IME. To get context switching to be even a moderate source of overhead, you have to force it to happen extra often by passing tiny messages back and forth way more frequently than your OS's time slice.

There are also other resources that can have a significant impact on performance if you try to over-parallelize. Different forms of caching (file system, database, L1, L2) can become much less effective if you have too many simultaneously competing uses for them (having to swap out/in pages of VM is just a specific instance of this general problem).

To a lesser extent, you can also lose performance for disk I/O by having reads be done in a less-sequential pattern. But I bet that is mostly "in the noise" compared to reduction in cache efficiency leading to things having to be read more than once each.

Poor lock granularity can also lead to greatly reduced performance when you over-parallelize, but I doubt that applies in your situation.

- tye        

Replies are listed 'Best First'.
Re^4: Design advice: Classic boss/worker program memory consumption (context switching is *absolutely not* cheap)
by BrowserUk (Patriarch) on May 21, 2014 at 02:08 UTC
    context switching is cheap

    Sorry Tye, but that is twaddle. Eiher guesswork, or naiveté.

    Firstly, which type of "context switch" are you mis-describing?

    • Thread-context.
    • Process-context.

    The cost of a hardware-based, thread-only context switch runs from 10's to over 1000 microseconds. Add in the need to invalidate and refill L1/L2/L3 caches, and the total time to re-consitute a thread-context back the point that real work can proceed can actually take longer than the maximum timeslice some (flavours of some) OSs will allocate to a thread.

    And don't go blaming threads; switching process-contexts is a (collection of) software operations and is more expensive still.

    The cost of context switch may come from several aspects. The processor registers need to be saved and restored, the OS kernel code (scheduler) must execute, the TLB entries need to be reloaded, and processor pipeline must be flushed. These costs are directly associated with almost every context switch in a multitasking system. These are the direct costs.

    In addition, context switch leads to cache sharing between multiple processes, which may result in performance degradation. This cost varies for different workloads with different memory access behaviors and for different architectures. These are cache interference costs or indirect costs of a context switch


    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.

      Thanks for mostly agreeing with me (despite feeling like you completely disagreed with me).

      - tye        

        Naiveté then. (You headlined your post.)

        Until you show the world how to divorce a "context switch" from "cache misses" -- along with the TLB misses caused by stack segment changes -- your editorialising is not just meaningless, but misinformative ...


        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.
Re^4: Design advice: Classic boss/worker program memory consumption (context switching is cheap)
by Laurent_R (Canon) on May 21, 2014 at 06:30 UTC
    Having to swap pages out and back in surely can make things run much, much longer. 56 processes talking to databases isn't really going to add enough overhead from context switching to cause the total run-time to be "much longer", IME.

    Well I guess it depends on our definitions of what "much longer" mean. In our case, it can be up to twice longer, say four hours instead of 2. For us it is sometimes the difference between usable and not usable program.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found