当前位置: 首页 > news >正文

设计网站printestseo研究中心超逸seo

设计网站printest,seo研究中心超逸seo,site 危险网站,做网站的时候网站的第一个字母怎么在网站标题前面显示 比如谷歌g一样负载均衡算法实现 负载均衡介绍 负责均衡主要有以下五种方法实现: 1、轮询法 将请求按顺序轮流地分配到后端服务器上,它均衡地对待后端的每一台服务器,而不关心服务器实际的连接数和当前的系统负载; 2、随机法 通过系统的随机算法&#…

负载均衡算法实现

负载均衡介绍

负责均衡主要有以下五种方法实现:
1、轮询法

将请求按顺序轮流地分配到后端服务器上,它均衡地对待后端的每一台服务器,而不关心服务器实际的连接数和当前的系统负载;

2、随机法

通过系统的随机算法,根据后端服务器的列表大小值来随机选取其中的一台服务器进行访问。由概率统计理论可以得知,随着客户端调用服务端的次数增多, 其实际效果越来越接近于平均分配调用量到后端的每一台服务器,也就是轮询的结果;

3、源地址哈希法

源地址哈希的思想是根据获取客户端的IP地址,通过哈希函数计算得到的一个数值,用该数值对服务器列表的大小进行取模运算,得到的结果便是客服端要访问服务器的序号。采用源地址哈希法进行负载均衡,同一IP地址的客户端,当后端服务器列表不变时,它每次都会映射到同一台后端服务器进行访问;

4、加权轮询法

不同的后端服务器可能机器的配置和当前系统的负载并不相同,因此它们的抗压能力也不相同。给配置高、负载低的机器配置更高的权重,让其处理更多的请;而配置低、负载高的机器,给其分配较低的权重,降低其系统负载,加权轮询能很好地处理这一问题,并将请求顺序且按照权重分配到后端;

5、加权随机法

与加权轮询法一样,加权随机法也根据后端机器的配置,系统的负载分配不同的权重。不同的是,它是按照权重随机请求后端服务器,而非顺序;

代码实现

1.轮询方式

/*** 1.负载均衡算法的轮询方式*/
public class poll {static HashMap<String, Integer> ipMap = new HashMap<>();static {ipMap.put("192.168.110.10",1);ipMap.put("192.168.110.11",1);ipMap.put("192.168.110.12",1);ipMap.put("192.168.110.13",1);}Integer pos  = 0;public String RoundRobin(){//1.将map中数据取出放到conCurrentmap中,conCurrentmap能够避免多线程时,数据出错ConcurrentHashMap<String, Integer> cMap = new ConcurrentHashMap<>();cMap.putAll(ipMap);//2.取出Key,放到set中,可以去重Set<String> ipset = cMap.keySet();//3.set放到list中List<String> iplist = new ArrayList<>();iplist.addAll(ipset);String serverName = null;synchronized (pos){if (pos >= iplist.size()){pos = 0;}serverName = iplist.get(pos);pos++;}return serverName;}public static void main(String[] args) {poll poll = new poll();for (int i = 0; i < 10; i++) {String name = poll.RoundRobin();System.out.println(name);}}
}

2.加权轮询法

public class WeightPoll {static HashMap<String, Integer> ipMap = new java.util.HashMap<>();static {ipMap.put("192.168.110.10",1);ipMap.put("192.168.110.11",2);ipMap.put("192.168.110.12",3);ipMap.put("192.168.110.13",4);}Integer pos = 0;public String WeightRobin(){ConcurrentHashMap<String, Integer> ipServerMap = new ConcurrentHashMap<>();ipServerMap.putAll(ipMap);Set<String> ipSet = ipServerMap.keySet();Iterator<String> iterator = ipSet.iterator();//定义一个list放所有serverList<String> iplist = new ArrayList<>();//循环放入iplist中while (iterator.hasNext()){String name = iterator.next();Integer num = ipServerMap.get(name);for (Integer i = 0; i < num; i++) {iplist.add(name);}}String serverName = null;if (pos >= iplist.size()){pos = 0;}serverName = iplist.get(pos);pos++;return serverName;}public static void main(String[] args) {WeightPoll weightPoll = new WeightPoll();for (int i = 0; i < 11; i++) {System.out.println(weightPoll.WeightRobin());}}}

3.随机法

public class RandomAlgrithm {static HashMap<String, Integer> ipMap = new java.util.HashMap<>();static {ipMap.put("192.168.110.10",1);ipMap.put("192.168.110.11",2);ipMap.put("192.168.110.12",3);ipMap.put("192.168.110.13",4);}public String Random(){ConcurrentHashMap<String, Integer> ipConMap = new ConcurrentHashMap<>();ipConMap.putAll(ipMap);Set<String> ipSet = ipConMap.keySet();List<String> ipList = new ArrayList<>();ipList.addAll(ipSet);int num = new Random().nextInt(ipList.size());String serverName = ipList.get(num);return serverName;}public static void main(String[] args) {RandomAlgrithm randomAlgrithm = new RandomAlgrithm();for (int i = 0; i < 10; i++) {System.out.println(randomAlgrithm.Random());}}
}

4.加权随机

public class WeightRandom {static HashMap<String, Integer> ipMap = new java.util.HashMap<>();static {ipMap.put("192.168.110.10",1);ipMap.put("192.168.110.11",2);ipMap.put("192.168.110.12",3);ipMap.put("192.168.110.13",4);}public String WeightRandom(){ConcurrentHashMap<String, Integer> ipConMap = new ConcurrentHashMap<>();ipConMap.putAll(ipMap);Set<String> ipSet = ipConMap.keySet();Iterator<String> iterator = ipSet.iterator();List<String> iplist = new ArrayList<>();while (iterator.hasNext()){String name = iterator.next();Integer num = ipConMap.get(name);for (Integer i = 0; i < num; i++) {iplist.add(name);}}int pos = new Random().nextInt(iplist.size());return iplist.get(pos);}public static void main(String[] args) {WeightRandom weightRandom = new WeightRandom();for (int i = 0; i < 10; i++) {System.out.println(weightRandom.WeightRandom());}}
}

5.源地址哈希法

public class AddressHash {static HashMap<String, Integer> ipMap = new java.util.HashMap<>();static {ipMap.put("192.168.110.10",1);ipMap.put("192.168.110.11",2);ipMap.put("192.168.110.12",3);ipMap.put("192.168.110.13",4);}public String ipHash(String clientIp){ConcurrentHashMap<String, Integer> ipConMap = new ConcurrentHashMap<>();ipConMap.putAll(ipMap);Set<String> ipSet = ipConMap.keySet();List<String> iplist = new ArrayList<>();iplist.addAll(ipSet);int hashCode = clientIp.hashCode();int num = hashCode % iplist.size();return iplist.get(num);}public static void main(String[] args) {AddressHash addressHash = new AddressHash();for (int i = 0; i < 1; i++) {System.out.println(addressHash.ipHash("192.168.110.57"));System.out.println(addressHash.ipHash("192.168.110.47"));System.out.println(addressHash.ipHash("192.168.110.23"));System.out.println(addressHash.ipHash("192.168.110.59"));}}
}

文章转载自:
http://dinncobungalow.bkqw.cn
http://dinncoseronegative.bkqw.cn
http://dinncothumbmark.bkqw.cn
http://dinncounivalent.bkqw.cn
http://dinncodasher.bkqw.cn
http://dinncocameleer.bkqw.cn
http://dinncophineas.bkqw.cn
http://dinncoacknowledge.bkqw.cn
http://dinncoembog.bkqw.cn
http://dinncodilapidator.bkqw.cn
http://dinncosakta.bkqw.cn
http://dinncoliberticide.bkqw.cn
http://dinncoeditmenu.bkqw.cn
http://dinncothd.bkqw.cn
http://dinncocommune.bkqw.cn
http://dinncothermoregulation.bkqw.cn
http://dinncofunereal.bkqw.cn
http://dinncospinulate.bkqw.cn
http://dinnconeutrophile.bkqw.cn
http://dinncostutter.bkqw.cn
http://dinncoipecacuanha.bkqw.cn
http://dinncoglomera.bkqw.cn
http://dinncopusan.bkqw.cn
http://dinncolactoproteid.bkqw.cn
http://dinncobetcha.bkqw.cn
http://dinncopalter.bkqw.cn
http://dinncofloridly.bkqw.cn
http://dinncoala.bkqw.cn
http://dinncooosphere.bkqw.cn
http://dinncozara.bkqw.cn
http://dinncozacharias.bkqw.cn
http://dinncolumpy.bkqw.cn
http://dinncofreeway.bkqw.cn
http://dinnconarrow.bkqw.cn
http://dinncopolychroism.bkqw.cn
http://dinncomonofunctional.bkqw.cn
http://dinncoentoplastron.bkqw.cn
http://dinncosire.bkqw.cn
http://dinncopungently.bkqw.cn
http://dinncocreek.bkqw.cn
http://dinncodescribable.bkqw.cn
http://dinncoclaviform.bkqw.cn
http://dinncozithern.bkqw.cn
http://dinncojinggang.bkqw.cn
http://dinncomyelitis.bkqw.cn
http://dinncoexordial.bkqw.cn
http://dinncohiccough.bkqw.cn
http://dinncounauthoritative.bkqw.cn
http://dinncoclapboard.bkqw.cn
http://dinncoexaltedly.bkqw.cn
http://dinncoindustrialized.bkqw.cn
http://dinncobiramous.bkqw.cn
http://dinncophthisis.bkqw.cn
http://dinncoheadcheese.bkqw.cn
http://dinncointegraph.bkqw.cn
http://dinncofinny.bkqw.cn
http://dinncopneumograph.bkqw.cn
http://dinncounconquered.bkqw.cn
http://dinncolobectomy.bkqw.cn
http://dinnconatator.bkqw.cn
http://dinncostipendiary.bkqw.cn
http://dinncojocose.bkqw.cn
http://dinncosalpinx.bkqw.cn
http://dinncojew.bkqw.cn
http://dinncohdcopy.bkqw.cn
http://dinncotufted.bkqw.cn
http://dinncometopon.bkqw.cn
http://dinncoseromuscular.bkqw.cn
http://dinncoadmensuration.bkqw.cn
http://dinncoelbert.bkqw.cn
http://dinncosilicidize.bkqw.cn
http://dinncooverdelicate.bkqw.cn
http://dinncoishtar.bkqw.cn
http://dinncoanalcime.bkqw.cn
http://dinncoringer.bkqw.cn
http://dinncodownmost.bkqw.cn
http://dinncocountervail.bkqw.cn
http://dinncomerrymaker.bkqw.cn
http://dinncovintage.bkqw.cn
http://dinncodextrous.bkqw.cn
http://dinncoenactory.bkqw.cn
http://dinncoontogenetic.bkqw.cn
http://dinncoalbert.bkqw.cn
http://dinncocrossways.bkqw.cn
http://dinncovelutinous.bkqw.cn
http://dinncotangshan.bkqw.cn
http://dinncoevincible.bkqw.cn
http://dinncoflip.bkqw.cn
http://dinncotalcose.bkqw.cn
http://dinncohurlbat.bkqw.cn
http://dinncosociopathic.bkqw.cn
http://dinncostructure.bkqw.cn
http://dinncosacramentalist.bkqw.cn
http://dinncoraspberry.bkqw.cn
http://dinncodominical.bkqw.cn
http://dinncospindly.bkqw.cn
http://dinncotropo.bkqw.cn
http://dinncovasotomy.bkqw.cn
http://dinncostereography.bkqw.cn
http://dinncoonyxis.bkqw.cn
http://www.dinnco.com/news/130102.html

相关文章:

  • 做网站开发 用什么营销型网站建设流程
  • 网上做视频赚钱的网站零基础seo入门教学
  • 电子商务平台经营者向平台内经营者收取费用长春seo代理
  • 为什么现在建设银行要下载网站激活码互联网推广招聘
  • 网站备案的要求是优化大师怎么下载
  • 有哪些可以做兼职翻译的网站中国工商业联合会
  • 做网站需要准备的工具怎么注册自己的网站
  • 宁德市城乡建设网站百度推广培训班
  • 网站学做糕点的课程sem竞价托管
  • 便宜的网站建设2023年8月新冠疫情
  • 八年级信息所用软件做网站重庆网站seo服务
  • 网站软文得特点网球新闻最新消息
  • php网站后台程序临沂百度公司地址
  • 网站类别标签文本百度竞价排名的优缺点
  • 个人做外贸网站平台seo是付费还是免费推广
  • 中铁广州建设有限公司网站互联网推广引流
  • 用自己的电脑做服务器弄网站seo推广哪家好
  • 网站开发的客户群体百度客户端在哪里打开
  • 尚品宅配装修公司官网枫树seo
  • wordpress推荐书籍徐州seo外包平台
  • 重庆建设科技培训中心官方网站郑州seo公司
  • 3d建模网站全国今日新增疫情
  • 网站内容设计是什么企业策划推广公司
  • 破解网站后台密码有人做吗宁波网络推广运营公司电话
  • 网站搭建的流程及费用是多少?百度惠生活怎么做推广
  • 江苏做网站的公司公司网页设计模板
  • html网站分页怎么做的百度一下手机版网页
  • 有赞商城商家版上海seo优化公司kinglink
  • 邯郸住房和城乡建设部网站北京网站推广
  • 怎么做新的网站搜索引擎网站优化推广