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

Reduce message batches in requeue and mv commands #666

Merged

Conversation

cjlarose
Copy link
Collaborator

@cjlarose cjlarose commented Apr 7, 2021

Follow-up to #664

This change replaces the `rerun` parameter with a separate method that
just handles messages post-normalization, just to improve readability.
Since it's possible now to send a batch with fewer messages than
`messages_per_batch`, the parameter is really just an upper bound for
the number of messages to put into any single batch.
The previous algorithm computed the size of a batch of messages using
the Ruby literal representation of the messages, which overestimates the
true size of the messages as SQS computes it. While overestimating is
relatively benign, it does mean that we can end up making more SQS API
calls than necessary.
The previous algorithm considered each `max_batch_size`-sized slice of
the messages in order. For each slice, it'd subdivide the slice until
the batches were small enough to send.

To minimize the number of batches we send, however, it makes more sense
to take as many messages as we can from the beginning of the list of
messages, and just do that repeatedly until we've sent them all.
@cjlarose cjlarose merged commit 87b3d60 into ruby-shoryuken:master Apr 7, 2021
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.

1 participant