Skip to content

Conversation

chakaz
Copy link
Contributor

@chakaz chakaz commented Jun 1, 2023

In this case, redis.RedisCluster.

To be double sure I also looked at the actual packets and saw that the client asks for CLUSTER SLOTS, and then after the redistribution of slots, following a few MOVED replied, it asks for the new slots again.

@chakaz chakaz requested a review from adiholden June 1, 2023 20:12
Comment on lines 349 to 354
client = redis.RedisCluster(decode_responses=True, host="localhost", port=nodes[0].port)

for i in range(10_000):
key = 'key' + str(i)
assert client.set(key, 'value') == True
assert client.get(key) == 'value'
Copy link
Contributor

Choose a reason for hiding this comment

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

Small note: you're using the sync client inside an async function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that's a good catch!
I'm new to Python async (and also to Python in general).
My goal here is to use RedisCluster, which seems to be a sync library. Is there a way for me to still use the other async tools we have here, like push_config() and get_node_id()?
Alternatively I guess I could use run_in_executor() (from here), do you think that's advisable?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the async aioredis.RedisCluster (which is now just a re-export of the official redis.asyncio). It should have the same interface

If there were only the sync version, wouldn't have caused any trouble either way, as you only perform sequential operations and don't have any tasks running

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That worked, thanks!

@chakaz chakaz force-pushed the py-redis-cluster branch from f9091db to d5a8a1a Compare June 4, 2023 05:31
@adiholden
Copy link
Contributor

@chakaz This looks good. Will you please add also replica so we will check our client commands with replicas

@chakaz chakaz requested a review from dranikpg June 4, 2023 14:01
In this case, `redis.RedisCluster`.

To be double sure I also looked at the actual packets and saw that the
client asks for `CLUSTER SLOTS`, and then after the redistribution of
slots, following a few `MOVED` replied, it asks for the new slots again.
@chakaz chakaz force-pushed the py-redis-cluster branch from c57dec6 to 484c7bb Compare June 4, 2023 18:42
Copy link
Contributor

@dranikpg dranikpg left a comment

Choose a reason for hiding this comment

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

Python part looks valid, left a small performance comment. You could've formatted the config in a more compact way to save some lines and make it easier to read, but it probably doesn't matter in this test.

I don't track the cluster progress in depth, so please don't rely on me in reviews

Comment on lines 566 to 570

for i in range(10_000):
key = 'key' + str(i)
assert await client.set(key, 'value') == True
assert await client.get(key) == 'value'
Copy link
Contributor

Choose a reason for hiding this comment

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

About the recent timeout in CI that we had. In the future:

  • such parts can be split in multiple tasks that run concurrently, all on its range or modulo
  • possibly ranges that surely belong to a single node can be handled in pipelines?

When more tests are added, it can add up to hundreds of thousands or requests (its already 40k for this test). Github runners in debug mode have a very low throughput.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whats also under question if this load is needed. Replication tests trigger all kinds of edge cases with different values and higher load (replicate during update, etc...). Here it seems like it doesn't really matter and you verify only correctness. So you could for example check 10% random values of the range: if you have a bug it's likely to be found in one or a few passes, otherwise why check the whole range

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not realize we're so constraint!
Thanks for the comment, I tuned down the test.

dranikpg
dranikpg previously approved these changes Jun 5, 2023
assert await client.get(key) == 'value'

# Make sure that getting a value from a replica works as well.
replica_response = await client.execute_command(
Copy link
Contributor

Choose a reason for hiding this comment

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

you dont wait here for the replica to finish replicating all the changes

await push_config(config, c_masters_admin + c_replicas_admin)

for i in range(100):
key = 'key' + str(i)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if you want to set only 100 keys you should generate a random key so that we test all slots when this test runs few times

client = aioredis.RedisCluster(decode_responses=True, host="localhost", port=masters[0].port)

for i in range(100):
key = 'key' + str(i)
Copy link
Contributor

Choose a reason for hiding this comment

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

also here random key.
Maybe create nested function , you have the same loop below

@chakaz chakaz requested a review from adiholden June 6, 2023 08:41
assert await client.get(key) == 'value'
async def test_random_keys():
for i in range(100):
key = 'key' + str(i)
Copy link
Contributor

Choose a reason for hiding this comment

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

you forgot to add the random call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, nice catch :)

@chakaz chakaz requested a review from adiholden June 6, 2023 09:51
@chakaz chakaz merged commit de21afc into main Jun 6, 2023
@chakaz chakaz deleted the py-redis-cluster branch June 6, 2023 13:03
dranikpg pushed a commit to dranikpg/dragonfly that referenced this pull request Jun 9, 2023
dragonflydb#1336)

In this case, `redis.RedisCluster`.

To be double sure I also looked at the actual packets and saw that the
client asks for `CLUSTER SLOTS`, and then after the redistribution of
slots, following a few `MOVED` replied, it asks for the new slots again.
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.

3 participants