Skip to content

Commit

Permalink
Update docs on NS tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesge committed Sep 17, 2018
1 parent 49d05dc commit 74abadb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions docs/cn/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,18 @@ BNS是百度内常用的命名服务,比如bns://rdev.matrix.all,其中"bns"
用户可以通过实现brpc::NamingService来对接更多命名服务,具体见[这里](https://github.com/brpc/brpc/blob/master/docs/cn/load_balancing.md#%E5%91%BD%E5%90%8D%E6%9C%8D%E5%8A%A1)

### 命名服务中的tag
tag的用途主要是实现“粗粒度的wrr”,当给同一个地址加上不同的tag后,它们会被认为是不同的实例,从而让那个地址被负载均衡器正比与不同tag个数的流量。不过,你应当优先考虑使用[wrr算法](#wrr),相比使用tag可以实现更加精细的按权重分流。
每个地址可以附带一个tag,在常见的命名服务中,如果地址后有空格,则空格之后的内容均为tag。
相同的地址配合不同的tag被认为是不同的实例,brpc会建立不同的连接。用户可利用这个特性更灵活地控制与单个地址的连接方式。
如果你需要"带权重的轮询",你应当优先考虑使用[wrr算法](#wrr),而不是用tag来模拟。

### VIP相关的问题
VIP一般是4层负载均衡器的公网ip,背后有多个RS。当客户端连接至VIP时,VIP会选择一个RS建立连接,当客户端连接断开时,VIP也会断开与对应RS的连接。

如果客户端只与VIP建立一个连接(brpc中的单连接),那么来自这个客户端的所有流量都会落到一台RS上。如果客户端的数量非常多,至少在集群的角度,所有的RS还是会分到足够多的连接,从而基本均衡。但如果客户端的数量不多,或客户端的负载差异很大,那么可能在个别RS上出现热点。另一个问题是当有多个vip可选时,客户端分给它们的流量与各自后面的RS数量可能不一致。
如果客户端只与VIP建立一个连接(brpc中的单连接),那么来自这个客户端的所有流量都会落到一台RS上。如果客户端的数量非常多,至少在集群的角度,所有的RS还是会分到足够多的连接,从而基本均衡。但如果客户端的数量不多,或客户端的负载差异很大,那么可能在个别RS上出现热点。另一个问题是当有多个VIP可选时,客户端分给它们的流量与各自后面的RS数量可能不一致。

解决这个问题的一种方法是使用连接池模式(pooled),这样客户端对一个vip就可能建立多个连接(约为一段时间内的最大并发度),从而让负载落到多个RS上。如果有多个vip,可以用[wrr负载均衡](#wrr)给不同的vip声明不同的权重从而分到对应比例的流量,或给相同的vip后加上多个不同的tag而被认为是多个不同的实例
解决这个问题的一种方法是使用连接池模式(pooled),这样客户端对一个VIP就可能建立多个连接(约为一段时间内的最大并发度),从而让负载落到多个RS上。如果有多个VIP,可以用[wrr负载均衡](#wrr)给不同的VIP声明不同的权重从而分到对应比例的流量,或给相同的VIP后加上多个不同的tag而被认为是多个不同的实例

注意:在客户端使用单连接时,给相同的vip加上不同的tag确实能让这个vip分到更多的流量,但连接仍然只会有一个,这是由目前brpc实现决定的
如果对性能有更高的要求,或要限制大集群中连接的数量,可以使用单连接并给相同的VIP加上不同的tag以建立多个连接。相比连接池一般连接数量更小,系统调用开销更低,但如果tag不够多,仍可能出现RS热点

### 命名服务过滤器

Expand Down
6 changes: 4 additions & 2 deletions docs/en/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ If consul is not accessible, the naming service can be automatically downgraded
User can extend to more naming services by implementing brpc::NamingService, check [this link](https://github.com/brpc/brpc/blob/master/docs/cn/load_balancing.md#%E5%91%BD%E5%90%8D%E6%9C%8D%E5%8A%A1) for details.

### The tag in naming service
tag was used for implementing "coarse-grained wrr": different tags are appended to a same address to make different instances, such that the address gets traffic proportional to the number of different tags. However, you should consider using [wrr algorithm](#wrr) first which distributes traffic proportional to assigned weights and is more fine-grained.
Every address can be attached with a tag. The common implementation is that if there're spaces after the address, the content after the spaces is the tag.
Same address with different tag are treated as different instances which are interacted with separate connections. Users can use this feature to establish connections with remote servers in a more flexible way.
If you need weighted round-robin, you should consider using [wrr algorithm](#wrr) first rather than emulate "a coarse-grained version" with tags.

### VIP related issues
VIP is often the public IP of layer-4 load balancer, which proxies traffic to RS behide. When a client connects to the VIP, a connection is established to a chosen RS. When the client connection is broken, the connection to the RS is reset as well.
Expand All @@ -148,7 +150,7 @@ If one client establishes only one connection to the VIP("single" connection typ

One solution to these issues is to use "pooled" connection type, so that one client may create multiple connections to one VIP (roughly the max concurrency recently) to make traffic land on different RS. If more than one VIP are present, consider using [wrr load balancing](#wrr) to assign weights to different VIP, or add different tags to VIP to form more instances.

Note: When the client uses "single" connection type, even if one VIP appended with different tags can get more traffic, the connection is still one. This is decided by current implementation in brpc.
If higher performance is demanded, or number of connections is limited (in a large cluster), consider using single connection and attach same VIP with different tags to create different connections. Comparing to pooled connections, number of connections and overhead of syscalls are often lower, but if tags are not enough, RS hotspots may still present.

### Naming Service Filter

Expand Down

0 comments on commit 74abadb

Please sign in to comment.