Skip to content

Instantly share code, notes, and snippets.

@darxtrix
Last active July 29, 2018 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darxtrix/819a4eb01743ff3c5bc5047d5184b8be to your computer and use it in GitHub Desktop.
Save darxtrix/819a4eb01743ff3c5bc5047d5184b8be to your computer and use it in GitHub Desktop.
/*
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