英文:
Why is lpop increasing Redis CPU usage?
问题
我有一个应用程序,在调用lpop
时不断循环。使用top
命令,我可以看到Redis使用了64%的CPU,而我的应用程序使用了101%。
我正在使用Redis创建一个队列和工作器。我的工作器处于无限循环状态,调用lpop
并等待下一个作业到来。
为此,我使用了machinery包。这里有一个相关的问题链接,其中问题被认为是由lpop
引起的。然而,由于评论很令人困惑,我不知道LPOP
和BLPOP
之间的区别是什么,除了一个是阻塞的,另一个不是。
英文:
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
。
英文:
> 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论