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

Memoization of boolean causes extra calls to SQS #529

Merged
merged 4 commits into from
Oct 30, 2018

Conversation

timbreitkreutz
Copy link
Contributor

This was causing us to get rate limited by SQS. Our team eventually found this boolean memoization bug which solved the rate limiting problem for us.

@timbreitkreutz timbreitkreutz mentioned this pull request Oct 29, 2018
Co-authored-by: Alec Kloss <[email protected]>
Co-authored-by: William Johnston <[email protected]>
lib/shoryuken/queue.rb Outdated Show resolved Hide resolved
@timbreitkreutz
Copy link
Contributor Author

@phstc Thanks for the feedback. I think this is ready to go :)

@phstc phstc merged commit ef585d6 into ruby-shoryuken:master Oct 30, 2018
@phstc
Copy link
Collaborator

phstc commented Oct 30, 2018

@timbreitkreutz thanks for the fix 🍻 Shoryuken 3.3.1 is out with your fix.

@phstc
Copy link
Collaborator

phstc commented Oct 31, 2018

Hi @timbreitkreutz

I think I found another unexpected behavior with FIFO queues and Shoryuken:

The message group ID is the tag that specifies that a message belongs to a specific message group. Messages that belong to the same message group are always processed one by one, in a strict order relative to the message group (however, messages that belong to different message groups might be processed out of order).

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html

Messages that belong to the same message group are always processed one by one

In the way Shoryuken works now, it is grabbing up to 10 messages per receive_message even for FIFOs, see https://github.com/phstc/shoryuken/blob/46456fb4aa00321ee95ac40b19e472613d0b93ab/lib/shoryuken/fetcher.rb#L50

What I think it should do instead is every time it fetches messages for a FIFO queue, it should fetch one at the time:

    def receive_messages(queue, limit)
      options = receive_options(queue)

      shoryuken_queue = Shoryuken::Client.queues(queue.name)

      options[:max_number_of_messages]  = shoryuken_queue.fifo? ? 1 : max_number_of_messages(limit, options)
      options[:message_attribute_names] = %w[All]
      options[:attribute_names]         = %w[All]

      options.merge!(queue.options)

      shoryuken_queue.receive_messages(options)
    end

Otherwise, you may end up processing more than one message per group at the time.

WDYT?

@timbreitkreutz
Copy link
Contributor Author

Makes sense to me— we are not yet using fifo queues with shoryuken though.

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