Redis, XREADGROUP stream with block for a year, stupid?

2.4k views Asked by At

Are there any downsides to telling XREADGROUP to block until there is a message rather than the client having to poll?

From:

https://redis.io/commands/xreadgroup

It is not clear that this means:

"On the other side when XREADGROUP blocks, XADD will pay the O(N) time in order to serve the N clients blocked on the stream getting new data."

Can someone shed some light on the blocking mechanisms of streams in Redis?

1

There are 1 answers

6
for_stack On BEST ANSWER

"On the other side when XREADGROUP blocks, XADD will pay the O(N) time in order to serve the N clients blocked on the stream getting new data."

Say, the stream is empty, and N clients call XREADGROUP with different group names. Since the stream is empty, these clients will block until there's new message.

When you call XADD to add a message to the stream, Redis need to send replies to these N blocking clients. That's why XADD will pay O(N) time.

Are there any downsides to telling XREADGROUP to block until there is a message rather than the client having to poll?

If N is very large, i.e. too many clients blocking on the stream, XADD command might block Redis for a while, since it's single-threaded. If N is small, there won't be performance impact.