Skip to content
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

Membership discovery and (self) awareness improvements #16

Merged
merged 6 commits into from Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/broadcast.rs
Expand Up @@ -207,6 +207,10 @@ where
.windows(2)
.all(|w| w[0].remaining_tx <= w[1].remaining_tx)
}

pub fn is_empty(&self) -> bool {
self.storage.is_empty()
}
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -242,13 +246,6 @@ impl<T: AsRef<[u8]>> PartialOrd for Entry<T> {
}
}

#[cfg(test)]
impl<T> Broadcasts<T> {
pub fn is_empty(&self) -> bool {
self.storage.is_empty()
}
}

#[cfg(test)]
mod tests {

Expand Down
97 changes: 97 additions & 0 deletions src/config.rs
Expand Up @@ -94,10 +94,80 @@ pub struct Config {
/// to a value smaller than your network's MTU. 1400 is a good
/// value for a in a non-ancient network.
pub max_packet_size: NonZeroUsize,

/// Wether foca should try to let members that are down know about it
///
/// Whenever a member is declared down by the cluster, their messages
/// get ignored and there's no way for them to learn that this is happening.
/// With this setting enabled, will try to notify the down member that
/// their messages are being discarded.
///
/// This feature is an extension to the SWIM protocol and should be left
/// disabled if you're aiming at pure SWIM behavior.
pub notify_down_members: bool,

/// How often should foca ask its peers for more peers
///
/// [`crate::Message::Announce`] is the mechanism foca uses to discover
/// members. After joining a sizeable cluster, it may take a while until
/// foca discovers every active member. Periodically announcing helps speed
/// up this process.
///
/// This setting is helpful for any cluster size, but smaller ones can
/// get by without it if discovering the full active roster quickly is
/// not a requirement.
///
/// As a rule of thumb, use large values for `frequency` (say, every
/// 30s, every minute, etc) and small values for `num_members`: just
/// one might be good enough for many clusters.
///
/// Whilst you can change the parameters at runtime, foca prevents you from
/// changing it from `None` to `Some` to simplify reasoning. It's required
/// to recreate your foca instance in these cases.
///
/// This feature is an extension to the SWIM protocol and should be left
/// disabled if you're aiming at pure SWIM behavior.
pub periodic_announce: Option<PeriodicParams>,

/// How often should foca send cluster updates to peers
///
/// By default, SWIM disseminates cluster updates during the direct and
/// indirect probe cycle (See [`crate::Message`]). This setting instructs
/// foca to also propagate updates periodically.
///
/// Periodically gossiping influences the speed in which the cluster learns
/// new information, but gossiping too much is often unnecessary since
/// cluster changes are not (normally) high-rate events.
///
/// A LAN cluster can afford high frequency gossiping (every 200ms, for example)
/// without much worry; A WAN cluster might have better results gossiping less
/// often (500ms) but to more members at once.
///
/// Whilst you can change the parameters at runtime, foca prevents you from
/// changing it from `None` to `Some` to simplify reasoning. It's required
/// to recreate your foca instance in these cases.
///
/// This feature is an extension to the SWIM protocol and should be left
/// disabled if you're aiming at pure SWIM behavior.
pub periodic_gossip: Option<PeriodicParams>,
}

/// Configuration for a task that should happen periodically
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PeriodicParams {
/// How often should the task be performed
pub frequency: Duration,
/// How many random members should be chosen
pub num_members: NonZeroUsize,
}

impl Config {
/// A simple configuration that should work well in a LAN scenario.
///
/// This is Foca in its simplest form and has no extensions enabled.
/// Use this config if you are trying to get a grasp of how SWIM
/// works, without any additional behavior.
pub fn simple() -> Self {
Self {
probe_period: Duration::from_millis(1500),
Expand All @@ -110,6 +180,11 @@ impl Config {
remove_down_after: Duration::from_secs(15),

max_packet_size: NonZeroUsize::new(1400).unwrap(),

notify_down_members: false,

periodic_announce: None,
periodic_gossip: None,
}
}
}
Expand Down Expand Up @@ -144,6 +219,17 @@ impl Config {
remove_down_after: Duration::from_secs(15),

max_packet_size: NonZeroUsize::new(1400).unwrap(),

notify_down_members: true,

periodic_announce: Some(PeriodicParams {
frequency: Duration::from_secs(30),
num_members: NonZeroUsize::new(1).unwrap(),
}),
periodic_gossip: Some(PeriodicParams {
frequency: Duration::from_millis(200),
num_members: NonZeroUsize::new(3).unwrap(),
}),
}
}

Expand All @@ -169,6 +255,17 @@ impl Config {
remove_down_after: Duration::from_secs(15),

max_packet_size: NonZeroUsize::new(1400).unwrap(),

notify_down_members: true,

periodic_announce: Some(PeriodicParams {
frequency: Duration::from_secs(60),
num_members: NonZeroUsize::new(2).unwrap(),
}),
periodic_gossip: Some(PeriodicParams {
frequency: Duration::from_millis(500),
num_members: NonZeroUsize::new(4).unwrap(),
}),
}
}

Expand Down