Skip to content

Commit

Permalink
Fix: transition to math/rand/v2 for Improved Performance and Code C…
Browse files Browse the repository at this point in the history
…larity (#15438)

Signed-off-by: Aoang <aoang@x2oe.com>
  • Loading branch information
Aoang authored Mar 12, 2024
1 parent d5bd597 commit 85aeb34
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
3 changes: 0 additions & 3 deletions go/hack/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,3 @@ func Atof64(s string) (float64, int, error)

//go:linkname Atof32 strconv.atof32
func Atof32(s string) (float32, int, error)

//go:linkname FastRand runtime.fastrand
func FastRand() uint32
5 changes: 2 additions & 3 deletions go/pools/smartconnpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package smartconnpool

import (
"context"
"math/rand/v2"
"slices"
"sync"
"sync/atomic"
"time"

"vitess.io/vitess/go/hack"
"vitess.io/vitess/go/vt/log"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/servenv"
Expand Down Expand Up @@ -373,8 +373,7 @@ func (pool *ConnPool[D]) extendedMaxLifetime() time.Duration {
if maxLifetime == 0 {
return 0
}
extended := hack.FastRand() % uint32(maxLifetime)
return time.Duration(maxLifetime) + time.Duration(extended)
return time.Duration(maxLifetime) + time.Duration(rand.Uint32N(uint32(maxLifetime)))
}

func (pool *ConnPool[C]) connReopen(ctx context.Context, dbconn *Pooled[C], now time.Time) error {
Expand Down

0 comments on commit 85aeb34

Please sign in to comment.