MCPcopy Create free account
hub / github.com/cortexproject/cortex / startGoroutinesDoingUpdates

Function startGoroutinesDoingUpdates

pkg/util/users/active_user_test.go:132–164  ·  view source on GitHub ↗
(b *testing.B, count int, as *ActiveUsers)

Source from the content-addressed store, hash-verified

130}
131
132func startGoroutinesDoingUpdates(b *testing.B, count int, as *ActiveUsers) {
133 done := sync.WaitGroup{}
134 stop := atomic.NewBool(false)
135
136 started := sync.WaitGroup{}
137 for j := range count {
138 done.Add(1)
139 started.Add(1)
140 userID := fmt.Sprintf("user-%d", j)
141 go func() {
142 defer done.Done()
143 started.Done()
144
145 ts := int64(0)
146 for !stop.Load() {
147 ts++
148 as.UpdateUserTimestamp(userID, ts)
149
150 // Give other goroutines a chance too.
151 if ts%1000 == 0 {
152 runtime.Gosched()
153 }
154 }
155 }()
156 }
157 started.Wait()
158
159 b.Cleanup(func() {
160 // Ask goroutines to stop, and then wait until they do.
161 stop.Store(true)
162 done.Wait()
163 })
164}

Calls 6

DoneMethod · 0.80
LoadMethod · 0.80
StoreMethod · 0.65
AddMethod · 0.45
UpdateUserTimestampMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected