|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Multiple Processes, multi threading
My questions is about the beniifit or performace differences between multi threading and multiple processes or even a single process and adjusting its priority. (try not to start any flames on which is better than the other just trying to see the benifits, when a person should chooes a certain technique)
Since a CPU manages the time slices and there length each process is given (I believe depending on priority of the process as well) if I change a process's priority based upon how much work there is to be done do I receive a benifit from doing this? Multi Threading uses one process but handles multiple threads within that one process. This handles multitasking environments but I would think some what slower since the same time slice is given to the process and the threading process has to handle all the internal threads specifying which thread receives that time slice. comments? Multi Processing forking another process to handle the work load should speed up processing since I now have more CPU time slice to work on the same task. (I realize the initial fork itself can be costly but it is possible to have some idle children around and manage the children to be created or destroyed depending upon workload required). Also, i realize there is a limit on the amount of process I create before bogging down the system since I used up to many CPU time slices. comments? Tried googling and searching this forum a bit and can't seem to find any comments or answers on this. If anyone has any links to some info that would be appreciated. Thanks |
|
#2
|
|||
|
|||
|
The answer is very much "it depends..."
What exactly do you mean by "performance"? The CPU has only a fixed number of clock cycles that it can use for all the processes and threads, and switching context between processes or threads uses up cycles, so in absolute terms the best performance will come from having a single process running a single thread. Adding more processes or threads will not result in more work being done. Threads are useful for many things, but improving raw performance in the way that you want is not one of them. Spawing new processes so that you can hog more time cycles is also not a good idea - you will make the program much more complex and probably add overheads that will negate any advantage you may gain. It is also very unfriendly to other apps - it should be up to the user or the OS to decide how much priority to give your program. It is far better to spend your time finding ways of optimising your program algorithms. The exception to this is with multi-processor machines, where separate threads or processes can be run in parallel on different processors. How well it does this depends on the nuances of the operating system and the language being used. Optimising code for multi-processor systems is a highly advanced topic and not something you are likely to find a solution to in a non-specialist discussion board. Dave - The Developers' Coach |
|
#3
|
|||
|
|||
|
Thanks for your comments. I'm not concerned with multiple processors as of yet just looking for information on single processor systems. As for performance I was looking from an application stand-point.
Would this be an interpretation - multiple threads or multiple processes are used mainly when you have a multiple user application? (As MySQL and/or Apache). multiple processes can also be used as a security implementation (eg Postfix)? Thanks again Also, any links or extra info (books etc.) would be appreciated. |
|
#4
|
|||
|
|||
|
There could be performance gains in multithreading/processing
When a thread performs I/O it is temporarily suspended until the operation completes. In such cases you could get additional work done in another thread. All context switches between threads, and between processes in particular, takes time and consumes CPU. Use threads or processes when it makes the design of your system simpler.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Multiple Processes, multi threading |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|