A robust implementation of the SWIM (Scalable Weakly-consistent Infection-style Process Group Membership) protocol in Ruby, designed for building reliable distributed systems and microservices.
- Distributed Node Discovery: Automatic node discovery and membership management
- Failure Detection: Fast and accurate failure detection with configurable timeouts
- State Synchronization: Efficient distributed state management with version control
- Metadata Management: Flexible metadata storage and synchronization
- HTTP Monitoring: Built-in HTTP endpoints for monitoring and debugging
- Configurable Logging: Multiple log levels for different debugging needs
Add this line to your application's Gemfile:
gem 'ruby-swim-microservices'
Or install it directly:
gem install ruby-swim-microservices
- Create a new node:
require 'swim'
# Initialize a node
node = Swim::Protocol.new('localhost', 3000)
# Add some metadata
node.set_metadata("#{node.host}:#{node.port}:role", 'primary')
node.set_metadata("#{node.host}:#{node.port}:region", 'us-west')
# Start the node
node.start
- Run the example cluster:
# Start a cluster with default settings
ruby examples/cluster.rb
# Start with custom settings
ruby examples/cluster.rb --nodes 5 --base-port 3000 --log-level DEBUG
The framework supports various configuration options:
host
: Host address (default: localhost)port
: Port number for SWIM protocolseeds
: List of seed nodes for joining the clusterinitial_metadata
: Initial metadata for the node
PROTOCOL_PERIOD
: Main protocol loop interval (1.0 seconds)PING_TIMEOUT
: Direct ping timeout (0.5 seconds)PING_REQUEST_TIMEOUT
: Indirect ping timeout (0.5 seconds)SYNC_INTERVAL
: State synchronization interval (10.0 seconds)
PING_TIMEOUT
: 5 secondsSUSPICIOUS_TIMEOUT
: 10 secondsFAILED_TIMEOUT
: 30 seconds
The framework provides several HTTP endpoints for monitoring:
GET /status
: Basic node status and statisticsGET /members
: List of all cluster members and their statusGET /metadata
: Node metadata informationGET /state
: Current distributed state
-
Protocol
- Node discovery and membership management
- Failure detection
- Message handling
- State synchronization
-
StateManager
- Distributed state management
- Version control
- State merging
- Change notifications
-
Member
- Member status tracking
- Timeout management
- Health monitoring
-
HTTPServer
- Monitoring endpoints
- Status reporting
- Debug information
join
: Node joining requestmembers
: Member list exchangeping
: Health checkack
: Ping acknowledgmentping_req
: Indirect ping requestupdate
: Status updatestate_sync
: Full state synchronizationstate_update
: Incremental state update
rake test
Use different log levels for debugging:
ruby examples/cluster.rb --log-level DEBUG
ruby examples/cluster.rb --log-level INFO
ruby examples/cluster.rb --log-level WARN
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -am 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Based on the SWIM paper by Abhinandan Das, Indranil Gupta, and Ashish Motivala
- Inspired by various SWIM implementations in the open-source community
This project is actively maintained and used in production environments. Please report any issues or feature requests through the issue tracker.