Welcome to mirror list, hosted at ThFree Co, Russian Federation.

util.go « lightstep-tracer-go « lightstep « github.com « vendor - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc27f9e3ab8e3d0e2a2094dbe23670b6cb6ce93e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package lightstep

import (
	"runtime"
	"time"

	"github.com/lightstep/lightstep-tracer-go/lightstep/rand"
)

var (
	// create a random pool with size equal to 16 generators or number of CPU Cores which ever is higher to spread
	// random int call loads across multiple go routines. This number is obtained via local benchmarking
	// where any number more than 16 reaches a point of diminishing return given the test scenario.
	randompool = rand.NewPool(time.Now().UnixNano(), uint64(max(16, runtime.NumCPU())))
)

// max returns the larger value among a and b
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func genSeededGUID() uint64 {
	return uint64(randompool.Pick().Int63())
}

func genSeededGUID2() (uint64, uint64) {
	n1, n2 := randompool.Pick().TwoInt63()
	return uint64(n1), uint64(n2)
}