Skip to content

Commit

Permalink
Set a floor of 1.5s for threshold to switch Os (livepeer#2837)
Browse files Browse the repository at this point in the history
* Set a floor of 1.5s for threshold to switch Os

* Update tests to account for new minimum timeout

* Update changelog
  • Loading branch information
thomshutt authored and eliteprox committed Feb 21, 2024
1 parent 009fcf1 commit d6f3e17
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### General

#### Broadcaster
- \#2837 Set a floor of 1.5s for accepted Orchestrator response times, regardless of segment length (@thomshutt)

#### Orchestrator

Expand Down
6 changes: 6 additions & 0 deletions server/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func selectSession(ctx context.Context, sessions []*BroadcastSession, exclude []
// durMult can be tuned by the caller to tighten/relax the maximum in flight time for the oldest segment
maxTimeInFlight := time.Duration(durMult) * oldestSegInFlight.segDur

// We're more lenient for segments <= 1s in length, since we've found the overheads to make this quite an aggressive target
// to consistently meet, so instead set a floor of 1.5s
if maxTimeInFlight <= 1*time.Second {
maxTimeInFlight = 1500 * time.Millisecond
}

if timeInFlight < maxTimeInFlight {
clog.PublicInfof(ctx,
"Selected orchestrator reason=%v",
Expand Down
4 changes: 2 additions & 2 deletions server/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,15 @@ func TestSelectSession_MultipleInFlight2(t *testing.T) {
}

func TestSelectSession_NoSegsInFlight(t *testing.T) {
assert := assert.New(t)
assert := require.New(t)
ctx := context.Background()

sess := &BroadcastSession{}
sessList := []*BroadcastSession{sess}

// Session has segs in flight
sess.SegsInFlight = []SegFlightMetadata{
{startTime: time.Now().Add(time.Duration(-1) * time.Second), segDur: 1 * time.Second},
{startTime: time.Now().Add(time.Duration(-2) * time.Second), segDur: 1 * time.Second},
}
s := selectSession(ctx, sessList, nil, 1)
assert.Nil(s)
Expand Down
10 changes: 5 additions & 5 deletions server/sessionpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func TestSelectSession_MultipleInFlight(t *testing.T) {
assert.Equal(expectedSess0.OrchestratorInfo, sess0.OrchestratorInfo)
assert.Len(pool.lastSess[0].SegsInFlight, 1)

time.Sleep(110 * time.Millisecond)
time.Sleep(1600 * time.Millisecond)

sess1 = sendSegStub()
assert.Equal(pool.lastSess[0], sess1)
Expand All @@ -396,7 +396,7 @@ func TestSelectSession_MultipleInFlight(t *testing.T) {
assert.Equal(expectedSess1.OrchestratorInfo, sess0.OrchestratorInfo)
assert.Len(pool.lastSess[0].SegsInFlight, 1)

time.Sleep(110 * time.Millisecond)
time.Sleep(1000 * time.Millisecond)

sess1 = sendSegStub()
assert.Equal(pool.lastSess[0], sess1)
Expand All @@ -417,7 +417,7 @@ func TestSelectSession_MultipleInFlight(t *testing.T) {
assert.Equal(expectedSess1.OrchestratorInfo, sess0.OrchestratorInfo)
assert.Len(pool.lastSess[0].SegsInFlight, 1)

time.Sleep(210 * time.Millisecond)
time.Sleep(1600 * time.Millisecond)

sess1 = sendSegStub()
assert.Nil(sess1)
Expand Down Expand Up @@ -504,14 +504,14 @@ func TestSelectSessionMoreThanOne(t *testing.T) {
assert.Len(pool.sessList(), 0)
assert.Len(sessions[0].SegsInFlight, 1)
assert.Len(pool.lastSess[0].SegsInFlight, 1)
time.Sleep(100 * time.Millisecond)
time.Sleep(800 * time.Millisecond)
sessions2 := sendSegStub(3)
assert.Len(sessions2, 3)
assert.Len(pool.sessList(), 0)
assert.Len(sessions2[0].SegsInFlight, 2)
assert.Len(pool.lastSess[1].SegsInFlight, 2)
assert.Equal(sessions, sessions2)
time.Sleep(100 * time.Millisecond)
time.Sleep(800 * time.Millisecond)
sessions3 := sendSegStub(3)
assert.Len(sessions3, 0)
assert.Len(sessions2[0].SegsInFlight, 2)
Expand Down

0 comments on commit d6f3e17

Please sign in to comment.