/// <summary> /// 获取快照权重的列表 /// </summary> /// <returns></returns> static List <int> GetSnapWeightList() { List <int> snapWeightList = new List <int>(); foreach (DbSnapInfo dbSnapInfo in DbSnapConfigs.GetEnableSnapList()) { snapWeightList.Add(dbSnapInfo.Weight); } return(snapWeightList); }
public DbSnapInfo GetConnectDbSnap() { lock (lockHelper) { if (curentSnapIndex >= DbSnapConfigs.GetEnableSnapList().Count) { curentSnapIndex = (curentSnapIndex) % DbSnapConfigs.GetEnableSnapList().Count; } return(DbSnapConfigs.GetEnableSnapList()[curentSnapIndex++]); } }
/// <summary> /// 获取应用当前负载均衡调度算法下的快照链接信息 /// </summary> /// <returns></returns> public DbSnapInfo GetConnectDbSnap() { lock (lockHelper) { DbSnapInfo current = RoundRobinScheduling(); if (current != null) { return(current); } else { return(DbSnapConfigs.GetEnableSnapList()[0]); } } }
/// <summary> /// 权重轮询调度算法 /// </summary> static DbSnapInfo RoundRobinScheduling() { while (true) { curentSnapIndex = (curentSnapIndex + 1) % DbSnapConfigs.GetEnableSnapList().Count; if (curentSnapIndex == 0) { currentWeight = currentWeight - gcd; if (currentWeight <= 0) { currentWeight = maxWeight; if (currentWeight == 0) { return(null); } } } if (DbSnapConfigs.GetEnableSnapList()[curentSnapIndex].Weight >= currentWeight) { return(DbSnapConfigs.GetEnableSnapList()[curentSnapIndex]); } } }