chore: fix typo (#4246)

This commit is contained in:
Kevin Wan 2024-07-14 10:52:47 +08:00 committed by GitHub
parent 775b105ab2
commit 9f8455ddb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 23 deletions

View File

@ -135,5 +135,5 @@ func verify(t *testing.T, fn func() bool) {
count++
}
}
assert.True(t, count >= 80, fmt.Sprintf("should be greater than 80, actual %d", count))
assert.True(t, count >= 75, fmt.Sprintf("should be greater than 75, actual %d", count))
}

View File

@ -84,10 +84,10 @@ func Range(source <-chan any) Stream {
}
}
// AllMach returns whether all elements of this stream match the provided predicate.
// AllMatch returns whether all elements of this stream match the provided predicate.
// May not evaluate the predicate on all elements if not necessary for determining the result.
// If the stream is empty then true is returned and the predicate is not evaluated.
func (s Stream) AllMach(predicate func(item any) bool) bool {
func (s Stream) AllMatch(predicate func(item any) bool) bool {
for item := range s.source {
if !predicate(item) {
// make sure the former goroutine not block, and current func returns fast.
@ -99,10 +99,10 @@ func (s Stream) AllMach(predicate func(item any) bool) bool {
return true
}
// AnyMach returns whether any elements of this stream match the provided predicate.
// AnyMatch returns whether any elements of this stream match the provided predicate.
// May not evaluate the predicate on all elements if not necessary for determining the result.
// If the stream is empty then false is returned and the predicate is not evaluated.
func (s Stream) AnyMach(predicate func(item any) bool) bool {
func (s Stream) AnyMatch(predicate func(item any) bool) bool {
for item := range s.source {
if predicate(item) {
// make sure the former goroutine not block, and current func returns fast.

View File

@ -398,16 +398,16 @@ func TestWalk(t *testing.T) {
func TestStream_AnyMach(t *testing.T) {
runCheckedTest(t, func(t *testing.T) {
assetEqual(t, false, Just(1, 2, 3).AnyMach(func(item any) bool {
assetEqual(t, false, Just(1, 2, 3).AnyMatch(func(item any) bool {
return item.(int) == 4
}))
assetEqual(t, false, Just(1, 2, 3).AnyMach(func(item any) bool {
assetEqual(t, false, Just(1, 2, 3).AnyMatch(func(item any) bool {
return item.(int) == 0
}))
assetEqual(t, true, Just(1, 2, 3).AnyMach(func(item any) bool {
assetEqual(t, true, Just(1, 2, 3).AnyMatch(func(item any) bool {
return item.(int) == 2
}))
assetEqual(t, true, Just(1, 2, 3).AnyMach(func(item any) bool {
assetEqual(t, true, Just(1, 2, 3).AnyMatch(func(item any) bool {
return item.(int) == 2
}))
})
@ -416,17 +416,17 @@ func TestStream_AnyMach(t *testing.T) {
func TestStream_AllMach(t *testing.T) {
runCheckedTest(t, func(t *testing.T) {
assetEqual(
t, true, Just(1, 2, 3).AllMach(func(item any) bool {
t, true, Just(1, 2, 3).AllMatch(func(item any) bool {
return true
}),
)
assetEqual(
t, false, Just(1, 2, 3).AllMach(func(item any) bool {
t, false, Just(1, 2, 3).AllMatch(func(item any) bool {
return false
}),
)
assetEqual(
t, false, Just(1, 2, 3).AllMach(func(item any) bool {
t, false, Just(1, 2, 3).AllMatch(func(item any) bool {
return item.(int) == 1
}),
)

View File

@ -22,13 +22,20 @@ const (
// Name is the name of p2c balancer.
Name = "p2c_ewma"
decayTime = int64(time.Second * 10) // default value from finagle
forcePick = int64(time.Second) // If a node is not selected for a period of time, it is forcibly selected.
initSuccess = 1000 // Initial success count
throttleSuccess = initSuccess / 2 // Success count to trigger throttling
penalty = int64(math.MaxInt32) // Penalty value for load calculation
pickTimes = 3 // Number of pick attempts
logInterval = time.Minute // Log interval for statistics
// default value from finagle
decayTime = int64(time.Second * 10)
// if a node is not selected for a period of time, it is forcibly selected.
forcePick = int64(time.Second)
// initial success count
initSuccess = 1000
// success count to trigger throttling
throttleSuccess = initSuccess / 2
// penalty value for load calculation
penalty = int64(math.MaxInt32)
// number of pick attempts
pickTimes = 3
// log interval for statistics
logInterval = time.Minute
)
var emptyPickResult balancer.PickResult
@ -45,7 +52,7 @@ func (b *p2cPickerBuilder) Build(info base.PickerBuildInfo) balancer.Picker {
return base.NewErrPicker(balancer.ErrNoSubConnAvailable)
}
var conns []*subConn
conns := make([]*subConn, 0, len(readySCs))
for conn, connInfo := range readySCs {
conns = append(conns, &subConn{
addr: connInfo.Address,
@ -122,8 +129,9 @@ func (p *p2cPicker) buildDoneFunc(c *subConn) func(info balancer.DoneInfo) {
td = 0
}
// As the td/decayTime value increases, indicating an increase in delay, the value of w (y axis) will decrease, inversely proportional.
// The function curve of y = x^(-x) is as follows.
// As the td/decayTime value increases, indicating an increase in delay,
// the value of w (y-axis) will decrease, inversely proportional.
// The function curve of y = x^(-x) is as follows:
// https://github.com/zeromicro/zero-doc/blob/main/doc/images/y_e_x.png?raw=true
w := math.Exp(float64(-td) / float64(decayTime))
lag := int64(now) - start
@ -191,7 +199,8 @@ type subConn struct {
// The request latency measured by the weighted moving average algorithm.
lag uint64
// The value represents the number of requests that are either pending or just starting at the current node, and it is obtained through atomic addition.
// The value represents the number of requests that are either pending or just
// starting at the current node, and it is obtained through atomic addition.
inflight int64
success uint64
requests int64