-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thread-safe subscriptions and listener cleanup (#166)
This PR adds: - Thread-safety for mutation of listener maps - Safe cleanup flow for listener channels As a general principle, we use Golang's `sync.map`. This is an optimistic concurrency pattern that restricts contention to a per-key level, and separates reads and writes via a read-only map and dirty map. So the dispatch loop is not affected - any mutations to the sync maps are performed outside of the dispatching goroutine. I've also added a `RWMutex` to synchronize between adding and removing listeners. The main thing we are protecting against is that when removing a listener, we may want to delete the `listenerset` if it is empty - but we can't perform the emptiness check and the deletion step atomically without a mutex. I think this should be okay, because in the current server we are getting something like 10 new subscriptions a second. Would love to do some benchmarking on this later to make sure we've made the right tradeoffs, I can see us changing out the implementation underneath depending on where the bottleneck is. Closes #125
- Loading branch information
1 parent
4caf7ad
commit 2427b56
Showing
3 changed files
with
158 additions
and
58 deletions.
There are no files selected for viewing
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
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
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