Find the answer to your Linux question:
Results 1 to 7 of 7
Will there be any performance hit on the running process by spawning many threads? Somebody please explain about the scheduling policy of a thread....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    19

    Performance hit by creating new thread


    Will there be any performance hit on the running process by spawning many threads?
    Somebody please explain about the scheduling policy of a thread.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,558
    1. Yes
    2. Threads are "light-weight" processes. Not as much context switch information/overhead as in full process context switches.
    3. Performance impact depends ENTIRELY on the number of CPU's or cores that the system has. There is a finite amount of CPU time available. Once you hit that wall, performance falls off due to resource contention (CPU cycles available).

    As for actual scheduling policy, you need to research this yourself. The answer is "it depends" upon many factors, including kernel version, which scheduler you are using, etc.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    May 2010
    Posts
    19
    Quote Originally Posted by Rubberman View Post
    There is a finite amount of CPU time available. Once you hit that wall, performance falls off due to resource contention (CPU cycles available).
    My question is weather the performance of other processes is effected or the threads with in the same process will be effected by spawning more number of threads?

  4. #4
    Just Joined!
    Join Date
    May 2010
    Posts
    19

    @Rubberman

    Precisely put, I wanted to know if the time slice allocated to the thread is shared from the time slice of the same process or does it depend on number of process in the run queue of the scheduler?

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,558
    Yes to both questions. There is thread scheduling associeted with each process, and there is the process scheduling. The more work a thread is doing (other than waiting for I/O) the more it will impact the process and add to the load the process is making on the system, hence other processes. Multi-core systems are great for reducing this load. For example, I have an 8 core system and often run a program called ffmpeg to transcode video streams from one format into another, such as from AVI to MP4 so I can run the video on my Android phone. Since ffmpeg has an option to specify how many threads it can use to transcode the video (more == faster processing up to a point), I often specify between 4 and 8 threads, depending upon what else I am doing on the system at the time. As a result, each thread can run in pararllel with minimal impact on the rest of the system.

    In practical terms, there are other resources that will limit the number of actual threads you can run in a process, but it is not uncommon for application servers that handle a lot of client requests to have dozens or hundreds of threads running. What the limits are depend upon factors mentioned, such as number of core processors, RAM, system configuration, other workloads, etc. The means of determining what that maximum number of threads may be is something of a "black art"...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Just Joined!
    Join Date
    May 2010
    Posts
    19
    Thanks Rubberman.

    Can you suggest a book or a site where I can get more Information about Linux scheduler.

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,558
    I'll see what I can come up with. It will likely be a day or two before I get back to you.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •