简体   繁体   English

可靠的UDP实施设计问题

[英]Reliable UDP implementation design issue

I have been working on a customization around UDP to make it reliable. 我一直在围绕UDP进行自定义,以使其可靠。 I have this design problem which I realized only after my entire program was ready and I started sending packets from source to sink. 我有这个设计问题,只有在整个程序准备好并且开始将数据包从源发送到接收器后,我才意识到。

Scenario: I created a single thread for reception of packets. 场景:我创建了一个用于接收数据包的单线程。 The parent does packet sending job. 父级执行数据包发送作业。 Since this is just a POC, I have kept the buffer and common data structures as global pointer for whom memory is allocated on heap by the parent. 由于这只是一个POC,因此我将缓冲区和公共数据结构保留为全局指针,由父级为其分配内存。 I am taking care of critical memory sections using mutex. 我正在照顾使用互斥的关键内存部分。

As part of reliability I send across some control packets apart from data packets. 作为可靠性的一部分,我跨数据包发送了一些控制包。 At anytime, client will send data packets and receive control packets from server whereas server will receive data packets and send out control packets. 在任何时候,客户端将发送数据包并从服务器接收控制包,而服务器将接收数据包并发送控制包。 I have used single socket, as my understanding is send & recv works simultaneously on single socket and default blocking. 我使用了单套接字,因为我的理解是send&recv可同时在单套接字和默认阻止下工作。

Problem: For test purpose, I send 100 packets from source to sink. 问题:出于测试目的,我从源向接收器发送了100个数据包。 Unfortunately, the thread on the server side busy keeps receiving packets and stores it in buffer. 不幸的是,服务器端的线程正忙于接收数据包并将其存储在缓冲区中。 Server code isn't delivering packets to application until the parent thread gets the context switch. 在父线程获得上下文切换之前,服务器代码不会将数据包传递给应用程序。 This add to unacceptable delay in overall communication. 这增加了整体通信中无法接受的延迟。

Please help me understand, what is the issue; 请帮助我了解问题所在; what can be changed to improve the performance? 可以进行哪些更改以提高性能?

Thanks in advance, Kedar 在此先感谢Kedar

Since you're using a mutex, when the mutex is released on one thread after the packets are sent, then the other thread should consume the packet. 由于使用的是互斥锁,因此在发送数据包后在一个线程上释放互斥锁时,另一个线程应该使用该数据包。 Perhaps you are not releasing the mutex soon enough. 也许您没有足够快地释放互斥量。

Alternately, let the socket's select() method handle the unblock-on-receive for you. 或者,让套接字的select()方法为您处理接收时解除阻塞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM