Skip to content

Commit

Permalink
docs(lb): Add description of Alias Method (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
NX-Official authored Mar 14, 2024
1 parent d2ff623 commit 78113b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions content/en/docs/kitex/Tutorials/service-governance/loadbalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Kitex provides these LoadBalancers officially:
- WeightedRoundRobin
- InterleavedWeightedRoundRobin (kitex >= v0.7.0)
- WeightedRandom
- Alias Method(kitex >= v0.9.0)
- ConsistentHash
- Tagging Based

Expand Down Expand Up @@ -56,6 +57,17 @@ If all instances have the same weights, it uses a purely random implementation t
```go
cli, err := echo.NewClient("echo", client.WithLoadBalancer(loadbalance.NewWeightedRandomBalancer()))
```

## Alias Method

LoadBalancer that uses the Alias Method, specifically implementing Vose's Alias Method from [Darts, Dice, and Coins](https://www.keithschwarz.com/darts-dice-coins/).

Generates an alias table in O(n) time, then selects an instance in O(1) time, achieving higher selection efficiency than [WeightedRandom](#weightedrandom).

```go
cli, err := echo.NewClient("echo", client.WithLoadBalancer(loadbalance.NewWeightedRandomWithAliasMethodBalancer()))
```

## ConsistentHash

### Introduction
Expand Down
12 changes: 12 additions & 0 deletions content/zh/docs/kitex/Tutorials/service-governance/loadbalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Kitex 默认提供了以下几种 LoadBalancer:
- WeightedRoundRobin
- InterleavedWeightedRoundRobin(kitex >= v0.7.0)
- WeightedRandom
- Alias Method(kitex >= v0.9.0)
- ConsistentHash
- Tagging Based

Expand Down Expand Up @@ -57,6 +58,17 @@ cli, err := echo.NewClient("echo", client.WithLoadBalancer(loadbalance.NewInterl
cli, err := echo.NewClient("echo", client.WithLoadBalancer(loadbalance.NewWeightedRandomBalancer()))
```

## Alias Method

使用别名方法的 LoadBalancer ,具体来说实现的是 [Darts, Dice, and Coins](https://www.keithschwarz.com/darts-dice-coins/) 中的 Vose's Alias Method

使用 O(n) 时间生成别名表,之后在 O(1) 时间内选取实例,选取效率比 [WeightedRandom](#weightedrandom) 更高

```go
cli, err := echo.NewClient("echo", client.WithLoadBalancer(loadbalance.NewWeightedRandomWithAliasMethodBalancer()))
```


## ConsistentHash

### 简介
Expand Down

0 comments on commit 78113b8

Please sign in to comment.