小编Dai*_*ail的帖子

什么是最好的,单线程或多线程服务器?

我必须创建一个简单的客户端< - >服务器通信来使用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:速度较慢但使用较低的内存

我错了吗?

c linux network-programming

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

linux ×1

network-programming ×1