perf(bondserver): убрать аллокацию snapshotLanes на каждый retry записи
This commit is contained in:
1 parent
2b24471553
commit
9459e94066
1 file changed
+17
-7
@@ -355,8 +355,18 @@ func (c *serverConn) copyBackendToBond(backendConn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *serverConn) writeToNextLane(typ byte, seq uint64, data []byte, laneIdx *uint64) error {
|
func (c *serverConn) writeToNextLane(typ byte, seq uint64, data []byte, laneIdx *uint64) error {
|
||||||
for {
|
|
||||||
lanes := c.snapshotLanes()
|
lanes := c.snapshotLanes()
|
||||||
|
for {
|
||||||
|
if len(lanes) == 0 {
|
||||||
|
select {
|
||||||
|
case <-c.ctx.Done():
|
||||||
|
return c.ctx.Err()
|
||||||
|
case <-time.After(10 * time.Millisecond):
|
||||||
|
}
|
||||||
|
lanes = c.snapshotLanes()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
written := false
|
||||||
for range lanes {
|
for range lanes {
|
||||||
lane := lanes[*laneIdx%uint64(len(lanes))]
|
lane := lanes[*laneIdx%uint64(len(lanes))]
|
||||||
*laneIdx++
|
*laneIdx++
|
||||||
@@ -364,7 +374,8 @@ func (c *serverConn) writeToNextLane(typ byte, seq uint64, data []byte, laneIdx
|
|||||||
err := bondframe.WriteFrame(lane.stream, typ, seq, data)
|
err := bondframe.WriteFrame(lane.stream, typ, seq, data)
|
||||||
lane.mu.Unlock()
|
lane.mu.Unlock()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
written = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
left := c.removeLane(lane)
|
left := c.removeLane(lane)
|
||||||
c.deps.log().Errorf("[bond %d] lane %d write error: %v (lanes=%d)", c.id, lane.index, err, left)
|
c.deps.log().Errorf("[bond %d] lane %d write error: %v (lanes=%d)", c.id, lane.index, err, left)
|
||||||
@@ -372,10 +383,9 @@ func (c *serverConn) writeToNextLane(typ byte, seq uint64, data []byte, laneIdx
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
select {
|
if written {
|
||||||
case <-c.ctx.Done():
|
return nil
|
||||||
return c.ctx.Err()
|
}
|
||||||
case <-time.After(10 * time.Millisecond):
|
lanes = c.snapshotLanes()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user