mirror of
https://github.com/soypat/lneto.git
synced 2026-08-15 12:23:44 +00:00
Stack backoff rework (#83)
* huge Stack backoff rework * lneto bump: huge Stack backoff rework
This commit is contained in:
+22
-4
@@ -4,13 +4,31 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ConnRWBackoff implements exponential backoff suitable for TCP connection
|
||||
// BackoffConnRW implements exponential backoff suitable for TCP connection
|
||||
// read/write polling. It starts at 1us and caps at 5ms, doubling on each consecutive backoff.
|
||||
func ConnRWBackoff(consecutiveBackoffs int) {
|
||||
func BackoffConnRW(consecutiveBackoffs uint) {
|
||||
const (
|
||||
minWait = uint32(time.Microsecond) >> 1
|
||||
minWait = uint32(time.Microsecond)
|
||||
maxWait = 5 * uint32(time.Millisecond)
|
||||
maxShift = 23
|
||||
maxShift = 22
|
||||
_overflowCheck = minWait << maxShift
|
||||
)
|
||||
wait := minWait << min(consecutiveBackoffs, maxShift)
|
||||
if wait > maxWait {
|
||||
wait = maxWait
|
||||
}
|
||||
time.Sleep(time.Duration(wait))
|
||||
}
|
||||
|
||||
// BackoffStackProto implements exponential backoff suitable for stack-level
|
||||
// protocol processing polling. It starts at 1us and caps at 100ms, doubling on each consecutive backoff.
|
||||
func BackoffStackProto(consecutiveBackoffs uint) {
|
||||
const (
|
||||
minWait = uint32(time.Microsecond)
|
||||
maxWait = 100 * uint32(time.Millisecond)
|
||||
|
||||
// Statically calculated numbers below.
|
||||
maxShift = 22
|
||||
_overflowCheck = minWait << maxShift
|
||||
)
|
||||
wait := minWait << min(consecutiveBackoffs, maxShift)
|
||||
|
||||
@@ -271,20 +271,6 @@ func (r *Ring) addOff(a, b int) int {
|
||||
return result
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (r *Ring) string() string {
|
||||
var b bytes.Buffer
|
||||
r2 := *r
|
||||
|
||||
Reference in New Issue
Block a user