Skip to content

Commit

Permalink
Adjust network back pressure
Browse files Browse the repository at this point in the history
  • Loading branch information
enfein committed Dec 17, 2024
1 parent 71f475f commit 2874e25
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/protocol/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,22 @@ func (s *Session) writeChunk(b []byte) (n int, err error) {
seqBeforeWrite, _ := s.sendQueue.MinSeq()

// Determine number of fragments to write.
// Return if there is no enough space in send queue.
nFragment := 1
fragmentSize := MaxFragmentSize(s.mtu, s.conn.TransportProtocol())
if len(b) > fragmentSize {
nFragment = (len(b)-1)/fragmentSize + 1
}
if s.sendQueue.Remaining() <= nFragment { // leave one slot in case it is needed
time.Sleep(tickInterval) // add back pressure
return 0, nil
for s.sendQueue.Remaining() < nFragment {
select {
case <-s.closedChan:
return 0, io.EOF
case <-s.outputErr:
return 0, io.ErrClosedPipe
case <-timeC:
return 0, stderror.ErrTimeout
default:
}
time.Sleep(tickInterval) // add back pressure if queue is full
}

s.oLock.Lock()
Expand Down

0 comments on commit 2874e25

Please sign in to comment.