cool-elephant-31930
11/07/2023, 2:33 AMfatal error: concurrent map writes
while running a multi-threaded benchmark with single instance *growthbook.GrowthBook (in Go SDKs)
func getGBInstance() *growthbook.GrowthBook {
context := growthbook.NewContext().
WithClientKey("keyxxxxx").
WithCacheTTL(10 * time.Second)
gb := growthbook.New(context)
gb.LoadFeatures(&growthbook.FeatureRepoOptions{
AutoRefresh: true,
})
return gb
}
func evaluateFeature(gb *growthbook.GrowthBook, attVal string) bool {
gb.WithAttributes(growthbook.Attributes{"id": attVal})
rs := gb.EvalFeature("enable-dark-mode").On
return rs
}
func BenchmarkEvaluateFeatureParallel(b *testing.B) {
gbInstance = getGBInstance()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var wg sync.WaitGroup
for pb.Next() {
wg.Add(1)
go func() {
attVal := "some-random-value"
_ = evaluateFeature(gbInstance, attVal)
wg.Done()
}()
}
wg.Wait()
})
}
rhythmic-agent-34208
11/07/2023, 2:33 AMfresh-football-47124
cool-elephant-31930
11/07/2023, 7:44 AMgo test -bench=.
command to run benchmark above function.
b.SetParallelism(change_me)
When I set any value for change_me before run benchmark, I also got error fatal error: concurrent map read and map write
brief-honey-45610
11/08/2023, 8:29 PM