Multithreading – Pros and Cons in Client/Server Architecture

clientclient-servermultithreadingserver

In my classes of parallel programming the teacher mentioned three models, dynamic thread creation (create threads according to demand), thread pool (create a fixed amount of threads) and mixed or hybrid (create a number of threads at first, but you can create more if the demand increases too much and then return to the previous amount of threads when demand returns to normal)

I would like if someone could elaborate on the advantages and disadvantages of each model in general terms of performance, when it is best to use one in specific, etc…

Best Answer

A quick non-academic view:

Dynamic model:

  • Pros: uses only the number of threads needed.
  • Cons: the overhead of the thread creation and deletion during the processing. Consider also thread switching overhead, if the number of dynamic threads increases over the hardware supported limit.
  • Typical use case: handling event driven processes/sessions (e.g. I/O), where threads are frequently waiting and performance of thread creation is small compared to I/O (e.g. new incoming network connection).

Thread pool:

  • Pros: reduces overhead of thread management to the minimum. Constant throughput ?
  • Cons: If the size of the pool is too large (compared to hardware capacity or to processing needs), there might be an unnecessary switching overhead for unused threads.
  • Typical use case: handling work processes for queued input. More here

Mixed model:

  • can have the advantages (or the inconveniences if not careful !!) of both models. One possible approach is to size the a pool with an optimal size determined dynamically at runtime to maximize performance in view of hardware and processing needs.
  • Pros & cons of hybrid models can't be analyzed in general: they must be assessed case by case.
Related Topic