Difference between revisions of "FAQ.MultiThreading"

From Overbyte
Jump to navigation Jump to search
m
Line 12: Line 12:
 
== A Thread per Socket ==  
 
== A Thread per Socket ==  
 
When incoming connection, encapsulating socket within a thread, and managing communication within the thread, across several threads
 
When incoming connection, encapsulating socket within a thread, and managing communication within the thread, across several threads
 +
 +
== Many sockets per thread ==
 +
A single thread is able to handle a lot of simultaneous sockets. Using a single socket per thread is not the way to go to support a large number of concurrent connections. In that case you need to use many socket per threads. Something like 10 to 500 sockets per thread. This way you can handle thousand simultaneous connections.
  
 
== A Worker Thread ==  
 
== A Worker Thread ==  
 
When running a lengthy process (SQLing a RBDMS, doing bottlenecked I/O, ...), and to prevent GUI from freezing, encapsulating it in a thread (JobThread), and sending back data when the thread is done (or simulating a process end).
 
When running a lengthy process (SQLing a RBDMS, doing bottlenecked I/O, ...), and to prevent GUI from freezing, encapsulating it in a thread (JobThread), and sending back data when the thread is done (or simulating a process end).

Revision as of 19:44, 3 March 2006

Main page -> FAQ -> MultiThreading

Introduction

  • What is a thread ?
  • What is multithreading ?
  • Advantages & Disadvantages

The Main Question

Do i need Threads ?

Cases where needed and where not needed

A Thread per Socket

When incoming connection, encapsulating socket within a thread, and managing communication within the thread, across several threads

Many sockets per thread

A single thread is able to handle a lot of simultaneous sockets. Using a single socket per thread is not the way to go to support a large number of concurrent connections. In that case you need to use many socket per threads. Something like 10 to 500 sockets per thread. This way you can handle thousand simultaneous connections.

A Worker Thread

When running a lengthy process (SQLing a RBDMS, doing bottlenecked I/O, ...), and to prevent GUI from freezing, encapsulating it in a thread (JobThread), and sending back data when the thread is done (or simulating a process end).