Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources: BenchmarkResourcesMatch cannot run with -count=10 and crashes with an index out of range error #8981

Closed
odeke-em opened this issue Sep 18, 2021 · 2 comments · Fixed by #8982
Labels

Comments

@odeke-em
Copy link
Contributor

Noticed while testing out continuous benchmarking for Go on Hugo using our product "Bencher" if we look at https://dashboard.github.orijtech.com/benchmark/83306b009ae244afa735fa6cb31defda
Screen Shot 2021-09-18 at 1 55 30 PM

and this crash is trivially reproducible by running

go test -run=^$ -bench=. -count=10 -benchmem

reproducible on Linux and Darwin.

Continuous benchmarking with bencher

Shameless plug We at Orijtech Inc are on a mission to bring high performance engineering to the doorstep of every programmer. Our product is currently focused on benchmarking for the Go programming language and we take away all the tedious error prone ergonomics of benchmarking, running your benchmarks on every push, doing the heavy lifting for you. The product is non-invasive and can be added as a Github app, available at the marketplace at https://github.com/marketplace/gobencher

@odeke-em
Copy link
Contributor Author

I believe the reason for this failure is because the RNG is NOT SAFE for concurrent use yet the code uses pb.Next() which spins up goroutines to process concurrently, as documented https://pkg.go.dev/math/rand#NewSource
Screen Shot 2021-09-18 at 10 46 34 PM

per

rnd := rand.New(rand.NewSource(time.Now().Unix()))
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
resources.Match(prefixes[rnd.Intn(len(prefixes))])
}
})

Remedy

The math/rand docs say that the default source is SAFE for concurrent usage so we could switch to that
Screen Shot 2021-09-18 at 10 52 34 PM

odeke-em added a commit to orijtech/hugo that referenced this issue Sep 19, 2021
The source from NewSource is documented not to be safe for
concurrency, and instead use the eefault source which is documented
as safe.

Fixes gohugoio#8981
@bep bep closed this as completed in #8982 Sep 19, 2021
bep pushed a commit that referenced this issue Sep 19, 2021
The source from NewSource is documented not to be safe for
concurrency, and instead use the eefault source which is documented
as safe.

Fixes #8981
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant