-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs: update pub-sub.md to reflect ShardedHashMap architecture #7239
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,9 +2,10 @@ | |||||||||||||
|
|
||||||||||||||
| This document describes how Dragonfly implements the Publish-Subscribe (Pub/Sub) messaging | ||||||||||||||
| paradigm within its shared-nothing, multi-threaded architecture. It covers the global | ||||||||||||||
| subscription registry, the Read-Copy-Update (RCU) mechanism used to prevent lock contention | ||||||||||||||
| on the publish path, the asynchronous message delivery pipeline, and the backpressure system | ||||||||||||||
| that protects the server from slow-subscriber OOM. | ||||||||||||||
| subscription registry backed by a `ShardedHashMap` with fine-grained per-shard locking, | ||||||||||||||
| the RCU-style pointer swap used for lock-free reads on the publish path, the asynchronous | ||||||||||||||
| message delivery pipeline, and the backpressure system that protects the server from | ||||||||||||||
| slow-subscriber OOM. | ||||||||||||||
|
Comment on lines
+6
to
+8
|
||||||||||||||
| the RCU-style pointer swap used for lock-free reads on the publish path, the asynchronous | |
| message delivery pipeline, and the backpressure system that protects the server from | |
| slow-subscriber OOM. | |
| the RCU-style pointer swap and per-shard shared locking used for concurrent reads on the | |
| publish path, the asynchronous message delivery pipeline, and the backpressure system that | |
| protects the server from slow-subscriber OOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/pub-sub.md:48: ShardedHashMap is templated on the shard count (default is 32 in sharded_hash_map.h), while ChannelStore uses 16. Consider wording this row as “N shards (ChannelStore uses 16)” to avoid implying the container is always 16-way sharded.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Copilot
AI
Apr 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ShardedHashMap type itself is generic (default NUM_SHARDS=32), so describing it as “split into 16 shards” is only true for the ChannelStore::ChannelMap instantiation. Also, ChannelMap is defined with a transparent hash/equality (StringViewHash, std::equal_to<>) to support std::string_view lookups used by FindIf; consider reflecting that in the type/description to avoid implying the simpler 3-parameter template.
| | `ShardedHashMap` | `src/core/sharded_hash_map.h` | Thread-safe hash map split into 16 shards, each with independent `write_mu_` (Mutex) and `read_mu_` (SharedMutex). | | |
| | `ChannelStore::ChannelMap` | `src/server/channel_store.h` | `ShardedHashMap<string, UpdatablePointer, 16>` — maps channel/pattern names to subscriber lists across 16 independently-locked shards. | | |
| | `ShardedHashMap` | `src/core/sharded_hash_map.h` | Generic thread-safe sharded hash map template with independently locked shards (`write_mu_` and `read_mu_`); shard count depends on the template instantiation. | | |
| | `ChannelStore::ChannelMap` | `src/server/channel_store.h` | `ShardedHashMap<string, UpdatablePointer, 16, StringViewHash, std::equal_to<>>` — maps channel/pattern names to subscriber lists across 16 independently locked shards and supports transparent `std::string_view` lookups. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/pub-sub.md:49: The ChannelMap alias in code includes StringViewHash + std::equal_to<> for heterogeneous lookup (e.g. std::string_view in FindIf). Consider either spelling out the full alias or noting the transparent hash/equality requirement so the later FindIf(channel, ...) examples stay accurate.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/pub-sub.md:51: Similar to the intro, “lock-free reads” is a bit ambiguous here since readers still acquire read_mu_ shared; only the UpdatablePointer::Get() atomic load itself is lock-free. Consider tightening the wording to reflect that distinction.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/pub-sub.md:6: This mentions “lock-free reads on the publish path”, but
FetchSubscribersdoes takeread_mu_in shared mode viaShardedHashMap::FindIf/ForEachShared. Consider rephrasing to avoid implying the publish path is fully lock-free (it’s lock-free only for theUpdatablePointerload).Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.