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

[core] New moving average value for sent/recv rates over last second #3009

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

npanhaleux
Copy link
Collaborator

@npanhaleux npanhaleux commented Aug 19, 2024

fixes #1812 - A new class was created to compute received and sent average rates for last second, independent of the call interval.

@maxsharabayko maxsharabayko added this to the v1.5.4 milestone Aug 19, 2024
@maxsharabayko maxsharabayko added Type: Enhancement Indicates new feature requests [core] Area: Changes in SRT library core labels Aug 19, 2024
Copy link
Collaborator

@maxsharabayko maxsharabayko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use formatting from the .clang-format file in the root of the project.

srtcore/buffer_tools.h Outdated Show resolved Hide resolved
srtcore/buffer_tools.h Outdated Show resolved Hide resolved
srtcore/stats.h Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/buffer_tools.h Outdated Show resolved Hide resolved
srtcore/buffer_tools.h Outdated Show resolved Hide resolved
srtcore/stats.h Outdated Show resolved Hide resolved
srtcore/buffer_tools.h Outdated Show resolved Hide resolved
srtcore/core.cpp Outdated Show resolved Hide resolved
@maxsharabayko maxsharabayko changed the title [core] New mobile average value for sent/recv rates over last second [core] New moving average value for sent/recv rates over last second Aug 22, 2024
@maxsharabayko
Copy link
Collaborator

maxsharabayko commented Aug 22, 2024

  • Compiler warning
buffer_tools.cpp:160:7: warning: field 'm_iFirstSampleIdx' will be initialized after field 'm_iCurSampleIdx' [-Wreorder-ctor]
    , m_iFirstSampleIdx(0)
      ^~~~~~~~~~~~~~~~~~~~
      m_iRateBps(0)
  • Socket group mbpdRate calculation not updated.
  • CI failure due to compiler warnings. E.g. this.

@maxsharabayko
Copy link
Collaborator

A pacing file for srt-xtransmit with the following sending rate loop:

0.0 - 2.0 s: 1 Mbps 
2.0 - 3.0 s: 2 Mbps
3.0 - 4.0 s: 5 Mbps
4.0 - 5.5 s: 0 Mbps
5.5 - 7.0 s: 2 Mbps

Usage:

srt-xtransmit generate --playback-csv pacing.csv --duration 20s srt://ip:port --statsfreq 5s --statsfile test-freq5s-snd.csv

pacing.zip

srtcore/core.cpp Outdated Show resolved Hide resolved
srtcore/stats.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@maxsharabayko maxsharabayko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMovingRateEstimator::addSample(int pkts, double bytes) is quite similar to CSndRateEstimator::addSample, but done more nicely and compact.
The main difference I see between the two classes if in how the current rate is calculated. In particular, how not full sampling period participates in rate estimation.
The CMovingRateEstimator just uses the value as it is. It is ok because the sampling interval is 10 ms. The CSndRateEstimator applies a filter:
(rate + 15 * sample_bytes) / 16 to be more sensitive to the newer 100 ms sampling period. Because the estimation is then used for retransmission rate estimation and limiting the retransmission if certain limit is exceeded. BTW this filtering is not necessarily correct.

So potentially both lasses could be merged if switching to a finer 10 ms sampling is ok for the retransmission rate estimation (I guess it is ok).

srtcore/buffer_tools.h Outdated Show resolved Hide resolved
srtcore/buffer_tools.cpp Outdated Show resolved Hide resolved
srtcore/buffer_tools.cpp Outdated Show resolved Hide resolved
srtcore/buffer_tools.cpp Outdated Show resolved Hide resolved
srtcore/buffer_tools.cpp Outdated Show resolved Hide resolved
srtcore/buffer_tools.cpp Outdated Show resolved Hide resolved
newRateBps += (m_Samples[i].m_iBytesCount + (CPacket::HDR_SIZE * m_Samples[i].m_iPktsCount));

if (isFirstPeriod)
newRateBps = newRateBps * 1000 / startDelta;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!! Division by zero not prevented!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is :) We don't go in the computeAverageValue method if iSampleDeltaIdx == 0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ RUN      ] TestSocketOptions.LossMaxTTL
/home/travis/.travis/functions: line 109:  7133 Floating point exception(core dumped) ./test-srt -disable-ipv6
[New LWP 7133]
[New LWP 7746]
[New LWP 7749]
[New LWP 7750]
[New LWP 7745]
[New LWP 7747]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./test-srt -disable-ipv6'.
Program terminated with signal SIGFPE, Arithmetic exception.
#0  0x000000000087cafc in srt::CMovingRateEstimator::computeAverageValue (this=0x7fe6bc005cb8) at /home/travis/build/Haivision/srt/srtcore/buffer_tools.cpp:334
334	        newRateBps = newRateBps * 1000 / startDelta;
[Current thread is 1 (Thread 0x7fe6c9ee9740 (LWP 7133))]
#0  0x000000000087cafc in srt::CMovingRateEstimator::computeAverageValue (this=0x7fe6bc005cb8) at /home/travis/build/Haivision/srt/srtcore/buffer_tools.cpp:334
#1  0x000000000087c94d in srt::CMovingRateEstimator::addSample (this=0x7fe6bc005cb8, pkts=0, bytes=0) at /home/travis/build/Haivision/srt/srtcore/buffer_tools.cpp:313
#2  0x00000000008d80bb in srt::stats::Sender::updateRate (this=0x7fe6bc005c18, pkts=0, bytes=0) at /home/travis/build/Haivision/srt/srtcore/stats.h:174
#3  0x00000000008b934a in srt::CUDT::bstats (this=0x7fe6bc000938, perf=0x7ffd64377750, clear=false, instantaneous=false) at /home/travis/build/Haivision/srt/srtcore/core.cpp:7577
#4  0x000000000085bfe3 in srt::CUDT::bstats (u=412356694, perf=0x7ffd64377750, clear=false, instantaneous=false) at /home/travis/build/Haivision/srt/srtcore/api.cpp:4338

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is :) We don't go in the computeAverageValue method if iSampleDeltaIdx == 0.

The division by 0 is made using the value that is calculated out of the present time taken exactly in this function, so there's even no possibility that you could control this value this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make mbpsSendRate stat independent on srt_bstats(..) call interval
3 participants