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

Increase should never decrease #221

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mengelbart
Copy link
Contributor

When the controller decides to increase the rate, it should not decrease, even if the measured transmission rate was low. The rate could be lower because there was not enough data to send.

When the controller decides to increase the rate, it should not
decrease, even if the measured transmission rate was low. The rate could
be lower because there was not enough data to send.
Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (450ac84) 79.73% compared to head (d095871) 79.64%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #221      +/-   ##
==========================================
- Coverage   79.73%   79.64%   -0.09%     
==========================================
  Files          68       68              
  Lines        3587     3587              
==========================================
- Hits         2860     2857       -3     
- Misses        602      604       +2     
- Partials      125      126       +1     
Flag Coverage Δ
go 79.56% <100.00%> (-0.09%) ⬇️
wasm 77.61% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mengelbart
Copy link
Contributor Author

Draft because we might want to add a test case.

And I don't know what's wrong with that failing test...

@alexpokotilo
Copy link

I've checked and sometimes this branch:
return int(math.Min(float64(c.target+increase), 1.5*float64(c.latestReceivedRate)))
really produced value less than c.target. So in case if we are in "increase" state this fix prevents bandwidth from looping over latestReceivedRate if latestReceivedRate is not enough to increase bandwidth

@alexpokotilo
Copy link

We have a problem with a.variance calculation in *func (a exponentialMovingAverage) update(value float64)
currently we have

a.variance = (1 - decreaseEMAAlpha) * (a.variance + decreaseEMAAlpha*x*x)
=>
a.variance = a.variance + decreaseEMAAlpha*x*x - decreaseEMAAlpha*a.variance - decreaseEMAAlpha*decreaseEMAAlpha*x*x
=>
a.variance = (1 - decreaseEMAAlpha)a.variance + decreaseEMAAlphax*x *(1 - decreaseEMAAlpha)`

but variance should be
a.variance = decreaseEMAAlpha* (x*x) + (1-decreaseEMAAlpha)* a.variance

another problem that we never reset latestDecreaseRate and potentially could always fall into

if c.latestDecreaseRate.average > 0 && float64(c.latestReceivedRate) > c.latestDecreaseRate.average-3*c.latestDecreaseRate.stdDeviation &&
		float64(c.latestReceivedRate) < c.latestDecreaseRate.average+3*c.latestDecreaseRate.stdDeviation {

condition. But standard clearly stats that we MUST reset latestDecreaseRate and go back to "multiplicative increase state".

If R_hat(i) increases above three standard deviations of the average
max bitrate, we assume that the current congestion level has changed,
at which point we reset the average max bitrate and go back to the
multiplicative increase state.

Now if we ever reach "func (c rateController) decrease() int" function
we will never reset latestDecreaseRate and hence if "c.latestReceivedRate" will be close to c.latestDecreaseRate.average calculated previously(an hour ago, a day ago) we will reset target bitrate to 1.5
c.latestDecreaseRate even if we are in "increase" state.

So we must reset c.latestDecreaseRate to not set target bitrate to 1.5 * c.latestReceivedRate in "increase" state if our current c.latestReceivedRate fall in clamps of latestDecreaseRate calculated on last overuse state.

@alexpokotilo alexpokotilo mentioned this pull request Jan 18, 2024
10 tasks
@alexpokotilo
Copy link

Draft because we might want to add a test case.
And I don't know what's wrong with that failing test...

Checker just want you to set go version to 1.19. d095871

Interceptor's main go.mod has 1.15. I don't know how last commit two weeks ago passed this check

last commit to interceptor main has these tests "Test / test-i386 (1.21) / Go i386 1.21 (push) Failing after 43s" failed as well.
I don't think this is related to this fix somehow

@alexpokotilo
Copy link

I've submitted new request #226 containing this fix

@joshforbes
Copy link

We're currently using a forked version of Pion with this change. As we reworked our video streaming code, we needed this change to make bandwidth estimation work smoothly (@danielslee can provide more details if necessary). Just wondering if there is a path to getting this merged? I see that 226 got closed but we didn't need the other changes in 226 - just this one.

Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants