Pacer in down stream path. (#1835)

* Pacer interface to send packets

* notify outside lock

* use select

* use pass through pacer

* add error to OnSent

* Remove log which could get noisy

* Starting TWCC work (#1727)

* add packet time

* WIP commit

* WIP commit

* WIP commit

* minor comments

* Some measurements (#1736)

* WIP commit

* some notes

* WIP commit

* variable name change and do not post to closed channel

* unlock

* clean up

* comment

* Hooking up some more bits for TWCC (#1752)

* wake under lock

* Pacer in down stream path.

Splitting out only the pacer from a feature branch to
introduce the concept of pacer.

Currently, there should be no difference in functionality
as a pass through pacer is used.

Another implementation exists which is just put it in a queue and send
it from one goroutine.

A potential implementation to try would be data paced by bandwidth
estimate. That could include priority queues and such.

But, the main goal here is to introduce notion of pacer in the down
stream path and prepare for more congestion control possibilities down
the line.

* Don't need peak detector

* remove throttling of write IO errors
This commit is contained in:
Raja Subramanian
2023-06-28 13:22:44 +05:30
committed by GitHub
parent 2b0a470474
commit eaf70d5549
12 changed files with 537 additions and 225 deletions
+80
View File
@@ -0,0 +1,80 @@
package pacer
import (
"sync"
"github.com/gammazero/deque"
"github.com/livekit/protocol/logger"
)
type NoQueue struct {
*Base
logger logger.Logger
lock sync.RWMutex
packets deque.Deque[Packet]
wake chan struct{}
isStopped bool
}
func NewNoQueue(logger logger.Logger) *NoQueue {
n := &NoQueue{
Base: NewBase(logger),
logger: logger,
wake: make(chan struct{}, 1),
}
n.packets.SetMinCapacity(9)
go n.sendWorker()
return n
}
func (n *NoQueue) Stop() {
n.lock.Lock()
if n.isStopped {
n.lock.Unlock()
return
}
close(n.wake)
n.isStopped = true
n.lock.Unlock()
}
func (n *NoQueue) Enqueue(p Packet) {
n.lock.Lock()
defer n.lock.Unlock()
n.packets.PushBack(p)
if n.packets.Len() == 1 && !n.isStopped {
select {
case n.wake <- struct{}{}:
default:
}
}
}
func (n *NoQueue) sendWorker() {
for {
<-n.wake
for {
n.lock.Lock()
if n.isStopped {
n.lock.Unlock()
return
}
if n.packets.Len() == 0 {
n.lock.Unlock()
break
}
p := n.packets.PopFront()
n.lock.Unlock()
n.Base.SendPacket(&p)
}
}
}
// ------------------------------------------------