Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^6: Perl threading stability?

by iburrell (Chaplain)
on Jul 26, 2005 at 00:39 UTC ( #478031=note: print w/replies, xml ) Need Help??


in reply to Re^5: Perl threading stability?
in thread Perl threading stability?

Java will use multiple CPUs for multiple threads depending on the platform and the thread library. The JVM may run multiple Java threads on top of a single kernel thread, but all the thread libraries I know about will do multiple kernel threads. My impression was that recent JVMs on Linux run directly on the pthread library and each thread is a separate kernel thread. The kernel threads on Linux are efficient enough that implementing threads in user space does not help.

Replies are listed 'Best First'.
Re^7: Perl threading stability?
by BrowserUk (Patriarch) on Jul 26, 2005 at 00:56 UTC

    Indeed, it looks as though things have moved on--on Linux at least--from my last experience of using Java.

    About Linux Threads

    One major difference between developing on Linux from other Unix operating systems is the system threads library. In Java 2 releases prior to 1.3, the Java virtual machine uses its own threads library, known as green threads, to implement threads in the Java platform. The advantage here is that green threads minimize the Java virtual machine's exposure to differences in the Linux threads library and makes the port easier to complete. The downside is that using green threads means system threads on Linux are not taken advantage of and so the Java virtual machine is not scalable when additional CPUs are added.

    In Java 2 Release 1.3, the Hotspot virtual machine uses system threads to implement Java threads. Because Linux threads are implemented as a cloned process, each Java thread shows up in the process table if you run the ps command. This is normal behavior on Linux.

    ...

    In the above listing, the process ID 11712 shown in the left-most PID column is the invoked Java virtual machine. The other processes that show process ID 11712 in the PPID column have process ID 11712 as their parent process. These children to process ID 11712 are Java threads implemented by the Linux system threads library. Each Linux thread is created as a process clone operation, which leaves the scheduling of threads to be a task of the process scheduler.

    By comparison, on Solaris the Java threads are mapped onto user threads, which in turn are run on Lightweight processes (LWP). On Windows the threads are created inside the process itself. For this reason, creating a large number of Java threads on Solaris and Windows today is faster than on Linux. This means you might need to adjust programs that rely on platform-specific timing to take a little longer on startup when they run on Linux.

    I'd question your conclusion regarding the efficiency of pthreads, but as I do not have any great experience of them I can only base my judgements upon generic information. Having user threads map 1:1 to kernel threads seems like an ideal situation, but history shows that it has nearly as many drawbacks as advantages.

    Update: More generic information:

    Linux Thread Optimizations

    The first thing Java developers notice when running their application on Linux is that the ps command, used to display the list of processes, appears to show multiple copies of Java runtime environment running even though only one Java application was started.

    This is due to the implementation of the system threads library on Linux. Linux threads are implemented as a cloned process, that means each Java thread appears as a new Linux process. The advantage of this approach is that the threads implementation is simpler and stable, however the downside is that this also affects the performance of even a moderately threaded Java application on Linux.

    ...

    Update2: And yet another demonstration that one to one user/kernel thread mapping is invariably bad for performance.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-09-27 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (118 votes). Check out past polls.

    Notices?