F5负载均衡算法及基本原理

原文:Intro to Load Balancing for Developers – The Algorithms

转载:http://blog.gesha.net/archives/205/

posted on Tuesday, March 31, 2009 11:02 PM

  • Random: This load balancing method randomly distributes load across the servers available, picking one via random number generation and sending the current connection to it. While it is available on many load balancing products, its usefulness is questionable except where uptime is concerned – and then only if you detect down machines.
  • 随机:此负载均衡算法在可用的服务器间随机分发请求,通过生成随机数随机挑选一台服务器,并将当前连接发给它。系统对需要进行负载均衡的服务器建立一个数组(array),使用随机数生成器来决定谁将获得下一个连接。

Plain Programmer Description:

The system builds an array of Servers being load balanced, and uses the random number generator to determine who gets the next connection… Far from an elegant solution, and most often found in large software packages that have thrown load balancing in as a feature.

  • Round Robin: Round Robin passes each new connection request to the next server in line, eventually distributing connections evenly across the array of machines being load balanced. Round Robin works well in most configurations, but could be better if the equipment that you are load balancing is not roughly equal in processing speed, connection speed, and/or memory.
  • 轮询:将请求依次顺序循环地分发给服务器,从1到N然后重新开始。此种均衡算法适合于服务器组中的所有服务器都有相同的软硬件配置并且平均服务请求相对均衡的情况。

Plain Programmer Description: 

The system builds a standard circular queue and walks through it, sending one request to each machine before getting to the start of the queue and doing it again. While I’ve never seen the code (or actual load balancer code for any of these for that matter), we’ve all written this queue with the modulus function before. In school if nowhere else.

  • Weighted Round Robin (called Ratio on the BIG-IP): With this method, the number of connections that each machine receives over time is proportionate to a ratio weight you define for each machine. This is an improvement over Round Robin because you can say “Machine 3 can handle 2x the load of machines 1 and 2”, and the load balancer will send two requests to machine #3 for each request to the others.
  • 权重:根据服务器的不同处理能力,给每个服 务器分配不同的权值,使其能够接受相应权值数的服务请求。例如:服务器A的权值被设计成1,B的权值是3,C的权值是6,则服务器A、B、C将分别接受到 10%、30%、60%的服务请求。此种均衡算法能确保高性能的服务器得到更多的使用率,避免低性能的服务器负载过重。

Plain Programmer Description: 

The simplest way to explain for this one is that the system makes multiple entries in the Round Robin circular queue for servers with larger ratios. So if you set ratios at 3:2:1:1 for your four servers, that’s what the queue would look like – 3 entries for the first server, two for the second, one each for the third and fourth. In this version, the weights are set when the load balancing is configured for your application and never change, so the system will just keep looping through that circular queue. Different vendors use different weighting systems – whole numbers, decimals that must total 1.0 (100%), etc. but this is an implementation detail, they all end up in a circular queue style layout with more entries for larger ratings.

  • Dynamic Round Robin (Called Dynamic Ratio on the BIG-IP): is similar to Weighted Round Robin, however, weights are based on continuous monitoring of the servers and are therefore continually changing. This is a dynamic load balancing method, distributing connections based on various aspects of real-time server performance analysis, such as the current number of connections per node or the fastest node response time. This Application Delivery Controller method is rarely available in a simple load balancer.
  • 动态比率:类似于权重,不过权重值是随着对服务器持续的监控而变化的。这是一个动态的负载均衡算法,基于对服务器性能的实时分析,如连接数或响应时间。

Plain Programmer Description:

If you think of Weighted Round Robin where the circular queue is rebuilt with new (dynamic) weights whenever it has been fully traversed, you’ll be dead-on.

  • Fastest: The Fastest method passes a new connection based on the fastest response time of all servers. This method may be particularly useful in environments where servers are distributed across different logical networks. On the BIG-IP, only servers that are active will be selected.
  • 最快模式:传递连接给那些响应速度最快的服务器。这种算法可能对于服务器处于不同的逻辑网络中的情况特别有用。均衡器记录着每个服务器的响应时间并选择最快的那一个。这非常直接了当,但是可能会导致拥塞,因为当前的响应时间并不一定真的还是1s或是2s了。
  • 解释一下:最快模式算法是基于未完成的七层请求数来计算的。请求被发送到一个成 员时,LTM将为它递增一个计数器,当请求被响应后,再对计数器递减。当LTM收到一个连接请求后,有最少的未完成请求的成员将被选择。如果VS没有关联 七层的Profile,LTM是不能追踪请求和回应的,负载均衡算法将“降级”为最小连接数模式。

Plain Programmer Description:

The load balancer looks at the response time of each attached server and chooses the one with the best response time. This is pretty straight-forward, but can lead to congestion because response time right now won’t necessarily be response time in 1 second or two seconds. Since connections are generally going through the load balancer, this algorithm is a lot easier to implement than you might think, as long as the numbers are kept up to date whenever a response comes through.

These next three I use the BIG-IP name for. They are variants of a generalized algorithm sometimes called Long Term Resource Monitoring.

  • Least Connections: With this method, the system passes a new connection to the server that has the least number of current connections. Least Connections methods work best in environments where the servers or other equipment you are load balancing have similar capabilities. This is a dynamic load balancing method, distributing connections based on various aspects of real-time server performance analysis, such as the current number of connections per node or the fastest node response time. This Application Delivery Controller method is rarely available in a simple load balancer.
  • 最小连接数:客户端的每一次请求服务在服务 器停留的时间可能会有较大的差异,随着工作时间加长,如果采用简单的轮循或随机均衡算法,每一台服务器上的连接进程可能会产生极大的不同,并没有达到真正 的负载均衡。最少连接数均衡算法对内部中需负载的每一台服务器都有一个数据记录,记录当前该服务器正在处理的连接数量,当有新的服务连接请求时,将把当前 请求分配给连接数最少的服务器,使均衡更加符合实际情况,负载更加均衡。此种均衡算法适合长时处理的请求服务,如FTP。
  • 但是,像Fastest一样,当连接时间不同时也可能导致拥塞——比如一个服务器正在处理简单的HTML页面,而另一个正在运行处理一堆数据库查询的JSP脚本,连接数就不太适合这种情况了。

Plain Programmer Description: 

This algorithm just keeps track of the number of connections attached to each server, and selects the one with the smallest number to receive the connection. Like fastest, this can cause congestion when the connections are all of different durations – like if one is loading a plain HTML page and another is running a JSP with a ton of database lookups. Connection counting just doesn’t account for that scenario very well.

  • Observed: The Observed method uses a combination of the logic used in the Least Connections and Fastest algorithms to load balance connections to servers being load-balanced. With this method, servers are ranked based on a combination of the number of current connections and the response time. Servers that have a better balance of fewest connections and fastest response time receive a greater proportion of the connections. This Application Delivery Controller method is rarely available in a simple load balancer.
  • 观察模式:以连接数和响应时间这两项的最佳平衡为依据来为新的请求选择服务器。

Plain Programmer Description: 

This algorithm tries to merge Fastest and Least Connections, which does make it more appealing than either one of the above than alone. In this case, an array is built with the information indicated (how weighting is done will vary, and I don’t know even for F5, let alone our competitors), and the element with the highest value is chosen to receive the connection. This somewhat counters the weaknesses of both of the original algorithms, but does not account for when a server is about to be overloaded – like when three requests to that query-heavy JSP have just been submitted, but not yet hit the heavy work.

  • Predictive: The Predictive method uses the ranking method used by the Observed method, however, with the Predictive method, the system analyzes the trend of the ranking over time, determining whether a servers performance is currently improving or declining. The servers in the specified pool with better performance rankings that are currently improving, rather than declining, receive a higher proportion of the connections. The Predictive methods work well in any environment. This Application Delivery Controller method is rarely available in a simple load balancer.
  • 预测模式:预测模式使用和观察模式一样的评 选方法,只不过BIGIP会利用收集到的服务器当前的性能指标(连接数和响应时间),进行预测分析,选择一台服务器在下一个时间片内,其性能将达到最佳的 服务器来响应用户的请求。预测模式试图修复在观察模式中的一个问题,如果服务器的响应时间已经开始下滑,那么它是不太可能接受下一个请求的。

Plain Programmer Description: 

This method attempts to fix the one problem with Observed by watching what is happening with the server. If its response time has started going down, it is less likely to receive the packet. Again, no idea what the weightings are, but an array is built and the most desirable is chosen.

You can see with some of these algorithms that persistent connections
would cause problems. Like Round Robin, if the connections persist to a
server for as long as the user session is working, some servers will
build a backlog of persistent connections that slow their response time.
The Long Term Resource Monitoring algorithms are the best choice if you
have a significant number of persistent connections. Fastest works okay
in this scenario also if you don’t have access to any of the dynamic
solutions.

你可以看到,有些算法遇到长连接可能会导致问题。像是轮询,如果长连接保持用户会话那么
久,当连接数积压到一定值时会导致服务器响应时间变慢。如果你有大量的长连接,LTRM( Long Term Resource Monitoring
)算法是最好的选择。如果没有动态的解决方案,Fastest算法也比较适合这种场景。

That’s it for this week, next week we’ll start talking specifically
about Application Delivery Controllers and what they offer – which is a
whole lot – that can help your application in a variety of ways.

Until then!

Don.

时间: 2024-08-27 10:44:00

F5负载均衡算法及基本原理的相关文章

几种简单的负载均衡算法及其Java代码实现

什么是负载均衡 负载均衡,英文名称为Load Balance,指由多台服务器以对称的方式组成一个服务器集合,每台服务器都具有等价的地位,都可以单独对外提供服务而无须其他服务器的辅助.通过某种负载分担技术,将外部发送来的请求均匀分配到对称结构中的某一台服务器上,而接收到请求的服务器独立地回应客户的请求.负载均衡能够平均分配客户请求到服务器阵列,借此提供快速获取重要数据,解决大量并发访问服务问题,这种集群技术可以用最少的投资获得接近于大型主机的性能. 负载均衡分为软件负载均衡和硬件负载均衡,前者的代

F5负载均衡及会话保持学习笔记一

在公司内部项目中经常用到F5,但由于对于F5实现负载均衡原理不是很清晰,在项目实战中遇到很多问题.比如:一个会话连接无故被中断,设置会话保持后,后端应用节点出现严重不均衡情况等等,所以特意回顾和整理了有关F5的相关技术资料,对于后续大家选择合适的负载均衡策略和会话保持方式提供参考依据,以免后续走弯路. 一:什么是F5? F5为一家公司,英文公司名:F5 Networks:应用交付网络(ADN)的全球领导者.F5提供的解决方案保证每个用户的应用实现安全.高速和高可用,帮企业获得最大投资回报.本文只

[转]f5负载均衡原理

f5负载均衡原理 一. 负载均衡技术 负载均衡技术在现有网络结构之上提供了一种廉价.有效.透明的方法,来扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性. 1. 负载均衡发生的流程图: 1. 客户发出服务请求到VIP 2.BIGIP接收到请求,将数据包中目的IP地址改为选中的后台服务器IP地址,然后将数据包发出到后台选定的服务器 3. 后台服务器收到后,将应答包按照其路由发回到BIGIP 4.BIGIP收到应答包后将其中的源地址改回成VIP的地址,发回客户端

spring-cloud-starter-ribbon提供客户端的软件负载均衡算法

Ribbon是什么? Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法,将Netflix的中间层服务连接在一起.Ribbon客户端组件提供一系列完善的配置项如连接超时,重试等.简单的说,就是在配置文件中列出Load Balancer(简称LB)后面所有的机器,Ribbon会自动的帮助你基于某种规则(如简单轮询,随即连接等)去连接这些机器.我们也很容易使用Ribbon实现自定义的负载均衡算法. LB方案分类 目前主流的LB方案可分成两类:一种是集中式LB, 即在服

互联网研发中负载均衡算法一点探索

负载均衡在线上服务中有着很重要作用,因为一台web服务比如tomcat,能够处理qps(每秒处理请求数) 是有限的.那么就需要有有前端负载均衡服务将大的流量分发为多个后端服务进行处理. 负载均衡产品有硬件F5.有软件,早之前使用Apache较多,目前是使用Nginx多,Nginx架构实现简洁优 雅性能高.LVS.HAProxy是著名软负载工具.说到LVS是由原淘宝章文蒿(目前在滴滴公司)博士领导开发, 是到目前为止Linux内核中网络核心部分,也是国人开Linux内核最高贡献,章博士在国内技术圈

Citrix Netscaler负载均衡算法

众所周知,作为新一代应用交付产品的Citrix Netscaler具有业内领先的数据控制.应用交付的能力,然而作为根本内容之一的ADC功能,如果不具备强大的.多元化的均衡算法是不可能适应如此众多的应用场景,更无法做到好的应用交付产品.因此我们在此讨论一下比较常用的负载均衡算法就很有必要. 目前最新版本的Netscaler支持17种均衡算法,目前先讨论最常用的12种 1.轮询算法(Round Robin) 当NetScaler 使用轮询的负载均衡算法时,它会将来自客户端的请求轮流分配给后台中的服务

劳动节配置F5负载均衡配置小结

2014年5月1日是劳动节,是劳动人民应该休息的节日,呵呵结果这几天却是作死的节奏,天天加班到2点半,真实很辛苦呀,整个过程很艰辛但是结果是好的. 1.配置LC1600链路负载均衡,首先要激活license的.在system-license-Re activacte 2.要创建VLAN,由于是联通线路.电信线路和下行线路,就创建vlan_cnc vlan_ctc vlan1,每个vlan要设置对应的端口,比如vlan_cnc对应光纤口2.1 3.创建完vlan 要写selfip即每个vlan的地

负载均衡算法及手段

负载均衡器 可以是专用设备,也可以是在通用服务器上运行的应用程序. 分散请求到拥有相同内容或提供相同服务的服务器. 专用设备一般只有以太网接口,可以说是多层交换机的一种. 负载均衡器一般会被分配虚拟IP地址,所有来自客户端的请求都是针对虚拟IP地址完成的.负载均衡器通过负载均衡算法将来自客户端的请求转发到服务器的实际IP地址上. 负载均衡算法 private Map<String,Integer> serverMap = new HashMap<String,Integer>(){

F5负载均衡名词LTM和GTM

LTM就是本地流量管理,也就是通常所说的服务器负载均衡.可以将多个提供相同服务的设备(pool)虚拟成一个逻辑设备,供用户访问.也就是说,对于用 户来讲,看到的只有一个设备,而实际上用户是服务请求是在多个设备之间,通过负载均衡算法分担的.通常可以理解为是一种代理的模式. LTM负责内网的负载均衡,比如一个用户访问进来,由LTM负责具体分配到哪个服务器来处理. GTM是广域网流量管理,也可以称为全局负载均衡.这个模块可以满足用户更高的负载均衡要求,提供不同站点间全局资源的调配.比如说,用户在北京和