我必须创建一个简单的客户端< - >服务器通信来使用C语言(Linux)传输文件.
服务器接受10000端口上的连接,我不知道是否更好地为每个请求创建一个新线程或创建固定数量的线程并使用异步技术.
CASE A:
client --> server --> (new thread) --> process the request
CASE B:
SERVER --> create thread 1 - thread 2 - thread 3
then
client1 --> server --> thread 1
client2 --> server --> thread 2
client3 --> server --> thread 3
client4 --> server --> thread 1
client5 --> server --> thread 2
client6 --> server --> thread 3
Run Code Online (Sandbox Code Playgroud)
在这种情况下,线程1可以处理许多客户端的请求
我的考虑:
情况1:速度更快但浪费了大量内存
情况2:速度较慢但使用较低的内存
我错了吗?