Skip to content

Commit eb80aa5

Browse files
committed
limit send queue size
1 parent 2abc5e9 commit eb80aa5

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

Cargo.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fastbloom-rs = "0.5.9"
4848
ollama-workflows = { git = "https://github.com/andthattoo/ollama-workflows", rev = "d6b2e1e" }
4949

5050
# peer-to-peer
51-
libp2p = { git = "https://github.com/anilaltuner/rust-libp2p.git", rev = "62f910e", features = [
51+
libp2p = { git = "https://github.com/anilaltuner/rust-libp2p.git", rev = "3c55e95", features = [
5252
# libp2p = { version = "0.54.1", features = [
5353
"dcutr",
5454
"ping",

src/p2p/behaviour.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ fn create_gossipsub_behavior(author: PeerId) -> gossipsub::Behaviour {
9898
/// and check their fields based on whether they exist or not.
9999
const VALIDATION_MODE: ValidationMode = ValidationMode::Permissive;
100100

101+
/// Heartbeat interval in seconds
102+
const HEARTBEAT_INTERVAL_SECS: u64 = 10;
103+
104+
/// Duplicate cache time in seconds
105+
const DUPLICATE_CACHE_TIME_SECS: u64 = 120;
106+
101107
/// Gossip cache TTL in seconds
102108
const GOSSIP_TTL_SECS: u64 = 100;
103109

@@ -111,6 +117,10 @@ fn create_gossipsub_behavior(author: PeerId) -> gossipsub::Behaviour {
111117
/// because we don't need historic messages at all
112118
const MAX_IHAVE_LENGTH: usize = 100;
113119

120+
/// Max size of the send queue
121+
/// This helps to avoid memory exhaustion during high load
122+
const MAX_SEND_QUEUE_SIZE: usize = 400;
123+
114124
// message id's are simply hashes of the message data
115125
let message_id_fn = |message: &Message| {
116126
let mut hasher = hash_map::DefaultHasher::new();
@@ -123,15 +133,17 @@ fn create_gossipsub_behavior(author: PeerId) -> gossipsub::Behaviour {
123133
Behaviour::new(
124134
MessageAuthenticity::Author(author),
125135
ConfigBuilder::default()
126-
.heartbeat_interval(Duration::from_secs(10))
127-
.max_transmit_size(MAX_TRANSMIT_SIZE) // 256 KB
136+
.heartbeat_interval(Duration::from_secs(HEARTBEAT_INTERVAL_SECS))
137+
.max_transmit_size(MAX_TRANSMIT_SIZE)
128138
.message_id_fn(message_id_fn)
139+
.message_capacity(MESSAGE_CAPACITY)
129140
.message_ttl(Duration::from_secs(MESSAGE_TTL_SECS))
130141
.gossip_ttl(Duration::from_secs(GOSSIP_TTL_SECS))
131-
.message_capacity(MESSAGE_CAPACITY)
142+
.duplicate_cache_time(Duration::from_secs(DUPLICATE_CACHE_TIME_SECS))
143+
.max_ihave_length(MAX_IHAVE_LENGTH)
144+
.send_queue_size(MAX_SEND_QUEUE_SIZE)
132145
.validation_mode(VALIDATION_MODE)
133146
.validate_messages()
134-
.max_ihave_length(MAX_IHAVE_LENGTH)
135147
.build()
136148
.expect("Valid config"), // TODO: better error handling
137149
)

0 commit comments

Comments
 (0)