replicount

package
v1.76.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 5 Imported by: 0

README

This is open-sourced in 2024, but was developed long ago, and is quite aged technology.
Initially developed as a demonstrator for an idea of reverse cluster discovery, it found
its use as a counter of cluster replicas.

Isn't applicable if there are sticky sessions/connections.

The algorithm is this:

    We have two TTL caches, slow mode cache and fast mode cache.

    SLOW MODE (initial):
        - Initially we think there is one replica, and, for example, the polling period is 30s,
            the TTL and fast mode period are x2 of poll period, fast mode speed is x20.
        - We make a first call, and immediatelly discover the new replica and switch to fast mode.
        - In slow mode we can not report result at all, because it is already reported while in
            the fast mode.

    FAST MODE:
        - We have TTL x20 shorter, i.e. the 3s, and a poll period would be 1.5s initially.
        - We can report the result every 3s, and on every report recalculate the poll period.
            For example, on first recalc we'd have 2 replicas, and poll period becomes 0.75s,
            on second recalc - 3 repl and 0.5s period, then - 5 repl and 0.3s, and so on.
            The reported number of replicas would grow fast and smooth.
        - If we have had replicas already, then on their mass replacement will happen a smooth
            displacement of old ones with new ones, new ones will be added, old ones will expire
            by TTL, and the reporten number will be stable.
        - If for the fast mode period there were added no new replicas, then we switch back to slow mode.
            The slow mode cache must be already filled with new replicas.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Id

func Id() (id string)

Types

type ChangeableObject

type ChangeableObject struct {
	NumberOfReplicas int
	ListOfReplicas   []string
}

type DataContainer

type DataContainer struct {
	ChangeableObject *ChangeableObject
}

must be inited by user, and passed to consumers of this data

type Monitoring added in v1.36.0

type Monitoring struct {
	State int
}

type PollFunc

type PollFunc func() (idPtr *string)

type Replicount

type Replicount struct {
	SlowPollPeriodPerReplica time.Duration // basic period, per-replica, in slow mode
	TTLMultiple              int           // multiple of basic poll period; also the TTL of slow mode cache
	FastModeSpeedMultiple    int           // relative to basic poll period
	PollFunc                 PollFunc
	ReportResultsFunc        func(newResult *ChangeableObject)
	LogFunc                  func(string)
	MonitoringFunc           func(*Monitoring)
	Context                  context.Context

	DQF     chan func(r *Replicount)
	DQF_Len int
	// contains filtered or unexported fields
}

func New

func New(of ...func(r *Replicount)) (r *Replicount)

Jump to

Keyboard shortcuts

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