swimy

package module
v0.0.0-...-0e7f584 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 16 Imported by: 0

README

swimy

Simple, unambitious implementation of swimy: Scalable Weakly-consistent Infection-style Process Group Membership Protocol plus some improvements.

Usage


    cfg := swimy.DefaultConfig()
    cfg.OnJoin = func(addr net.Addr) {
    // do something with the notification
    }
    cfg.OnLeave = func(addr net.Addr) {
    // do something with the notification
    }
    ms1, err := swimy.New(cfg)
    if err != nil {
    //
    }
    defer ms1.Stop()
    
    // some other app
    ms2, err := swimy.New(nil) 
    if err != nil {
    //
    }
    defer ms2.Stop()
    err := ms2.Join(ctx, "127.0.0.1:54555") // existing known members to join the membership

Decisions

  • Failure is immediately disseminated by multicast
    • using gossip style dissemination could have reduced msgs going around, yet reducing convergence speed.
  • Gossip uses randomness rather than round-robin
    • round-robin may be added for probing to reduce time to detect failure

TODOs

  • Add suspect mechanism to prevent false positives
  • Implement lamport clock
  • Instrument via otel & slog
  • TCP conn. pooling per addr
  • Add failure testing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port              uint16 // binding lister to
	MaxSuspicionCount int
	GossipInterval    time.Duration // duration of gossiping with members, default: 20ms
	GossipRatio       uint8         // min. percentage of gossiping active members concurrently. default: 20 (%20)
	IOTimeout         time.Duration
	OnJoin, OnLeave   func(addr net.Addr)
}

func DefaultConfig

func DefaultConfig() *Config

type Member

type Member struct {
	// contains filtered or unexported fields
}

func (Member) Addr

func (m Member) Addr() net.Addr

type Membership

type Membership struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) (*Membership, error)

func (*Membership) Join

func (ms *Membership) Join(ctx context.Context, existing ...string) error

func (*Membership) Leave

func (ms *Membership) Leave(ctx context.Context) error

func (*Membership) Me

func (ms *Membership) Me() Member

func (*Membership) Metrics

func (ms *Membership) Metrics() Metrics

func (*Membership) Stop

func (ms *Membership) Stop()

type Metrics

type Metrics struct {
	ActiveMembers        uint32
	SentNum, ReceivedNum uint32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL