博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
负载均衡算法(二)加权轮询负载均衡算法
阅读量:7218 次
发布时间:2019-06-29

本文共 1377 字,大约阅读时间需要 4 分钟。

///     /// 加权轮询算法    ///     public static class WeightRoundRobin    {        private static object obj = new object();        private static int pos = 0;        static Dictionary
dic = new Dictionary
{ { "192.168.1.12", 1}, {
"192.168.1.13", 1 }, { "192.168.1.14", 3}, { "192.168.1.15", 1}, {
"192.168.1.16", 1}, {
"192.168.1.17", 1 }, { "192.168.1.18", 1}, { "192.168.1.19", 1} }; public static string roundRobin() { //獲取ip列表list List
it = dic.Keys.ToList(); List
serverList = new List
(); foreach (var item in it) { int weight = 0; dic.TryGetValue(item, out weight); for (int i = 0; i < weight; i++) { serverList.Add(item); } } string server = null; lock (obj) { if (pos >= serverList.Count) { pos = 0; } server = serverList[pos]; pos++; } return server; } }

 

转载于:https://www.cnblogs.com/liyangLife/p/5729386.html

你可能感兴趣的文章
Algernon's Noxious Emissions POJ1121 zoj1052
查看>>
iOS-数据持久化-对象归档
查看>>
iOS开发UI篇—程序启动原理和UIApplication
查看>>
MUI 里js动态添加数字输入框后,增加、减少按钮无效
查看>>
python pip 更换国内安装源(windows)
查看>>
结对编程2后篇
查看>>
oracle exp 和 imp 数据和表结构互相独立导出导入
查看>>
iphone-common-codes-ccteam源代码 CCNSPredicate.m
查看>>
这次项目中应该注意的问题和应该保持的好习惯
查看>>
python-数据结构化与保存
查看>>
LeetCode - 551. Student Attendance Record I
查看>>
Java用户线程和守护线程
查看>>
ClassLoader类加载机制&&JVM内存管理
查看>>
Caml语句 查询分配给当前用户及当前组
查看>>
记一次源码分析
查看>>
php版本引起的const问题
查看>>
js实现60s倒计时效果
查看>>
【POJ 2176】Folding
查看>>
redis的过期策略以及内存淘汰机制
查看>>
阿牛的EOF牛肉串
查看>>