Merged
Conversation
changelog: Internal, Attempts API, Fetch from Redis in batches
n1zyy
commented
Jan 26, 2023
| end | ||
|
|
||
| def read_events(timestamp:) | ||
| def read_events(timestamp:, batch_size: 5000) |
Contributor
Author
There was a problem hiding this comment.
This is never passed in, but I'm leaving it to allow tinkering in rails c, unless rubocop yells.
Closed
Rwolfe-Nava
approved these changes
Jan 26, 2023
Contributor
Rwolfe-Nava
left a comment
There was a problem hiding this comment.
Looks good to me! Excited for this change!
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
changelog: Internal, Attempts API, Fetch from Redis in batches
🎫 Ticket
LG-8060
🛠 Summary of changes
This story was initially for a series of changes to the background job. Ultimately, none gave a performance improvement, except that reading in batches could be slightly faster, depending on batch size.
But, @zachmargolis pointed out that, because Redis is single-threaded, it's much kinder to Redis to read in batches rather than one gigantic
hgetall. That's the big win; the performance improvement is very marginal.I initially coded this to call
hscaninside a loop, introduced a lulzy infinite loop where we ran untilcounter == 0whencounterwas actually returned as a string, and then realized while looking at the source thathscan_eachalready did what I wanted. I have progressively whittled this down to just a few lines.Note that this will fetch from Redis in batches, but it still builds everything up in one big array before returning it. We may some day want to accept a block to allow us to operate on batches. Today is not that day, though -- the existing EnvelopeEncryptor code expects that we have the whole payload in memory.