-
Notifications
You must be signed in to change notification settings - Fork 103
/
bench_test.go
56 lines (45 loc) · 938 Bytes
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package taskq_test
import (
"context"
"sync"
"testing"
"github.com/vmihailenco/taskq/v3"
"github.com/vmihailenco/taskq/v3/memqueue"
"github.com/vmihailenco/taskq/v3/redisq"
)
func BenchmarkConsumerMemq(b *testing.B) {
benchmarkConsumer(b, memqueue.NewFactory())
}
func BenchmarkConsumerRedisq(b *testing.B) {
benchmarkConsumer(b, redisq.NewFactory())
}
var (
once sync.Once
q taskq.Queue
task *taskq.Task
wg sync.WaitGroup
)
func benchmarkConsumer(b *testing.B, factory taskq.Factory) {
c := context.Background()
once.Do(func() {
q = factory.RegisterQueue(&taskq.QueueOptions{
Name: "bench",
Redis: redisRing(),
})
task = taskq.RegisterTask(&taskq.TaskOptions{
Name: "bench",
Handler: func() {
wg.Done()
},
})
_ = q.Consumer().Start(c)
})
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < 100; j++ {
wg.Add(1)
_ = q.Add(task.WithArgs(c))
}
wg.Wait()
}
}