-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to handle with slow consumer? #204
Comments
Best practice is to use Message.Touch() periodically, perhaps roughly every 10 seconds, if the message is still being processed (successfully so far). The other thing you'll probably want to do is set the consumer Config setting "msg_timeout" which will tell the server how long to wait for a message sent to this consumer to finish before retrying it. It's not a good idea to set this too high because it makes failure/crash detection take a lot longer. By default this value is 60 seconds, and by default the server accepts a maximum of 15 minutes for this value. nsq is optimized more for a very high rate and volume of relatively quick-to-process messages, so it might not be perfect for your use case. |
@liudanking We use NSQ for long-running messages (10+ minutes) and we use If you expect to go over the 15m value mentioned by @ploxiln you'll also need to set |
I'm guessing that func (s stub) HandleMessage(msg *nsq.Message) error {
return consumerHandler(msg)
} Nothing about this problem is related to the message timing out, as the first thing that happens inside The likely cause of the problem here is that Line 519 in a53d495
If the delegate does not return, readLoop does not process heartbeats.
The better solution here would be to send the message to a concurrent goroutine that does the processing. If this is done, it's important to not have every message start a goroutine and eat memory (unless there are not many messages at a time). Lastly, the concurrent goroutine cannot block the handler, otherwise you will have the same issue that currently exists. |
Good catch, I completely missed that the body of the handler was calling Making it concurrent effectively creates an internal queue, which would still need to be bounded, and thus would ultimately block the read loop anyway. It might offer some optimization because you would be reading while processing though, shrug. |
@twmb Are you sure? Maybe I'm missing something Lines 636 to 641 in a53d495
Edit: I got you, if sending to the Even if |
@liudanking Try removing |
I have a very slow consumer with nsq topic:
After a while, I got some error with nsq:
What is the best practice with slow consumer handler?
The text was updated successfully, but these errors were encountered: