多个UDP端口
我遇到过这样的情况:我必须在服务器中处理多个实时 UDP 流。
我有两个选择(正如我所想的)
Single Socket : 1)监听服务器上的单个端口,并接收来自同一端口上所有客户端的数据,并为每个客户端创建线程来处理数据,直到客户端停止发送。 这里仅使用一个端口来接收数据,并使用多个线程来处理数据。
多个插座: 2) 客户端会向服务器请求打开端口来发送数据,应用程序会将打开的端口发送给客户端,并在该端口上打开一个新的线程监听以接收和处理数据。这里每个客户端都会有唯一的端口发送数据。
我已经实现了一种方法来知道哪个数据包来自 UDP 中的哪个客户端。
我有 1000 多个客户端,每秒接收 60KB 数据。
使用上述方法是否存在任何性能问题
,或者这里是否有任何有效的方法可以在 C 中处理此类任务?
谢谢,
拉古
I have situation where I have to handle multiple live UDP streams in the server.
I have two options (as I think)
Single Socket :
1) Listen at single port on the server and receive the data from all clients on the same port and create threads for each client to process the data till the client stop sending.
Here only one port is used to receive the data and number of threads used to process the data.
Multiple Sockets :
2) Client will request open port from the server to send the data and the application will send the open port to the client and opens a new thread listening at the port to receive and process the data.Here for each client will have unique port to send the data.
I already implemented a way to know which packet is coming from which client in UDP.
I have 1000+ clients and 60KB data per second I am receiving.
Is there any performance issues using the above methods
or Is here any efficient way to handle this type of task in C ?
Thanks,
Raghu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于如此多的客户端,每个客户端只有一个线程的效率非常低,因为必须执行大量的上下文切换。
此外,每个 IP 可以打开的端口数量是有限的(端口是 16 位数字)。
因此“单套接字”的效率会高得多。但您也可以通过异步 API 将“Multipe Sokets”与单个线程结合使用。如果您可以使用包的有效负载来识别客户端,则不需要每个客户端都有一个端口。
With that many clients, having one thread per client is very inefficient since lots and lots of context switches must be performed.
Also, the number of ports you can open per IP is limited (port is a 16 bit number).
Therefore "Single Socket" will be far more efficient. But you can also use "Multipe Sokets" with just a single thread using the asynchronous API. If you can identify the client using the package's payload, then there is no need to have a port per client.