fix(transport): recover rover feedback and retained WireGuard routes
This commit is contained in:
@@ -168,6 +168,7 @@ func (b *LinkBudget) tryLocked(class string, size int) (bool, time.Duration) {
|
||||
}
|
||||
if h := &b.runtime.feedback; h.enabled && h.sent-h.acknowledged+uint64(cost) > h.window {
|
||||
c.deferred++
|
||||
h.deferred = now
|
||||
return false, 10 * time.Millisecond
|
||||
}
|
||||
if b.tokens >= cost && c.tokens >= cost {
|
||||
@@ -180,6 +181,9 @@ func (b *LinkBudget) tryLocked(class string, size int) (bool, time.Duration) {
|
||||
return true, 0
|
||||
}
|
||||
c.deferred++
|
||||
if b.runtime.feedback.enabled {
|
||||
b.runtime.feedback.deferred = now
|
||||
}
|
||||
return false, 10 * time.Millisecond
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,28 @@ package node
|
||||
|
||||
// Independently bound optional egress when command UDP remains healthy but the
|
||||
// return path is congested. Probes never wait for permits; no authority lives here.
|
||||
import "time"
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
const feedbackMinWindow = uint64(linkPacket + linkOverhead)
|
||||
const feedbackMaxWindow = uint64(128 * 1024)
|
||||
|
||||
// Credit covers one probe period (or the measured path RTT when larger).
|
||||
// A fixed 128 KiB window imposed a 10.49 Mbit/s ceiling regardless of the
|
||||
// existing adaptive send budget. Bound credit by that budget instead; this
|
||||
// neither measures physical capacity nor relaxes silence/command guards.
|
||||
func (b *LinkBudget) feedbackMaxWindow() uint64 {
|
||||
period := max(100*time.Millisecond, b.baseline)
|
||||
return max(uint64(linkClassBurst), uint64(math.Min(b.effective, b.ceiling())*125*period.Seconds()))
|
||||
}
|
||||
|
||||
type linkDatagramFeedback struct {
|
||||
enabled bool
|
||||
seen, adjusted, healthy, delayed time.Time
|
||||
deferred time.Time
|
||||
recoverUntil time.Time
|
||||
recoverWindow uint64
|
||||
sent, acknowledged, window uint64
|
||||
rtt time.Duration
|
||||
limited bool
|
||||
@@ -76,6 +90,10 @@ func (b *LinkBudget) feedbackLimited(now time.Time) bool {
|
||||
return false
|
||||
}
|
||||
if now.Sub(h.seen) > max(250*time.Millisecond, b.baseline+150*time.Millisecond) {
|
||||
if !h.limited {
|
||||
h.recoverWindow = h.window
|
||||
h.recoverUntil = h.seen.Add(5 * time.Second)
|
||||
}
|
||||
h.recordPressure(now, "feedback_silence", now.Sub(h.seen), h.rtt, max(250*time.Millisecond, b.baseline+150*time.Millisecond))
|
||||
// A silent return path invalidates the previously grown send window.
|
||||
// Latch pressure before updating seen: one fresh ACK after a blackout
|
||||
@@ -110,6 +128,7 @@ func (b *LinkBudget) ObserveDatagramFeedback(elapsed time.Duration, coreMS float
|
||||
b.feedbackLimited(now)
|
||||
outstanding := h.sent - h.acknowledged
|
||||
gap := now.Sub(h.seen)
|
||||
freshBytes := mark - h.acknowledged
|
||||
h.acknowledged = mark
|
||||
h.seen = now
|
||||
if coreMS >= 0 && coreMS <= float64(elapsed.Microseconds())/1000 {
|
||||
@@ -120,6 +139,13 @@ func (b *LinkBudget) ObserveDatagramFeedback(elapsed time.Duration, coreMS float
|
||||
if h.delayed.IsZero() {
|
||||
h.delayed = now
|
||||
}
|
||||
// The first echo after a short gap may itself have queued during the
|
||||
// outage. It still suspends payload below, but is not sustained evidence
|
||||
// that the previously working window is unusable. Preserve only the
|
||||
// existing expiring recovery target; fresh useful ACKs must earn growth.
|
||||
if now.Sub(h.delayed) >= 200*time.Millisecond {
|
||||
h.recoverWindow = 0
|
||||
}
|
||||
// Moderate jitter shrinks outstanding optional bytes without turning a
|
||||
// viable video stream off. Full suspension is reserved for severe delay
|
||||
// or silence; neither condition changes command authority or watchdogs.
|
||||
@@ -155,10 +181,27 @@ func (b *LinkBudget) ObserveDatagramFeedback(elapsed time.Duration, coreMS float
|
||||
}
|
||||
h.limited = false
|
||||
}
|
||||
// Grow only when useful demand used the window, at most once per probe
|
||||
// period. ACK bursts after a stall cannot manufacture a large new window.
|
||||
if elapsed <= b.baseline+25*time.Millisecond && outstanding >= h.window/2 && (h.adjusted.IsZero() || now.Sub(h.adjusted) >= 100*time.Millisecond) {
|
||||
h.window = min(feedbackMaxWindow, h.window+linkPacket)
|
||||
// A quiet primary camera can use much less than its priority allocation.
|
||||
// Requiring half the window to be spent then traps waiting cloud packets
|
||||
// below that allocation forever. Recent denied *real packets* may also
|
||||
// probe upward when aggregate demand exceeds this window's rate. An idle
|
||||
// producer declaration alone never grows credit or generates probe payload.
|
||||
period := max(100*time.Millisecond, b.baseline)
|
||||
waiting := !h.deferred.IsZero() && now.Sub(h.deferred) <= 100*time.Millisecond &&
|
||||
b.demand(now) > float64(h.window)*8/period.Seconds()
|
||||
// Retain the healthy-echo and once-per-period gates. ACK bursts after a
|
||||
// stall cannot mint a large window or override command pressure.
|
||||
if elapsed <= b.baseline+25*time.Millisecond && !b.commandLimited(now) &&
|
||||
(outstanding >= h.window/2 || waiting) && (h.adjusted.IsZero() || now.Sub(h.adjusted) >= 100*time.Millisecond) {
|
||||
growth := max(uint64(linkPacket), h.window/8)
|
||||
// A recently working path may regain its previous window from fresh
|
||||
// useful ACKs. Never restore tokens or jump straight to stale credit:
|
||||
// at most one current window per healthy period, below both ceilings.
|
||||
if now.Before(h.recoverUntil) && h.window < h.recoverWindow {
|
||||
growth = max(growth, min(freshBytes, h.window, h.recoverWindow-h.window))
|
||||
}
|
||||
h.window = min(b.feedbackMaxWindow(), h.window+growth)
|
||||
h.adjusted = now
|
||||
h.deferred = time.Time{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,76 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHealthyFeedbackRecoversWhenPriorityLeavesCloudStarved(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.effective = 50000
|
||||
b.SetControl(false)
|
||||
b.EnableDatagramFeedback()
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
b.runtime.feedback.window = 64000
|
||||
primary, cloud := "11111111111111111111111111111111", "33333333333333333333333333333333"
|
||||
for tick := 0; tick < 300; tick++ {
|
||||
*now = now.Add(10 * time.Millisecond)
|
||||
if tick%50 == 0 {
|
||||
b.allocateRole(primary, "video", true, 5000000, true)
|
||||
b.allocateRole(cloud, "cloud", true, 8000000, false)
|
||||
}
|
||||
// A quiet primary image uses little of its declared bitrate. Real cloud
|
||||
// packets keep waiting behind its priority share after a window collapse.
|
||||
b.Try("cloud", 1000)
|
||||
if tick%10 == 0 {
|
||||
b.SetControl(false)
|
||||
b.Try("video", 1100)
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, b.DatagramFeedbackMark())
|
||||
}
|
||||
}
|
||||
if b.classes["cloud"].bytes < 270000 || b.classRates(*now)["cloud"] < 800000 {
|
||||
t.Fatal("healthy unsent cloud demand could not grow past the quiet primary share", b.Snapshot())
|
||||
}
|
||||
if b.runtime.feedback.window > b.feedbackMaxWindow() {
|
||||
t.Fatal("pending demand bypassed adaptive ceiling")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeclaredDemandWithoutWaitingPacketsDoesNotGrowFeedback(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.effective = 50000
|
||||
b.SetControl(false)
|
||||
b.EnableDatagramFeedback()
|
||||
b.allocateRole("33333333333333333333333333333333", "cloud", true, 8000000, false)
|
||||
initial := b.runtime.feedback.window
|
||||
for i := 0; i < 10; i++ {
|
||||
*now = now.Add(100 * time.Millisecond)
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
}
|
||||
if b.runtime.feedback.window != initial {
|
||||
t.Fatal("idle declaration manufactured feedback credit", b.runtime.feedback.window)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthyFeedbackWindowFollowsAdaptiveBudgetNotFixedTenMbps(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.effective = 50000
|
||||
b.EnableDatagramFeedback()
|
||||
for i := 0; i < 80; i++ {
|
||||
*now = now.Add(100 * time.Millisecond)
|
||||
b.SetControl(false)
|
||||
b.runtime.feedback.sent += b.runtime.feedback.window
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, b.runtime.feedback.sent)
|
||||
}
|
||||
if b.runtime.feedback.window <= 128*1024 || b.optional(*now) <= 10486 {
|
||||
t.Fatal("healthy useful traffic retained fixed window ceiling", b.runtime.feedback.window, b.optional(*now))
|
||||
}
|
||||
if b.runtime.feedback.window > b.feedbackMaxWindow() {
|
||||
t.Fatal("feedback credit escaped adaptive budget")
|
||||
}
|
||||
*now = now.Add(300 * time.Millisecond)
|
||||
b.ObserveCommandFrame(50*time.Millisecond, 10*time.Millisecond)
|
||||
if b.optional(*now) != 0 {
|
||||
t.Fatal("larger healthy window bypassed return-path silence")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDatagramFeedbackBoundsOptionalBytesDespiteHealthyDownlink(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.EnableDatagramFeedback()
|
||||
@@ -64,7 +134,7 @@ func TestDatagramFeedbackSilenceLatchesBeforeFreshEcho(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.EnableDatagramFeedback()
|
||||
b.ObserveDatagramFeedback(100*time.Millisecond, 0, 0)
|
||||
b.runtime.feedback.window = feedbackMaxWindow
|
||||
b.runtime.feedback.window = b.feedbackMaxWindow()
|
||||
b.tokens = linkBurst
|
||||
b.classes["video"].tokens = linkClassBurst
|
||||
*now = now.Add(time.Second)
|
||||
@@ -155,3 +225,77 @@ func TestDatagramFeedbackRetainsInitiatingPressureAcrossRecovery(t *testing.T) {
|
||||
t.Fatal("new transport would inherit old diagnostic identity")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShortFeedbackGapRecoversUsefulCloudFromFreshAcknowledgements(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.effective = 35000
|
||||
b.SetControl(false)
|
||||
b.EnableDatagramFeedback()
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
b.runtime.feedback.window = 240000
|
||||
*now = now.Add(300 * time.Millisecond)
|
||||
b.Snapshot()
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
for tick := 0; tick < 300; tick++ {
|
||||
*now = now.Add(10 * time.Millisecond)
|
||||
if tick%10 == 0 {
|
||||
b.SetControl(false)
|
||||
b.allocateRole("11111111111111111111111111111111", "video", true, 5000000, true)
|
||||
b.allocateRole("33333333333333333333333333333333", "cloud", true, 8000000, false)
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, b.DatagramFeedbackMark())
|
||||
}
|
||||
b.Try("video", 300)
|
||||
b.Try("cloud", 1000)
|
||||
}
|
||||
if b.classes["cloud"].bytes < 150000 {
|
||||
t.Fatal("healthy recovery kept cloud starved for three seconds", b.classes["cloud"].bytes, b.runtime.feedback.window)
|
||||
}
|
||||
if b.runtime.feedback.window > b.feedbackMaxWindow() {
|
||||
t.Fatal("recovery bypassed adaptive ceiling")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedbackRecoveryNeverRestoresStaleCredit(t *testing.T) {
|
||||
for _, scenario := range []string{"no-new-bytes", "expired", "command-pressure", "delayed"} {
|
||||
t.Run(scenario, func(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.effective = 35000
|
||||
b.EnableDatagramFeedback()
|
||||
b.SetControl(false)
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
h := &b.runtime.feedback
|
||||
h.window = 240000
|
||||
*now = now.Add(300 * time.Millisecond)
|
||||
b.Snapshot()
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
*now = now.Add(201 * time.Millisecond)
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
h.window = 8000
|
||||
h.adjusted = *now
|
||||
h.sent += 8000
|
||||
mark := h.sent
|
||||
if scenario == "no-new-bytes" {
|
||||
h.acknowledged = mark
|
||||
}
|
||||
if scenario == "expired" {
|
||||
h.recoverUntil = *now
|
||||
}
|
||||
*now = now.Add(100 * time.Millisecond)
|
||||
if scenario == "command-pressure" {
|
||||
b.SetControl(true)
|
||||
b.ObserveCommandFrame(400*time.Millisecond, 0)
|
||||
}
|
||||
elapsed := 15 * time.Millisecond
|
||||
if scenario == "delayed" {
|
||||
elapsed = 300 * time.Millisecond
|
||||
}
|
||||
b.ObserveDatagramFeedback(elapsed, 0, mark)
|
||||
if h.window > 10048 {
|
||||
t.Fatal("stale or pressured path gained recovery credit", h.window)
|
||||
}
|
||||
if b.tokens != 0 {
|
||||
t.Fatal("recovery manufactured burst tokens", b.tokens)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The first returning probe can have spent the short outage in the network.
|
||||
// Only later healthy acknowledgements justify recovery of useful traffic.
|
||||
func TestFeedbackRecoveryAfterDelayedFirstEcho(t *testing.T) {
|
||||
for _, firstRTT := range []time.Duration{15 * time.Millisecond, 300 * time.Millisecond} {
|
||||
t.Run(firstRTT.String(), func(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.effective = 35000
|
||||
b.SetControl(false)
|
||||
b.EnableDatagramFeedback()
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
b.runtime.feedback.window = 240000
|
||||
*now = now.Add(300 * time.Millisecond)
|
||||
b.Snapshot()
|
||||
b.ObserveDatagramFeedback(firstRTT, 0, b.DatagramFeedbackMark())
|
||||
if ok, _ := b.Try("video", 1000); ok {
|
||||
t.Fatal("first returning echo reopened payload without stable feedback")
|
||||
}
|
||||
for tick := 0; tick < 200; tick++ {
|
||||
*now = now.Add(10 * time.Millisecond)
|
||||
if tick%10 == 0 {
|
||||
b.SetControl(false)
|
||||
b.allocateRole("11111111111111111111111111111111", "video", true, 5000000, true)
|
||||
b.allocateRole("33333333333333333333333333333333", "cloud", true, 8000000, false)
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, b.DatagramFeedbackMark())
|
||||
}
|
||||
for packet := 0; packet < 8; packet++ {
|
||||
b.Try("video", 1000)
|
||||
b.Try("cloud", 1000)
|
||||
}
|
||||
}
|
||||
t.Logf("window=%d video=%d cloud=%d", b.runtime.feedback.window, b.classes["video"].bytes, b.classes["cloud"].bytes)
|
||||
if b.runtime.feedback.window < 128000 || b.classes["cloud"].bytes < 100000 {
|
||||
t.Fatal("a delayed first echo stranded the recovered path at a low rate", b.Snapshot())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedbackRecoveryTargetRetiresOnSustainedDelay(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.SetControl(false)
|
||||
b.EnableDatagramFeedback()
|
||||
b.ObserveDatagramFeedback(15*time.Millisecond, 0, 0)
|
||||
b.runtime.feedback.window = 240000
|
||||
*now = now.Add(300 * time.Millisecond)
|
||||
b.Snapshot()
|
||||
b.ObserveDatagramFeedback(300*time.Millisecond, 0, 0)
|
||||
for i := 0; i < 3; i++ {
|
||||
*now = now.Add(100 * time.Millisecond)
|
||||
b.ObserveDatagramFeedback(300*time.Millisecond, 0, 0)
|
||||
if ok, _ := b.Try("video", 1000); ok {
|
||||
t.Fatal("sustained delay admitted optional payload")
|
||||
}
|
||||
}
|
||||
if b.runtime.feedback.recoverWindow != 0 || !b.runtime.feedback.limited {
|
||||
t.Fatal("sustained delay retained short-gap recovery credit")
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,81 @@ func TestExplicitOperatorViewPrecedesResidualTraffic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecondaryVideosShareResidualWithFullCloudDemand(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.SetControl(false)
|
||||
b.effective = 10500
|
||||
primary := "11111111111111111111111111111111"
|
||||
b.allocateRole(primary, "video", true, 5000000, true)
|
||||
b.allocateRole("22222222222222222222222222222222", "video", true, 5000000, false)
|
||||
b.allocateRole("33333333333333333333333333333333", "video", true, 5000000, false)
|
||||
b.allocateRole("44444444444444444444444444444444", "cloud", true, 12000000, false)
|
||||
rates := b.classRates(*now)
|
||||
a, _ := b.allocateRole(primary, "video", true, 5000000, true)
|
||||
if a["allocation_bps"] != 5000000 || rates["cloud"] <= 500000 || rates["video"] <= 5000000 {
|
||||
t.Fatal("secondary cameras inherited priority or cloud could not use residual", a, rates)
|
||||
}
|
||||
if rates["cloud"]+rates["video"] > b.optional(*now)*1000 {
|
||||
t.Fatal("residual traffic exceeded shared budget", rates)
|
||||
}
|
||||
// A healthy larger allocation satisfies real demand, without a cloud ceiling.
|
||||
b.effective = 50000
|
||||
rates = b.classRates(*now)
|
||||
if rates["cloud"] != 12000000 || rates["video"] != 15000000 {
|
||||
t.Fatal("unused healthy capacity did not satisfy media demand", rates)
|
||||
}
|
||||
b.SetControl(true)
|
||||
b.effective = b.reserve(*now) + 3000
|
||||
if b.classRates(*now)["cloud"] != 0 {
|
||||
t.Fatal("cloud displaced primary camera during control")
|
||||
}
|
||||
}
|
||||
|
||||
func TestObservedPrimaryAllowsBoundedCloudWithoutBorrowingControl(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
primary, cloud := "11111111111111111111111111111111", "33333333333333333333333333333333"
|
||||
b.SetControl(false)
|
||||
b.allocateRole(primary, "video", true, 5000000, true)
|
||||
b.allocateRole(cloud, "cloud", true, 256000, false)
|
||||
rates := b.classRates(*now)
|
||||
if rates["cloud"] != 128000 || rates["video"] <= rates["cloud"] {
|
||||
t.Fatal("observing cloud starved or displaced primary video", rates)
|
||||
}
|
||||
if rates["cloud"]+rates["video"] > b.optional(*now)*1000 {
|
||||
t.Fatal("preview floor exceeded aggregate budget", rates)
|
||||
}
|
||||
// Preview credit passes through the same packet gate; no separate lane.
|
||||
*now = now.Add(100 * time.Millisecond)
|
||||
if ok, _ := b.Try("cloud", 1000); !ok {
|
||||
t.Fatal("allocated cloud could not progress through packet admission")
|
||||
}
|
||||
b.SetControl(true)
|
||||
if b.classRates(*now)["cloud"] != 0 {
|
||||
t.Fatal("cloud floor escaped active-control priority")
|
||||
}
|
||||
if ok, _ := b.Try("cloud", 1000); ok {
|
||||
t.Fatal("old cloud credit survived protected transition")
|
||||
}
|
||||
b.SetControl(false)
|
||||
*now = now.Add(2100 * time.Millisecond)
|
||||
if b.classRates(*now)["cloud"] != 0 {
|
||||
t.Fatal("cloud floor escaped stale-control priority")
|
||||
}
|
||||
b.SetControl(false)
|
||||
b.effective = b.reserve(*now) + 128
|
||||
rates = b.classRates(*now)
|
||||
if rates["cloud"] <= 0 || rates["cloud"] > b.optional(*now)*1000*2/11 {
|
||||
t.Fatal("weak-link cloud exceeded ordinary class share", rates)
|
||||
}
|
||||
b.allocateRole(cloud, "cloud", false, 256000, false)
|
||||
*now = now.Add(2100 * time.Millisecond)
|
||||
b.SetControl(false)
|
||||
b.allocateRole(primary, "video", true, 5000000, true)
|
||||
if b.classRates(*now)["cloud"] != 0 {
|
||||
t.Fatal("closed preview retained a reserved floor")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedViewHasBoundedModerateJitterProfileAndEmergencyYield(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
primary := "11111111111111111111111111111111"
|
||||
|
||||
@@ -302,22 +302,33 @@ func (b *LinkBudget) classRates(now time.Time) map[string]float64 {
|
||||
if b.primaryVideo(now) == "" {
|
||||
return waterfill(total, linkWeights, demands)
|
||||
}
|
||||
// During observation, explicitly requested recording transfer must make
|
||||
// bounded progress even when the selected camera demands all capacity.
|
||||
// Its floor is at most the ordinary 1/11 share and 32 kbit/s, taken from
|
||||
// the SAME optional budget. Active/stale control and command pressure
|
||||
// retain strict primary-video priority; exports never borrow its reserve.
|
||||
// During observation, requested cloud preview and recording transfer must
|
||||
// make bounded progress even when the selected camera demands all capacity.
|
||||
// Use their ordinary class shares, capped at 128/32 kbit/s, from the SAME
|
||||
// optional budget. Active/stale control and command pressure retain strict
|
||||
// primary-video priority; background traffic never borrows its reserve.
|
||||
rates := map[string]float64{}
|
||||
if !b.protected(now) {
|
||||
rates["cloud"] = math.Min(demands["cloud"], math.Min(128000, total*2/11))
|
||||
rates["bulk"] = math.Min(demands["bulk"], math.Min(32000, total/11))
|
||||
total -= rates["bulk"]
|
||||
total -= rates["cloud"] + rates["bulk"]
|
||||
demands["cloud"] -= rates["cloud"]
|
||||
demands["bulk"] -= rates["bulk"]
|
||||
}
|
||||
rates["inventory"] = math.Min(total, math.Min(32000, demands["inventory"]))
|
||||
total -= rates["inventory"]
|
||||
rates["video"] = math.Min(total, demands["video"])
|
||||
// The floor guarantees progress when the camera consumes the link; it is
|
||||
// not a ceiling on finite signalling/blueprint receipts. Admit the rest
|
||||
// from residual capacity after the selected operator camera is satisfied.
|
||||
demands["inventory"] -= rates["inventory"]
|
||||
// Only the selected operator camera owns priority. Other cameras/viewers
|
||||
// share residual capacity with cloud/export instead of inheriting that
|
||||
// priority merely because they use the same video packet class.
|
||||
primary := b.producers[b.primaryVideo(now)]
|
||||
rates["video"] = math.Min(total, float64(primary.demand))
|
||||
total -= rates["video"]
|
||||
for key, value := range waterfill(total, map[string]float64{"cloud": 1, "bulk": 1}, demands) {
|
||||
demands["video"] -= rates["video"]
|
||||
for key, value := range waterfill(total, linkWeights, demands) {
|
||||
rates[key] += value
|
||||
}
|
||||
return rates
|
||||
|
||||
@@ -101,3 +101,28 @@ func TestSmallInventoryDoesNotReserveAnUnlimitedStream(t *testing.T) {
|
||||
t.Fatal("small metadata held camera bandwidth", rates)
|
||||
}
|
||||
}
|
||||
|
||||
// A 42 KiB compressed spatial profile formerly took >10 s on an otherwise
|
||||
// healthy 35 Mbit/s path because inventory was pinned to its 32 kbit/s floor.
|
||||
func TestInventoryUsesResidualCapacityWithoutTakingCameraPriority(t *testing.T) {
|
||||
b, now := testBudget(t)
|
||||
b.effective = 35000
|
||||
b.SetControl(false)
|
||||
b.allocateRole("11111111111111111111111111111111", "video", true, 5000000, true)
|
||||
b.RequestDemand("inventory", 42*1024)
|
||||
b.Try("inventory", 1000)
|
||||
rates := b.classRates(*now)
|
||||
if rates["inventory"] < 340000 || rates["video"] != 5000000 {
|
||||
t.Fatal("finite signalling stuck at floor on healthy link", rates)
|
||||
}
|
||||
b.effective = 1000
|
||||
rates = b.classRates(*now)
|
||||
if rates["inventory"] != 32000 || rates["video"] != b.optional(*now)*1000-32000 {
|
||||
t.Fatal("signalling borrowed selected camera capacity", rates)
|
||||
}
|
||||
b.SetControl(true)
|
||||
b.ObserveCommandFrame(800*time.Millisecond, 800*time.Millisecond)
|
||||
if b.classRates(*now)["inventory"] != 0 {
|
||||
t.Fatal("signalling escaped command pressure")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user