负载均衡-Load balancer

    技术2022-07-14  79

    recruiter小姐姐把面试范围画了个重点,于是我来抱个佛脚。学习一下load balancer把流量分给各个server的原理和方法。

    什么是Load balancer

    efficiently distributing incoming network traffic across a group of backend servers,把流量高效地分配给后端server。

    基本职能:

    保证没有server overworked万一某个server down,分给其他的一个新的server添加进来,开始向他分流量

    Load balancer分类

    layer 4 网络/传输层layer 7 应用层简介通过虚拟IP+端口接收请求,然后再分配到真实的服务器通过虚拟的URL或主机名接收请求,然后再分配到真实的服务器协议IP, TCP, FTP, UDPHTTP实现方法1)DNS服务器2)硬件SDN3)软件下面几个算法sticky sessions: load balancer sets a cookie all of the requests from that session are directed to the same physical server

    两种类型的load balancers都接收requests, 并根据一个算法来决定该request分到哪个server上。 工业界常见的算法:

    Round robin: 顺序轮询Weighted round robinLeast connections:选有最少连接的那个serverLeast response time:选响应时间最短的那个Hash:根据hash value of client IP address或request URL决定 (a consistent hash to minimize redistribution of loads if the set of upstream servers changes)IP Hash: 根据hash value of client IP address决定哪个serverRandom with Two Choices:先随机选两个,再用其他算法二选一

    references

    https://www.f5.com/services/resources/glossary/load-balancer https://www.nginx.com/resources/glossary/load-balancing/

    Processed: 0.071, SQL: 9