forked from bfenetworks/bfe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize docs for load balance (bfenetworks#508)
- Loading branch information
1 parent
a639f90
commit c6290b9
Showing
6 changed files
with
123 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
# Request Routing | ||
|
||
In BFE configuration, a "product" could be composed of multiple clusters. User can define how requests are routed among the clusters. Request routing is based on the content of HTTP request. | ||
## Overview | ||
|
||
## Rule configuration | ||
- In BFE [forwarding model](./forward_model.md), after "product name" for one request is determined, the destionation cluster should be identified. | ||
- A Forwarding Table is provided for each product inside BFE. | ||
- For each request, the forwarding table for the determined product is searched, and destination cluster is identified. | ||
|
||
- Fields in HTTP Header is used to define routing rule for distributing traffic in cluster level, for example: | ||
- host, path, query, cookie, method, etc. | ||
- BFE provide a "Condition" expression to define how to route request with special header. This is routing rule in cluster level load balance. | ||
- If multiple rules are configured, BFE would match the rules in sequence. Matching procedure stop if one rule is matched. | ||
## Forwarding Table | ||
|
||
- Forwarding table is composed by one or more "forwarding rules". | ||
- Each forwarding rule has two parts: condition(for matching the request), destionation cluster. | ||
- Condition is expressed in [Condition Expression](../condition). | ||
- For a request, multiple rules in forwarding table are searched up to down.(i.e., the order of forwarding rules is very important.) The procedure will stop if some rule is matched. | ||
- There must be one Default Rule in the forwarding table. If no other rules is matched for a request, the destionation cluster defined in Default Rule is returned. | ||
|
||
## Example | ||
|
||
- A product "demo", which needs process three kinds of traffic: static content traffic, "post" traffic, other traffic, then we can define three clusters : | ||
## Example | ||
|
||
- A product "demo" has three clusters: | ||
- demo-static:serve static content | ||
- demo-post:serve post request | ||
- demo-main: serve other traffic | ||
|
||
- To BFE configuration, following routing rules can be added: | ||
- Rule 1: req_path_prefix_in("/static", false) -> demo-static, which means requests with path prefixed with "/static" will be routed to cluster demo-static. | ||
- Rule 2: req_method_in("POST")&&req_path_prefix_in("/setting",false) -> demo-post, which means that request which use method "POST" and is prefixed with "/setting" will be routed to cluster "demo-post". | ||
- Rule 3: default -> demo-main, which means all request which doesn't match above rules will be sent to cluster "demo-main". | ||
- The expected scenarios: | ||
- Requests with path prefixed with "/static" will be forwarded to cluster demo-static. | ||
- Request using method "POST" and prefixed with "/setting" will be forwarded to cluster "demo-post". | ||
- Other request will be forwarded to cluster "demo-main". | ||
|
||
- The corresponding forwarding table is shown as follows. | ||
|
||
![Forwarding Table](../../images/forwarding_table.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,35 @@ | ||
# 集群间分流 | ||
|
||
## 机制说明 | ||
- 集群间分流是指BFE收到请求,基于收到消息内容进行路由,确定由产品线中哪一个集群来处理消息。 | ||
|
||
## 示例场景 | ||
## 概述 | ||
|
||
- 对于一个产品线的流量,可能需要定义不同的集群来处理。例如,对产品线(demo),可以定义3种服务集群,实现对不同类型的流量的处理: | ||
- 在BFE的[接入转发流程](./forward_model.md)中,在确定产品线后,要进一步确定处理该请求的目标集群 | ||
- 在BFE内,为每个产品线维护一张“转发表” | ||
- 对每个属于该产品线的请求,查询转发表,获得目标集群 | ||
|
||
- 静态集群(demo-static):服务静态流量 | ||
- post集群(demo-post):服务post流量 | ||
- main集群(demo-main):服务其他流量 | ||
|
||
- BFE支持根据配置的分流规则, 将流量转发到以上不同的集群。 | ||
## 转发表 | ||
|
||
## 分流的配置方式 | ||
- 转发表由多条“转发规则”组成 | ||
- 每条转发规则包括两部分:匹配条件,目标集群 | ||
- 匹配条件使用“[条件表达式(Condition Expression)](../condition)”来表述 | ||
- 多条转发规则顺序执行。只要命中任何一条转发规则,就会结束退出 | ||
- 转发表必须包含“默认规则(Default)”。在所有转发规则都没有命中的时候,执行默认规则 | ||
|
||
- BFE基于请求内容进行条件判断,来决定分流 | ||
- 可以使用的信息包括:host,path, query,cookie,method等 | ||
- BFE提供了一个称为Condition的描述机制 | ||
## 示例 | ||
|
||
- 产品线demo,包含以下3种服务集群: | ||
+ 静态集群(demo-static):服务静态流量 | ||
+ post集群(demo-post):服务post流量 | ||
+ main集群(demo-main):服务其他流量 | ||
- 期望的转发条件如下: | ||
+ 对于path以"/static"为前缀的,都发往demo-static集群 | ||
+ 请求方法为"POST"、且path以"/setting"为前缀的,都发往demo-post | ||
+ 其它请求,都发往demo-main | ||
- 对应以上要求,产品线demo的转发表如下图所示 | ||
![Forwarding Table](../../images/forwarding_table.png) | ||
|
||
对于上面的例子,我们可以demo这个产品线创建了3条分流规则 | ||
|
||
- 第一条:对于path以"/static"作为前缀的,都发往demo-static | ||
|
||
- 第二条:请求方法为"POST"、并且path是以"/setting"为前缀的,都发往demo-post | ||
|
||
- 第三条:如果以上两条规则没有命中,则凡是这个产品的流量、都发往demo-main | ||
|
||
## 配置分流规则的注意事项 | ||
|
||
在配置一个产品线的分流规则时,需要注意以下事项: | ||
|
||
- 多条分流规则之间是有序的 | ||
|
||
- 对于一个HTTP请求,会按照从上至下的顺序,逐条去尝试匹配分流条件 | ||
- 只要命中任何一个分流规则的条件,就会结束 | ||
|
||
- 必须存在一个"default规则" | ||
|
||
- default规则永远处于规则列表的最后一条 | ||
- 如果其他分流规则都没有命中,则请求会发往default规则所指定的集群 |