lua-resty-redis icon indicating copy to clipboard operation
lua-resty-redis copied to clipboard

Skipping responses

Open subnetmarco opened this issue 11 years ago • 3 comments
trafficstars

I've came across a very specific scenario where due to a high volume of write requests, calling tcpsock:receive after every operation was too expensive. In this scenario, counters on Redis were incremented and decremented in a write-and-forget fashion.

For this reason I've introduced a new skip_responses(bool_skip) function to be able to optionally instruct the client to discard every response by skipping the tcpsock:receive function call.

I've submitted this pull request just in case somebody else needs it.

subnetmarco avatar Dec 05 '13 07:12 subnetmarco

@thefosk Your patch is wrong. You cannot leave Redis replies in the system read buffer because that way the current Redis connection will be blocked by accumulated unread data. The right approach for discarding Redis replies is to read the reply and throw it away immediately. And it's better done on the ngx_lua cosocket level.

agentzh avatar Dec 05 '13 21:12 agentzh

I've updated the code to sock:receive(0) when the client is instructed to skip the responses.

subnetmarco avatar Dec 06 '13 04:12 subnetmarco

@thefosk It's still wrong because sock:receive(0) does not consume any data in the system socket receive buffers, which could still prevent the remote redis server from sending more replies, leading to TCP connections with blocked traffic on the receiving direction.

agentzh avatar Dec 06 '13 04:12 agentzh