control of shaper heap size

This commit is contained in:
xtaci
2023-02-12 19:51:18 +08:00
parent d5ca637a0e
commit a54d6cb361
2 changed files with 18 additions and 3 deletions
+16 -1
View File
@@ -13,6 +13,7 @@ import (
const (
defaultAcceptBacklog = 1024
maxShaperSize = 1024
)
var (
@@ -420,8 +421,10 @@ func (s *Session) shaperLoop() {
var reqs shaperHeap
var next writeRequest
var chWrite chan writeRequest
var chShaper chan writeRequest
for {
// chWrite is not available until it has packet to send
if len(reqs) > 0 {
chWrite = s.writes
next = heap.Pop(&reqs).(writeRequest)
@@ -429,10 +432,22 @@ func (s *Session) shaperLoop() {
chWrite = nil
}
// control heap size, chShaper is not available until packets are less than maximum allowed
if len(reqs) >= maxShaperSize {
chShaper = nil
} else {
chShaper = s.shaper
}
// assertion on non nil
if chShaper == nil && chWrite == nil {
panic("both channel are nil")
}
select {
case <-s.die:
return
case r := <-s.shaper:
case r := <-chShaper:
if chWrite != nil { // next is valid, reshape
heap.Push(&reqs, next)
}
+2 -2
View File
@@ -325,7 +325,7 @@ func (s *Stream) Write(b []byte) (n int, err error) {
}
frame.data = bts[:sz]
bts = bts[sz:]
n, err := s.sess.writeFrameInternal(frame, deadline, s.numWritten)
n, err := s.sess.writeFrameInternal(frame, deadline, 0)
s.numWritten++
sent += n
if err != nil {
@@ -393,7 +393,7 @@ func (s *Stream) writeV2(b []byte) (n int, err error) {
}
frame.data = bts[:sz]
bts = bts[sz:]
n, err := s.sess.writeFrameInternal(frame, deadline, atomic.LoadUint32(&s.numWritten))
n, err := s.sess.writeFrameInternal(frame, deadline, 0)
atomic.AddUint32(&s.numWritten, uint32(sz))
sent += n
if err != nil {