Skip to content

LG-8060 | Fetch from Redis in batches#7706

Merged
n1zyy merged 1 commit intomainfrom
mattw/LG-8060_redis_in_batches
Jan 26, 2023
Merged

LG-8060 | Fetch from Redis in batches#7706
n1zyy merged 1 commit intomainfrom
mattw/LG-8060_redis_in_batches

Conversation

@n1zyy
Copy link
Contributor

@n1zyy n1zyy commented Jan 26, 2023

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 hscan inside a loop, introduced a lulzy infinite loop where we ran until counter == 0 when counter was actually returned as a string, and then realized while looking at the source that hscan_each already 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.

changelog: Internal, Attempts API, Fetch from Redis in batches
end

def read_events(timestamp:)
def read_events(timestamp:, batch_size: 5000)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is never passed in, but I'm leaving it to allow tinkering in rails c, unless rubocop yells.

@n1zyy n1zyy requested a review from a team January 26, 2023 15:54
@n1zyy n1zyy mentioned this pull request Jan 26, 2023
Copy link
Contributor

@Rwolfe-Nava Rwolfe-Nava left a comment

Choose a reason for hiding this comment

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

Looks good to me! Excited for this change!

@n1zyy n1zyy merged commit 0d6fd34 into main Jan 26, 2023
@n1zyy n1zyy deleted the mattw/LG-8060_redis_in_batches branch January 26, 2023 17:16
@mdiarra3 mdiarra3 mentioned this pull request Jan 26, 2023
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