From 94103967933f4720d0d053735cd1da5e3bbe7a86 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 23 Sep 2020 15:07:12 +0200 Subject: Pull in common 0c5bf36: spread UDP packets over time to avoid bursts --- contrib/edi/Transport.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'contrib') diff --git a/contrib/edi/Transport.cpp b/contrib/edi/Transport.cpp index d8627fd..fa7588a 100644 --- a/contrib/edi/Transport.cpp +++ b/contrib/edi/Transport.cpp @@ -26,6 +26,7 @@ */ #include "Transport.h" #include +#include using namespace std; @@ -131,6 +132,12 @@ void Sender::write(const TagPacket& tagpacket) edi_fragments.size()); } + /* Spread out the transmission of all fragments over 75% of the 24ms AF packet duration + * to reduce the risk of losing fragments because of congestion. + * + * 75% was chosen so that other outputs still have time to do their thing. */ + const auto inter_fragment_wait_time = std::chrono::microseconds(llrint(0.75 * 24000.0 / edi_fragments.size())); + // Send over ethernet for (auto& edi_frag : edi_fragments) { if (m_conf.dump) { @@ -155,6 +162,8 @@ void Sender::write(const TagPacket& tagpacket) throw logic_error("EDI destination not implemented"); } } + + std::this_thread::sleep_for(inter_fragment_wait_time); } } else { -- cgit v1.2.3