A Gossip Peer Sampling Service (GPSS) creates a dynamic, random, self-healing overlay network and provides peers for communication within that topology. This library is designed to be a general-purpose implementation of GPSS, making it useful for a variety of large-scale distributed systems.
Check out a walk through and tutorial here
cmake -S . -B cbuild -DINSTALL_LOCALLY=OFFcmake -S . -B cbuild -DINSTALL_LOCALLY=ONcmake --build cbuild #include <gossip> header.CMakeLists.txt and add_subdirectory(*proj_dir*) to your own CMake based project.Once the project has been built, there are examples for both Python and C++ located in the example/ directory. The behavior is the same for both languages:
gossip_entry_server_example.*192.168.1.173:50000 if no argument is provided.# IPv4
cd cbuild
./gossip_entry_server_example 0.0.0.0:50000
# IPv6
cd cbuild
./gossip_entry_server_example [::]:50000
# IPv4
cd example
python gossip_entry_server_example.py 0.0.0.0:50000
# IPv6
cd example
python gossip_entry_server_example.py [::]:50000
gossip_client_example.*192.168.1.173:60000 if not provided.192.168.1.173:50000 if no arguments are provided.# IPv4
cd cbuild
./gossip_client_example 0.0.0.0:60000 0.0.0.0:50000
# IPv6
cd cbuild
./gossip_client_example [::]:60000 [::]:50000
# IPv4
cd example
python gossip_client_example.py 0.0.0.0:60000 0.0.0.0:50000
# IPv6
cd example
python gossip_client_example.py [::]:60000 [::]:50000
To emulate a network over a local area network (LAN), you can:
Follow the notebook /example/python/simulation_example.ipynb that runs network simulations, calculates statistics, and compares them to the original paper.
Only documentation for the simulator is recorded as using the main library is quite simple unless you want to implement custom views or entry and exit protocols. At which point your best bet is just looking at the codebase anyways (start with view.h and peer_samping_service.h).
Defines a schema for creating simulation nodes with configurable parameters.
name (str): Name of the type this schema definespush (bool): Enable push-based communicationpull (bool): Enable pull-based communicationwait_time (int): Time to wait between communication attemptstimeout (int): Timeout for communicationfunc (Callable[[gossip.PeerSamplingService, gossip.View, gossip.TSLog, threading.Event], None]): Function to be executed by the node’s threadview_type (gossip.View): Type of view to use for network topologyselector_type (gossip.SelectorType): Type of selector for view management**view_kargs: Additional arguments for view initializationgen_node(address, entry_times, exit_times, entry_points=[])
Generates a SimNode based on the schema configuration.
Parameters
address (str): Network address for the nodeentry_times (dict[str, int]): Dictionary to track node entry timesexit_times (dict[str, int]): Dictionary to track node exit timesentry_times (list[str], optional): Initial entry points for the node
ReturnsSimNode A newly created node with the specified configurationThe gen_node() method is generally only called with the Simulator object
schema = NodeSchema(
name="GossipNode",
push=True,
pull=True,
wait_time=1,
timeout=5,
func=custom_node_function,
view_type=NetworkView,
selector_type=RandomSelector,
size=20,
healing=0,
swap=10
)
The Simulator class manages and executes simulations involving multiple network nodes, events, and data logging. It integrates node schemas, handles node lifecycle events, and supports configurable event-driven simulations
schema (dict[str, NodeSchema]): Registry of node schemas defining the characteristics of various node types.events (list[TopologyConstructor]): List of events to construct and execute during the simulation.log_dir (Path, optional): Directory to store simulation logs. Defaults to sim_logs/name (str, optional): Name of the simulation used to save. If None, it defaults to the simulation’s start time.There are many internal methods, if not for being in Python all but the below would be ‘private’
run(stats_interval: int = -1, save: bool = True) -> None
stats_interval (int, optional): Interval for calculating statistics. Defaults to -1. IF -1, indicates not to calc node and network statisticssave (bool, optional): Whether to save logs and statistics. Defaults to True.schema_registry = {
"GossipNode": gossip.NodeSchema(
name="GossipNode",
push=True,
pull=True,
wait_time=1,
timeout=5,
func=custom_node_function,
view_type=gossip.URView,
selector_type=gossip.SelectorType.TAIL,
view_args={'max_size': 10}
)
}
# Define events
events=[gossip.AddEntryServers(entry_nodes={"GossipNode": 4}),
gossip.AddRate(run_time=100, add_rates={"GossipNode": (10, 1)}),
gossip.AddDelay(delay_time=10),
gossip.ChurnRate(run_time=1000, add_rates={"GossipNode": (3, 1)}, rem_rates={"GossipNode": (3, 1)})
]
# Initialize the simulator
sim = Simulator(schema=schema_registry, events=events, name="ExampleSimulation")
# Run the simulation
sim.run(stats_interval=2000)
These topology constructors allow you to dynamically modify the network topology during a simulation by adding, removing, or delaying nodes.
Removes nodes from the simulation at specified rates.
run_time (int): Total duration of the node removal processrem_rates (dict[str, tuple[int, int]], optional): Rates for removing nodes
entry_rem_rates (dict[str, tuple[int, int]], optional): Rates for removing entry nodes
remove_config = RemoveRate(
run_time=60,
rem_rates={'Echo': (4, 1), 'Database': (1, 2)}, # Remove 4 Echo Type Nodes per 1 second and 1 Database Type Node per 2 seconds
entry_rem_rates={'BootStrap': (2, 1)} # Remove 2 Bootstrap Type Entry Nodes per 1 second
)
Allows both adding and removing nodes during the simulation.
run_time (int): Total duration of defined network churnrem_rates (dict[str, tuple[int, int]], optional): Rates for removing nodes
entry_rem_rates (dict[str, tuple[int, int]], optional): Rates for removing entry nodes
add_rates (dict[str, tuple[int, int]], optional): Rates for adding nodes
entry_add_rates (dict[str, tuple[int, int]], optional): Rates for adding entry nodes
churn_config = ChurnRate(
run_time=120,
rem_rates={'Echo': (2, 1), 'Database': (1, 2)}, # Remove 2 Echo Nodes per 1 second, 1 Database Node per 2 seconds
add_rates={'Worker': (3, 1)}, # Add 3 Worker Nodes per 1 second
entry_rem_rates={'BootStrap': (1, 1)}, # Remove 1 Bootstrap Entry Node per 1 second
entry_add_rates={'Aggregator': (2, 1)} # Add 2 Aggregator Entry Nodes per 1 second
)
Allows adding nodes during the simulation.
run_time (int): Total duration to add nodesadd_rates (dict[str, tuple[int, int]], optional): Rates for adding nodes
entry_add_rates (dict[str, tuple[int, int]], optional): Rates for adding entry nodes
churn_config = ChurnRate(
run_time=120,
add_rates={'Worker': (3, 1)}, # Add 3 Worker Nodes per 1 second
entry_add_rates={'Aggregator': (2, 1)} # Add 2 Aggregator Entry Nodes per 1 second
)
Introduces a delay in the simulation. Use to allow existing network to run without interference.
delay_time (int): Total duration of delaychurn_config = ChurnRate(
delay_time=120,
)
Creates a lattice topology by adding nodes with connections predefined upon entry.
entry_nodes (dict[str, int], optional): Number of entry nodes of each type to add
nodes (dict[str, int], optional): Number of nodes of each type to add
use_entry: Should these nodes still use entry_servers after entering with there initial lattice topologylattice_config = AddLattice(
entry_nodes={'BootStrap': 2}, # Add 2 Bootstrap Entry Nodes
nodes={'Worker': 5, 'Database': 2} # Add 5 Worker Nodes and 2 Database Nodes
)
Adds entry nodes to the simulation.
entry_nodes (dict[str, int], optional): Number of entry nodes of each type to add
entry_config = AddEntryServers(
entry_nodes={'Client': 3, 'BootStrap': 2} # Add 3 Client Entry Nodes and 2 Bootstrap Entry Nodes
)
Creates a random graph topology using the Erdős-Rényi model
entry_nodes (dict[str, int], optional): Number of entry nodes of each type to add
nodes (dict[str, int]): Number of nodes of each type to add
edge_prob (float): Probability of an edge existing between any two nodeserdos_config = AddErdosRenyi(
entry_nodes={'BootStrap': 2}, # Add 2 Bootstrap Entry Nodes
nodes={'Worker': 5, 'Database': 2}, # Add 5 Worker Nodes and 2 Database Nodes
edge_prob=0.3 # 30% chance of an edge between any two nodes
)
Creates a random graph topology using the Erdős-Rényi model
entry_nodes (dict[str, int], optional): Number of entry nodes of each type to add
nodes (dict[str, int]): Number of nodes of each type to add
edge_prob (float): Probability of an edge existing between any two nodeserdos_config = AddErdosRenyi(
entry_nodes={'BootStrap': 2}, # Add 2 Bootstrap Entry Nodes
nodes={'Worker': 5, 'Database': 2}, # Add 5 Worker Nodes and 2 Database Nodes
edge_prob=0.3 # 30% chance of an edge between any two nodes
)
This product uses gRPC which is licensed under the Apache License, Version 2.0