-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from nspcc-dev/rtt
context: add simple rtt estimator
- Loading branch information
Showing
5 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dbft | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
const rttLength = 7 * 10 // 10 rounds with 7 nodes | ||
|
||
type rtt struct { | ||
times [rttLength]time.Duration | ||
idx int | ||
avg time.Duration | ||
} | ||
|
||
func (r *rtt) addTime(t time.Duration) { | ||
var old = r.times[r.idx] | ||
|
||
if old != 0 { | ||
t = min(t, 2*old) // Too long delays should be normalized, we don't want to overshoot. | ||
} | ||
|
||
r.avg = r.avg + (t-old)/time.Duration(len(r.times)) | ||
r.avg = max(0, r.avg) // Can't be less than zero. | ||
r.times[r.idx] = t | ||
r.idx = (r.idx + 1) % len(r.times) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters