为什么lpop操作会增加Redis的CPU使用率?

huangapple go评论72阅读模式
英文:

Why is lpop increasing Redis CPU usage?

问题

我有一个应用程序,在调用lpop时不断循环。使用top命令,我可以看到Redis使用了64%的CPU,而我的应用程序使用了101%。

我正在使用Redis创建一个队列和工作器。我的工作器处于无限循环状态,调用lpop并等待下一个作业到来。

为此,我使用了machinery包。这里有一个相关的问题链接,其中问题被认为是由lpop引起的。然而,由于评论很令人困惑,我不知道LPOPBLPOP之间的区别是什么,除了一个是阻塞的,另一个不是。

英文:

I have an application which keeps looping while calling lpop. Using the top command, I can see that redis is using 64% of CPU, while my application uses 101%.

I'm using redis to create a queue and worker. My worker is in an infinite loop, calling lpop and waiting for the next job to come in.

For this, I'm using the machinery package. There is an issue for this here, where the problem is said to be from lpop. However, since the comments are confusing, I'm at a loss as to what the difference is between LPOP and BLPOP, apart from the fact that one doesn't block and the other does.

答案1

得分: 4

使用最新版本的machinery/v1/brokers/redis.go,将LPOP更改为BLPOP

参考:Redis命令:BLPOP

英文:

> Using timed BLPOP instead of LPOP to avoid massive cpu
> usage

>
> committed 7 days ago
>
> commit 54315dd9fe56a13b8aba2d2a8868fc48dfbb5795
>
> machinery/v1/brokers/redis.go
>
> - itemBytes, err := conn.Do("LPOP", redisBroker.config.DefaultQueue)
> + itemBytes, err := conn.Do("BLPOP", redisBroker.config.DefaultQueue, "1")

Use the latest version of machinery/v1/brokers/redis.go
which changes LPOP to BLPOP.

Reference: Redis commands: BLPOP

huangapple
  • 本文由 发表于 2016年1月31日 19:30:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/35113331.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定