1. Socket is one kind of I/O handle, just like a file handle.
Accessing a socket with multithreading is very similar to accessing a file with multithreading.
2. The network programming models are very mature today.
You may first refer to some old documents to know more about that:
http://think-async.com/Asio/LinuxPerformanceImprovements
http://www.kegel.com/c10k.html#strategies
3. If you are not very familiar with multithreading (MT),
it is recommended to use single threading + asynchronous socket programming model.
Because in this model, it would be easy to make your code run correctly as you expect.
Oppositely, if you are going to process I/O data with multithreading, you should think about
- the correctness and completeness of the data you get from a socket via multiple threads;
- using a thread pool.
4. Try to reduce memory copies when you process I/O data got from the sockets.
Especially for C/C++ programmers, it'd better to use smart pointers
(when you need to create something in heap) and pass them within the processing flows.
5. Adjust the parameters of the socket/thread API functions to proper values
so that your program can work well for your project's requirements.
The parameters might be the I/O buffer size, the timeout period, the stack size of a thread, etc.
Accessing a socket with multithreading is very similar to accessing a file with multithreading.
2. The network programming models are very mature today.
You may first refer to some old documents to know more about that:
http://think-async.com/Asio/LinuxPerformanceImprovements
http://www.kegel.com/c10k.html#strategies
3. If you are not very familiar with multithreading (MT),
it is recommended to use single threading + asynchronous socket programming model.
Because in this model, it would be easy to make your code run correctly as you expect.
Oppositely, if you are going to process I/O data with multithreading, you should think about
- the correctness and completeness of the data you get from a socket via multiple threads;
- using a thread pool.
4. Try to reduce memory copies when you process I/O data got from the sockets.
Especially for C/C++ programmers, it'd better to use smart pointers
(when you need to create something in heap) and pass them within the processing flows.
5. Adjust the parameters of the socket/thread API functions to proper values
so that your program can work well for your project's requirements.
The parameters might be the I/O buffer size, the timeout period, the stack size of a thread, etc.