-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Since drwmutex is mainly to improve the performance of read-most workload, use a fast hash function also can distribute the lock evenly, which may help to reduce lock contention.
Benchmark shows cost of runtime.fasthashn is very cheap.
func BenchmarkCpuid(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = cpu()
}
}
func BenchmarkFastrand(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fastrandn(CPU_COUNT)
}
}
func cpu() uint64
//go:noescape
//go:linkname fastrandn runtime.fastrandn
func fastrandn(x uint32) uint32goos: darwin
goarch: amd64
BenchmarkCpuid-12 16798030 66.3 ns/op
BenchmarkFastrand-12 504372906 2.39 ns/op
goos: linux
goarch: amd64
BenchmarkCpuid-4 1471983 813 ns/op
BenchmarkFastrand-4 324570566 3.58 ns/op
So is it reasonable to use this rand method to choose read lock on platforms other than linux_amd64?
Metadata
Metadata
Assignees
Labels
No labels