Created
March 10, 2017 20:08
-
-
Save dankleiman/02664a6f0a5a3b0556740cc229e10220 to your computer and use it in GitHub Desktop.
Code for Real-time Deduping at scala
This file contains 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
buckets = keys_per_minute / keys_per_bucket | |
buckets_per_min = 2,000,000 / 100 = 20,000 | |
buckets_per_sec = 20,000 / 60 = 333 |
This file contains 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
(overhead + key_bytes + value_bytes) * keys_per_minute * 60 * 24 | |
(64 + 36 + 13) * 2,000,000 * 60 * 24 = 300GB |
This file contains 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
HMGET(bucket, message_ids) | |
message_ids.each do | |
if existing owner matches or not set | |
not dupe | |
else | |
dupe | |
end | |
end | |
HMSET(bucket, new_message_ids_and_values) | |
return dupes |
This file contains 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
((per_key_overhead + key_bytes + value_bytes) * keys_per_minute) * 60 * 24 + | |
((per_bucket_overhead + bucket_key_bytes) * buckets_per_minute * 60 * 24 | |
((1 + 16 + 8) * 2,000,000) * 60 * 24 + | |
((64 + 14) * 20,000 * 60 * 24 | |
= (72,000,000,000 + 2,246,400,000) = 69GB |
This file contains 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
message_ids.each do |message_id, owner_id| | |
client.HSETNX(message_id, owner_id) # claim owner | |
client.HGET(message_id) # determine winner | |
end |
This file contains 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
(per_key_overhead + key_bytes + value_bytes) * keys_per_minute * 60 * 24 | |
(64 + 16 + 8) * 2,000,000 * 60 * 24 = 230GB |
This file contains 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
ByteBuffer.allocate(2).putShort(partition.toShort).array ++ ByteBuffer.allocate(8).putLong(offset).array.slice(2, 8) |
This file contains 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
client.pipeline do |pipeline| | |
message_ids.each do |message_id, owner_id| | |
pipeline.HSETNX(message_id, owner_id) # claim owner | |
pipeline.HGET(message_id) # determine winner | |
end | |
end |
This file contains 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
val uuid = java.util.UUID.fromString("ce059644-18a0-4f27-bc2b-c2a2d4d4e7bf") | |
val hi = uuid.getMostSignificantBits | |
val lo = uuid.getLeastSignificantBits | |
ByteBuffer.allocate(16).putLong(hi).putLong(lo).array | |
// => Array(-50, 5, -106, 68, 24, -96, 79, 39, -68, 43, -62, -94, -44, -44, -25, -65) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment