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

Add option to process messages in parallel #2

Merged
merged 3 commits into from
May 30, 2017
Merged

Conversation

ApsOps
Copy link
Contributor

@ApsOps ApsOps commented May 29, 2017

No description provided.

@ApsOps ApsOps requested a review from ameykpatil May 29, 2017 11:38
cmd/root.go Outdated
@@ -97,18 +100,30 @@ func startGohaqd(cmd *cobra.Command, args []string) {
QueueUrl: q.QueueUrl,
WaitTimeSeconds: aws.Int64(20),
}
sem = make(chan *sqs.Message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ApsOps This channel will have only one message at a time?
Instead of this approach I think we should go with buffered channel.
sem = make(chan *sqs.Message, parallelRequests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ameykpatil I had taken that approach first, but changed it since it doesn't really help. Consumers are almost always slower than producers here.

And it increases the chances of same messages being consumed buy other instances as well. If messages stay in buffer for longer than the SQS visibility timeout, they'd be picked by other gohaqd instances as well.

Does this make sense?

resp, err := svc.ReceiveMessage(msgparams)
if err != nil {
log.Fatalf(err.Error())
}

for _, msg := range resp.Messages {
sem <- msg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ApsOps Would this be blocking if sem already has a message?
Buffered channel should eliminate direct dependency between pollSqs & startConsumer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ameykpatil We want this to block, like I explained in the above comment.

cmd/root.go Outdated
for i := 0; i < parallelRequests; i++ {
go startConsumer(q.QueueUrl)
}

for {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this for loop above the other one?
Looks logically aligned. First poll then process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ameykpatil We can't. Since this is an infinite loop, the following part won't be reachable.

	for i := 0; i < parallelRequests; i++ {
		go startConsumer(q.QueueUrl)
	}

cmd/root.go Outdated
}
}

func pollSQS(queueURL *string) {
func pollSQS() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also good to add function level comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ameykpatil Added some comments.

@ameykpatil ameykpatil merged commit c16ce1f into master May 30, 2017
@ameykpatil ameykpatil deleted the add-parallelism branch May 30, 2017 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants