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

Murmur hashing fails with more than 2 shards #58

Closed
Iker-Jimenez opened this issue Nov 30, 2010 · 1 comment
Closed

Murmur hashing fails with more than 2 shards #58

Iker-Jimenez opened this issue Nov 30, 2010 · 1 comment

Comments

@Iker-Jimenez
Copy link

I have a ShardedJedisPool configured to use Murmur Hashing.
If I use it with two shards it splits the keys evenly among them.
If I add a third shard the first shard gets around 25% of they keys, the second one around 75% and the third one none.

@Iker-Jimenez
Copy link
Author

Added unit test:
@test
public void testMurmurSharding() throws Exception {
List shards = new ArrayList(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards,
Hashing.MURMUR_HASH);
int shard_6379 = 0;
int shard_6380 = 0;
int shard_6381 = 0;
for (int i = 0; i < 1000; i++) {
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
switch (jedisShardInfo.getPort()) {
case 6379:
shard_6379++;
break;
case 6380:
shard_6380++;
break;
case 6381:
shard_6381++;
break;
default:
fail("Attempting to use a non-defined shard!!:" + jedisShardInfo);
break;
}
// System.out.println("key=" + i + " shard=" + sharded.getShardInfo(Integer.toString(i)));
}
System.out.println("6379:" + shard_6379);
System.out.println("6380:" + shard_6380);
System.out.println("6381:" + shard_6381);
assertTrue(shard_6379 > 300 && shard_6379 < 400);
assertTrue(shard_6380 > 300 && shard_6380 < 400);
assertTrue(shard_6381 > 300 && shard_6381 < 400);
}

This issue was closed.
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

No branches or pull requests

1 participant