Skip to content
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

consumer: concurrent handlers not working as expected #256

Closed
pajadah opened this issue Apr 3, 2019 · 5 comments
Closed

consumer: concurrent handlers not working as expected #256

pajadah opened this issue Apr 3, 2019 · 5 comments
Labels

Comments

@pajadah
Copy link

pajadah commented Apr 3, 2019

Hi, I have a problem on my project that are using NSQ conccurent handler.
So I am using nsq.AddConcurrentHandlers(&MyHandler{}, 16). My project runs on 2 servers, so it means it will spawn 16 concurrent handlers from each server, with total of 32 handlers.
When one the topic depth is getting high (around 3 million), I check in nsqadmin that only 4 handlers out of 32 handlers are processing the messages. I wonder if there's any possible reason for this? since if I can get all that 32 handlers to process the messages, then there's won't be any high depth at all.

Here's my client code:

config := nsq.NewConfig()
config.DefaultRequeueDelay = 0
config.MaxAttempts = 0
config.MaxInFlight = 5000

q, err := nsq.NewConsumer("this_is_topic", "this_is_channel", config)
if err != nil {
    log.Println(err.Error())
    return
}

h := &MyHandler{
    q: q
}

q.AddConcurrentHandlers(h, 16)
q.SetLogger(log.New(os.Stderr, "nsq:", log.Ltime), nsq.LogLevelError)

err = p.connectToLookupds(q)
if err != nil {
    log.Println(err.Error())
}
@pajadah pajadah changed the title ConccurentHandlers not working as expected ConcurrentHandlers not working as expected Apr 3, 2019
@ploxiln
Copy link
Member

ploxiln commented Apr 3, 2019

Can you show more of your handler function? How long might it take to process a message?

MaxInFlight=5000 looks too high, you want it to be between 16 and maybe 100 depending on how many nsqd you have and how long the handler typically takes to process a message.

Setting MaxAttempts and DefaultRequeueDelay to 0 are not good ideas - I think you want MaxAttempts to be 1, and Default RequeueDelay should be positive, but you can leave it at the default and requeue with backoff=false so the consumer does not backoff when the message fails.

@ploxiln
Copy link
Member

ploxiln commented Apr 3, 2019

(can you also share stats from nsqd? and how many nsqd have this topic?)

@mreiferson mreiferson changed the title ConcurrentHandlers not working as expected consumer: concurrent handlers not working as expected Apr 7, 2019
@ploxiln
Copy link
Member

ploxiln commented Sep 25, 2019

What do you set MaxInFlight to? This is the other key variable to adjust for concurrent handling.

@ploxiln ploxiln closed this as completed Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@ploxiln @pajadah and others