Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udp 是否有类似 TcpServer 的性能优化 #35

Closed
wasphin opened this issue Jul 6, 2020 · 4 comments
Closed

udp 是否有类似 TcpServer 的性能优化 #35

wasphin opened this issue Jul 6, 2020 · 4 comments

Comments

@wasphin
Copy link
Member

wasphin commented Jul 6, 2020

目前看 udp server 主要看主要是在 rtsp 及 rtpproxy 部分用到, 对性能要求可能不高.

我这边的情况是需要一个及主要通过 udp 接入的服务器, 这边是否有类似 TcpServer 这样的优化方案呢?

这里只有一个 tcp 的 connect 接口
https://github.com/xiongziliang/ZLToolKit/blob/ed47015f92cc79dfe3344b3666aafb54f1bbc2f4/src/Network/sockutil.h#L62

udp 也可以 connect

   If the socket sockfd is of type SOCK_DGRAM, then addr is the address to
   which datagrams are sent by default, and the only  address  from  which
   datagrams  are  received.   If  the  socket  is  of type SOCK_STREAM or
   SOCK_SEQPACKET, this call attempts to make a connection to  the  socket
   that is bound to the address specified by addr.

这样如果双向 connect 一下, 是否可以实现类似 TcpServer 中的效果? 这部分相关的改动如果有的话, 是否会考虑合到项目中?

@xia-chu
Copy link
Member

xia-chu commented Jul 6, 2020

udp connect 其实并没什么用 只是设置下对端的地址 这样可以调用write和send函数(而不用sendto).

一个udp端口对应一个fd,所以一般只能对应一条线程。所以要提高udp的性能,一般通过多个udp端口解决。

@xia-chu
Copy link
Member

xia-chu commented Jul 6, 2020

TcpServer中,一个tcp端口,有一个listen fd, 在收到accept事件后,能创建多个peerfd。
这个listen fd是多个线程监听的,可以多个线程同时accept,accept成功后有有一个peerfd,这个peerfd会 绑定到这条accept线程

@xia-chu
Copy link
Member

xia-chu commented Jul 6, 2020

也就是说 tcp服务器单端口能发挥多核cpu的性能,但是udp单端口只能发挥单条线程的性能

@wasphin
Copy link
Member Author

wasphin commented Jul 6, 2020

了解了, 多谢解答.

@wasphin wasphin closed this as completed Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants