2
0
mirror of https://github.com/hibiken/asynq.git synced 2026-02-01 06:44:22 +00:00

[performance] Use BRPOPLPUSH if one queue is used

This commit is contained in:
Ken Hibino
2020-01-14 06:29:05 -08:00
parent f0251be5d2
commit 5a6f737589
2 changed files with 28 additions and 6 deletions

View File

@@ -124,8 +124,12 @@ func (p *processor) exec() {
msg, err := p.rdb.Dequeue(qnames...)
if err == rdb.ErrNoProcessableTask {
// queues are empty, this is a normal behavior.
// sleep to avoid slamming redis and let scheduler move tasks into queues.
time.Sleep(time.Second)
if len(p.queueConfig) > 1 {
// sleep to avoid slamming redis and let scheduler move tasks into queues.
// Note: With multiple queues, we are not using blocking pop operation and
// polling queues instead. This adds significant load to redis.
time.Sleep(time.Second)
}
return
}
if err != nil {
@@ -221,6 +225,13 @@ func (p *processor) kill(msg *base.TaskMessage, e error) {
// If strict-priority is false, then the order of queue names are roughly based on
// the priority level but randomized in order to avoid starving low priority queues.
func (p *processor) queues() []string {
// skip the overhead of generating a list of queue names
// if we are processing one queue.
if len(p.queueConfig) == 1 {
for qname := range p.queueConfig {
return []string{qname}
}
}
if p.orderedQueues != nil {
return p.orderedQueues
}