Last active
July 29, 2018 15:18
-
-
Save darxtrix/819a4eb01743ff3c5bc5047d5184b8be to your computer and use it in GitHub Desktop.
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
/* | |
Assume 1M total subscribers on ticker_INR channel | |
*/ | |
// Without sharding | |
go func() { | |
// 1M subscribers since ticker_INR is a public channel | |
subscribersBST := channelSubscriberStateMap.Get("ticker_INR") | |
subscribers := subscribersBST.inorder() | |
// This loop will again take time due to large number of subscribers | |
for _, subscriber := range subscribers { | |
go subscriber.send(message) | |
} | |
} | |
// With sharding | |
go func() { | |
// The iterations are limited here by SHARD_COUNT (1k shards in our case) | |
for shardNumber = 0 ; shardNumber < channelSubscriberStateMap.GetNumShars() ; shardNumber++ { | |
go func() { | |
// Number of subscribers in a shards are ~1k only | |
subscribersBST := channelSubscriberStateMap.GetBySharNumber("ticker_INR",shardNumber) | |
subscribers := subscribersBST.inorder() | |
// This loop will take very less time | |
for _, subscriber := range subscribers { | |
go subscriber.send(message) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment