mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-19 05:17:30 +08:00
Avoid creating script struct on every rdb method invocation
This commit is contained in:
@@ -12,8 +12,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Simple E2E Benchmark testing with no scheduled tasks and
|
||||
// no retries.
|
||||
// Simple E2E Benchmark testing with no scheduled tasks and retries.
|
||||
func BenchmarkEndToEndSimple(b *testing.B) {
|
||||
const count = 100000
|
||||
for n := 0; n < b.N; n++ {
|
||||
@@ -101,3 +100,58 @@ func BenchmarkEndToEnd(b *testing.B) {
|
||||
b.StartTimer() // end teardown
|
||||
}
|
||||
}
|
||||
|
||||
// Simple E2E Benchmark testing with no scheduled tasks and retries with multiple queues.
|
||||
func BenchmarkEndToEndMultipleQueues(b *testing.B) {
|
||||
// number of tasks to create for each queue
|
||||
const (
|
||||
highCount = 20000
|
||||
defaultCount = 20000
|
||||
lowCount = 20000
|
||||
)
|
||||
for n := 0; n < b.N; n++ {
|
||||
b.StopTimer() // begin setup
|
||||
setup(b)
|
||||
redis := &RedisClientOpt{
|
||||
Addr: redisAddr,
|
||||
DB: redisDB,
|
||||
}
|
||||
client := NewClient(redis)
|
||||
bg := NewBackground(redis, &Config{
|
||||
Concurrency: 10,
|
||||
Queues: map[string]uint{
|
||||
"high": 6,
|
||||
"default": 3,
|
||||
"low": 1,
|
||||
},
|
||||
})
|
||||
// Create a bunch of tasks
|
||||
for i := 0; i < highCount; i++ {
|
||||
t := NewTask(fmt.Sprintf("task%d", i), map[string]interface{}{"data": i})
|
||||
client.Schedule(t, time.Now(), Queue("high"))
|
||||
}
|
||||
for i := 0; i < defaultCount; i++ {
|
||||
t := NewTask(fmt.Sprintf("task%d", i), map[string]interface{}{"data": i})
|
||||
client.Schedule(t, time.Now())
|
||||
}
|
||||
for i := 0; i < lowCount; i++ {
|
||||
t := NewTask(fmt.Sprintf("task%d", i), map[string]interface{}{"data": i})
|
||||
client.Schedule(t, time.Now(), Queue("low"))
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(highCount + defaultCount + lowCount)
|
||||
handler := func(t *Task) error {
|
||||
wg.Done()
|
||||
return nil
|
||||
}
|
||||
b.StartTimer() // end setup
|
||||
|
||||
bg.start(HandlerFunc(handler))
|
||||
wg.Wait()
|
||||
|
||||
b.StopTimer() // begin teardown
|
||||
bg.stop()
|
||||
b.StartTimer() // end teardown
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user