In BFE configuration, a "product" could be composed of mulitple clusters. User can define how requests are routed among the clusters. Request routing is based on the content of HTTP request.
- 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 message with special header. This is routing rule in cluster level load balance.
- If multiple rules are configured, BFE would match the rules in sequece. Matching procedure stop if one rule is matched.
-
A product "demo", which needs process three kinds of traffic: static content traffic, "post" traffic, other traffic, then we can define threee clusters :
- demo-static:serve static content
- demo-post:serve post message
- demo-main: serve other trafic
-
To BFE configuration, following routing rules can be added:
- Rule 1: req_path_prefix_in("/static", false) -> demo-static, which means messages 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 message which use method "POST" and is prefixed with "/setting" will be routed to cluster "demo-post".
- Rule 3: default -> demo-main, which means all message which doesn't match above rules will be sent to cluster "demo-main".
-
In sub cluster level, load balance rules also can be configured. The rules define traffic weight which is distributed to each sub cluster。
-
A special virutal sub cluster "BLACKHOLE" could be used to discard traffic。
-
Consider following configuration:
- Two IDC:IDC1, IDC2
- Two BFE cluster:BFE1, BFE2
- Two backend sub cluster:sub-cluster-1, sub-cluster-2
-
In BFE cluster(BFE1 and BFE2):
- BFE1:{sub-cluster-1:w11,sub-cluster-2:w12, Blackhole:w1B}
- BFE2:{sub-cluster-1:w21,sub-cluster-2:w22, Blackhole:w2B}
-
Based on the weight in configuration, BFE distribute traffic to backend sub cluster.
- For exmaple,if weight configuration {w11, w12, w1B} ={45,45,10}, percent of traffic to sub cluster is sub-cluster-1, sub-cluster-2 and Blackhole is 45%, 45% and 10%.
- Usually, a sub cluster is composed of multiple instances. Within sub cluster, WRR(weighted round robin) is used to distribute message among instance。
- Instance can be assign diffrent weight based on its capacity。
BFE do health check for each backend instance. A instance has following two states:
- NORAML state:the instance act normally in processing message.
- CHECKING state:the instance is abnormal and can't process message. BFE do health check periodically in this state.
State switch:
-
NORAML to CHECKING, when:
- Consecutive failure, in connecting or sending message to the instance, exceed a threshhod.
-
CHECKING to NORMAL, when:
- BFE receive correct response from backend instance for health check request.
If message routing fail, BFE support retry the message in two levels:
- Re-route message within same sub cluster.
- Re-route message to other sub cluster.
TCP connection between BFE and backend instance support:
-
short-lived connection:BFE route each request message to backend server with a new established TCP connection.
-
connection pool:
-
BFE maintain connection pool to instances.
-
To an incoming request:
- if there is an avaiable connection, reuse it.
- else establish a new TCP connection.
-
After finish processing a request via a connection:
- If current size of connection pool is less than configured number, the connection is added into the pool.
- Else close the connection directly.
-
BFE support session stickiness based on following identity of request message:
- Source IP
- Field in reuqest header, cookie etc.
Keep session in different routing level:
- Sub cluster level: message of a session is sent to same sub cluster (may be different instance in this sub cluster).
- Instance level: message of a session is sent to same instance.