perf(redis): fetch get_cache_data in chunked, non-transactional pipelines - #212
Merged
Merged
Conversation
…ines get_cache_data sent GET and PTTL for the whole keyspace in one pipeline, which redis-py makes transactional by default. The server therefore ran every command inside a single MULTI/EXEC and blocked other clients for its duration on a large keyspace. Send the commands in pipelines of _BATCH_SIZE keys with transaction=False. Monitoring does not need a consistent snapshot, and each chunk's expiry is still measured right after its own round trip. Closes #171
18 of 20 tasks
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.
Closes #171
Problem
get_cache_dataqueued aGETand aPTTLfor every key in oneself.client.pipeline(), which redis-py makes transactional by default. The server therefore ran all 2N commands inside a singleMULTI/EXECand blocked other clients for its duration on a large keyspace. With 250 keys, the recorded pipelines (transactional, commands) were[(True, 500)].Change
_BATCH_SIZE(100) keys withtransaction=False. The same 250 keys now produce[(False, 200), (False, 200), (False, 100)].nowis taken right after its ownexecute(), so the reported absolute expiry stays accurate to that round trip.PTTL == -2, as before.Tests
test_redis_get_cache_data_uses_chunked_non_transactional_pipelines: over 210 keys it checks three non-transactional pipelines, at most2 * _BATCH_SIZEcommands each, 2N commands in total, and every entry returned with an expiry.redis.pyreverted to master, only this test fails.transaction=Falsedropped, only this test fails.mypy --strict, full suite against live Redis and Memcached (CACHEX_REQUIRE_LIVE_SERVERS=1): 862 passed.backends/redis.pycoverage is 100%.CHANGELOG entry
Section: Changed (tracked in #206)