Skip to content

Wrong intervals between the packets being sent #637

@maxsharabayko

Description

@maxsharabayko

This issue affects network load, packet losses, receive speed and maximum bandwidth calculations, and congestion control for SRT file transfer mode. Time intervals between the packets are likely to be very short, even though the packet sending interval is set to much higher values. E.g. for 500 Mbps the interval between the packets should be approximately 20 us, while the actual time will be even 1 us on certain periods of sending.

Description

The sending thread function CSndQueue::worker() adjusts sending pace by calling to CTimer::sleepto(ts). The function is expected to make this working thread sleep until the timestamp of the next packet to be delivered comes, using:

pthread_cond_timedwait(&m_TickCond, &m_TickLock, &timeout);

where timeout is current time plus 10 ms (see + 10000 below).

timeout.tv_nsec = (now.tv_usec + 10000) * 1000;

Therefore, the implementation of this function makes the minimum sleep interval identical to 10 ms.

The sleep can be interrupted earlier by CRcvQueue::worker_RetrieveUnit() function, that calls m_pTimer->tick(); in the very beginning, and thus signals the conditional variable:

void CTimer::tick()
{
    pthread_cond_signal(&m_TickCond);
}

However, the CRcvQueue::worker_RetrieveUnit() will also wait for 10 ms on a socket in case there are no incoming packets:

tv.tv_usec = 10000;
const int select_ret = ::select((int) m_iSocket + 1, &set, NULL, &set, &tv);

When the waiting time is longer that expected, the CUDT::packData(…) function adds the delay to the m_ullTimeDiff_tk += entertime_tk - m_ullTargetTime_tk;. The target sending time of the next packet will be current time (entertime_tk) plus inter-packet interval (m_ullInterval_t) minus time difference (m_ullTimeDiff_tk):

ts_tk = entertime_tk + m_ullInterval_tk - m_ullTimeDiff_tk;

or just the current time if the difference is higher than the interval value:

ts_tk = entertime_tk;

Therefore further packets will be sent immediately after the previous one.
All these makes the sending pace very inaccurate, especially on Windows. The image below shows the number of bits sent in 10 ms interval. Average sending speed is 500 Mbps, while the deviation is almost +/-100%.
snd-windows

This affects network load, packet losses, receive speed and maximum bandwidth calculations, and congestion control for SRT file transfer mode.

Metadata

Metadata

Assignees

Labels

[core]Area: Changes in SRT library core

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions