shard

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

Shard selector

The Shard selector strategy should direct all requests for the given keys to a single node, or if that node is failing, a consistent second-choice etc.

It tries to consistently direct all requests for a given set of sharding keys to a single instance to improve caching memory efficiency.

Re-balancing requests

When a new node appears, it will get a fair share of requests randomly allocated from across the existing services as the new node will then be higher scoring for approximately 1/count(nodes) of the ids.

Similarly, when a node disappears, its load will get fairly redistributed amongst the existing remaining nodes.

Benefits

This benefits us in that memory can be more optimally used by trying to target requests that have support for caching to servers that are more likely to have that data already, whilst not requiring all servers to have all data for everything cached.

Over time, this results in overall memory savings where one is running multiple services, whist still allowing for fractional re-balancing with auto-scaling and unexpected node failure/replacement.

Usage

This method is a call option, which can be passed into client RPC requests.

Example

rsp, err := myClient.ClientCall(
    ctx,
    &ClientCallRequest{
    	//...
        SomeID: id,
    },
    shard.Strategy(id),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSelector

func NewSelector(keys []string) selector.SelectOption

NewSelector returns a `SelectOption` that directs all request according to the given `keys`.

func Next

func Next(keys []string, services []*registry.Service) selector.Next

Next returns a `Next` function which returns the next highest scoring node.

func ScoreNodes

func ScoreNodes(keys []string, services []*registry.Service) (possibleNodes []*registry.Node, scores []uint64)

ScoreNodes returns a score for each node found in the given services.

func Strategy

func Strategy(keys ...string) client.CallOption

Strategy returns a call option which tries to consistently direct all requests for a given set of keys to a single instance to improve memory efficiency where instances are caching data.

This is the preferred usage as it gives the ultimate flexibility for determining the keys used.

Usage:

`myClient.MyCall(ctx, req, shard.Strategy(req.ID))`

Types

This section is empty.

Jump to

Keyboard shortcuts

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