High Performance Service Framework REVOLVER:RUDP (reliable UDP) algorithm detailed (2)

Source: Internet
Author: User

In addition to the Send function, the send buffer object responds to On_ack and on_nack messages from the network, which are the network reports that handle normal status reports and packet drops, respectively. If On_ack is received, the buffer object removes all message IDs that have been reported by the receiving end from the Send window, and then calls Attempt_send to attempt a new block to send. If you receive a on_nack that indicates a packet loss to the end, the ID of the packet is first recorded in Loss_set, and then the on_ack is called for processing.

Triggering attempt_send is also possible timer timer, timer every 5MS will check the send buffer, and call Attempt_send try to send and check whether the buffer is writable.


The Attempt_send function pseudo-code is as follows:

void Rudpsendbuffer::attempt_send (uint64_t now_timer) {uint32_t cwnd_size = Send_window_.size (); uint32_t RTT = ccc_- >get_rtt (); uint32_t ccc_cwnd_size = Ccc_->get_send_window_size (); rudpsendsegment* seg = null;uint32_t Send_packet_number = 0;if (!loss_set_.empty ())//Resend Lost fragment {//Send message in packet drop queue uint64_t loss _last_ts = 0;uint64_t Loss_last_seq = 0;for (Lossidset::iterator it = Loss_set_.begin (); It! = Loss_set_.end ();)//Check if the missing message To resend {if (Send_packet_number >= ccc_cwnd_size)//exceed Send window break; Sendwindowmap::iterator cwnd_it = Send_window_.find (*it); if (cwnd_it! = Send_window_.end () && cwnd_it-> Second->last_send_ts_ + RTT < Now_timer)//Lost packets must be sent in the window {seg = CWND_IT-&GT;SECOND;//UDP network Send Net_channel_->send_ Data (0, Seg->seq_, Seg->data_, Seg->data_size_, Now_timer); if (Cwnd_max_seq_ < seg->seq_) cwnd_max_seq_ = seg->seq_;//Determine if Tsif (Loss_last_ts < Seg->last_send_ts_) can be changed {Loss_last_ts = Seg->last_send_ts_;if (loss _last_seq < *it) loss_last_seq = *it;} Seg->laSt_send_ts_ = Now_timer;seg->send_count_ ++;send_packet_number ++;loss_set_.erase (it + +);//Report CCC has re-issued Ccc_->add_ Resend ();} else++ it;} Update the time in the range of the package to not resend the message, prevent the next time the timer arrives repeatedly send for (sendwindowmap::iterator it = Send_window_.begin (); It! = Send_window_.end (); + + It) {if (It->second->push_ts_ < loss_last_ts && loss_last_seq >= it->first) it->second-> Last_send_ts_ = Now_timer;else if (Loss_last_seq < It->first) break;}} else if (send_window_.size () > 0)//drop-off queue is empty, resend timeout in all Windows Shard {//Send Inter time interval threshold uint32_t rtt_threshold = (uint32_t) ceil (RTT * 1.25) ; rtt_threshold = (Core_max (rtt_threshold, 30)); Sendwindowmap::iterator end_it = Send_window_.end (); for (Sendwindowmap::iterator it = Send_window_.begin (); it! = End_it ; ++it) {if (send_packet_number >= ccc_cwnd_size | | (It->second->push_ts_ + rtt_threshold > Now_timer)) BREAK;SEG = it->second;//the trigger condition of the resend block is that the last send time distance is now greater than the specific threshold or the push-in time is very long and belongs to the front of the send buffer block if (Seg->last_send_ts_ + rtt_ Threshold < Now_timer | | (Seg->push_ts_ + rtt_tHreshold * 5 < Now_timer && Seg->seq_ < dest_max_seq_ + 3 && seg->last_send_ts_ + Rtt_threshol D/2 < Now_timer) {net_channel_->send_data (0, Seg->seq_, Seg->data_, Seg->data_size_, Now_timer); Cwnd_max_seq_ < seg->seq_) Cwnd_max_seq_ = Seg->seq_;seg->last_send_ts_ = Now_timer;seg->send_count_ + + ; Send_packet_number ++;//Report CCC has re-hair block ccc_->add_resend ();}} Determine if a new message can be sent if (Ccc_cwnd_size > Send_packet_number) {while (!send_data_.empty ()) {rudpsendsegment* seg = Send_data _.front ();//Judge Nagle algorithm, Nagle need at least 100MS to gather 1024 bytes of message if (cwnd_size > 0 && nagle_ && seg->push_ts_ + Nagle_delay > Now_timer && seg->data_size_ < max_segment_size-256) break;//determine the Send window if (Cwnd_size < CCC _cwnd_size) {Send_data_.pop_front (); Send_window_.insert (Sendwindowmap::value_type (seg->seq_, SEG)); Cwnd_size + +;seg->push_ts_ = Now_timer;seg->last_send_ts_ = Now_timer;seg->send_count_ = 1;//UDP network Send net_channel_-> Send_datA (0, seg->seq_, Seg->data_, Seg->data_size_, Now_timer); if (Cwnd_max_seq_ < seg->seq_) Cwnd_max_seq_ = Seg->seq_;} else//Send window full, stop sending break;}}}

From the above can be learned that Attempt_send is the first to check whether the loss of the message can be sent, and then check the window is too old to resend, and finally add a new send message. All prerequisite constraints are no more than the Send window. In this function, the CCC determines the sending window size and the RTT directly controls the sending speed and the sending strategy.Here is worth mentioning is the implementation of the Nagle, rudp in order to prevent the packet too much, the implementation of a Nagle algorithm, if the switch is set, if only 1 blocks in the buffer queue, will wait for the data to reach 1024 of the length before sending. If the 100MS does not reach 1024 length will also be sent, that is, the maximum 100MS. The switch can be set by RUDP interface.

Receive buffers

High Performance Service Framework REVOLVER:RUDP (reliable UDP) algorithm detailed (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.