github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/ingester/locker_test.go (about) 1 package ingester 2 3 import ( 4 "sync" 5 "testing" 6 7 "github.com/prometheus/common/model" 8 ) 9 10 func BenchmarkFingerprintLockerParallel(b *testing.B) { 11 numGoroutines := 10 12 numFingerprints := 10 13 numLockOps := b.N 14 locker := newFingerprintLocker(100) 15 16 wg := sync.WaitGroup{} 17 b.ResetTimer() 18 for i := 0; i < numGoroutines; i++ { 19 wg.Add(1) 20 go func(i int) { 21 for j := 0; j < numLockOps; j++ { 22 fp1 := model.Fingerprint(j % numFingerprints) 23 fp2 := model.Fingerprint(j%numFingerprints + numFingerprints) 24 locker.Lock(fp1) 25 locker.Lock(fp2) 26 locker.Unlock(fp2) 27 locker.Unlock(fp1) 28 } 29 wg.Done() 30 }(i) 31 } 32 wg.Wait() 33 } 34 35 func BenchmarkFingerprintLockerSerial(b *testing.B) { 36 numFingerprints := 10 37 locker := newFingerprintLocker(100) 38 39 b.ResetTimer() 40 for i := 0; i < b.N; i++ { 41 fp := model.Fingerprint(i % numFingerprints) 42 locker.Lock(fp) 43 locker.Unlock(fp) 44 } 45 }