/// <summary> /// Выбирает регион с максимальным весом очереди /// </summary> /// <param name="j">номер главного региона</param> /// <returns>регион с максимальным весом</returns> RBN MaxWeightRegion(int j) { ArrayList NotSleepRegions = new ArrayList(RegionsCount); for (int i = 0; i < RegionsCount; i++) { RBN rbn = (RBN)Regions[i]; if (!rbn.IsSleep()) { NotSleepRegions.Add(rbn); } } if (NotSleepRegions.Count > 0) { RBN maxWeight = (RBN)NotSleepRegions[0]; for (int i = 1; i < NotSleepRegions.Count; i++) { RBN rbn = (RBN)NotSleepRegions[i]; if (maxWeight.Weight_Compute(WeightComputeMode) < rbn.Weight_Compute(WeightComputeMode)) { maxWeight = rbn; } } return(maxWeight); } else { return(null); } }
/// <summary> /// Функция реализует работу без балансировщика /// </summary> void NotBalancedHandler() { for (int i = 0; i < RegionsCount; i++) { RBN rbn = (RBN)Regions[i]; rbn.Work(time); if (ThrottleCount == Throttle) { if (RIA != null) { RIA(rbn.Region_num, !rbn.IsSleep()); } if (QS != null) { QS(rbn.Region_num, rbn.GetQueueCount()); } if (QCS != null) { QCS(rbn.Region_num, rbn.TOTAL_QUERY_COUNT); } if (QWS != null) { QWS(rbn.Region_num, rbn.Weight_Compute()); } if (GR != null) { GR(GeneralRNBnum); } } } }
/// <summary> /// Функция реализует работу второго варианта централизованной балансировки /// </summary> void CentralizedHandlerType2() { NotBalancedHandler(); for (int i = 0; i < RegionsCount; i++) { RBN rbn = (RBN)Regions[i]; if (rbn.IsSleep()) { RBN another_rbn = MaxWeightRegion(i); if (another_rbn != null) { if (!rbn.QueueIsFull() && another_rbn.CanGetQuery()) { rbn.SetNewQuery(another_rbn.GetQueryFromQueue()); } } } SendAns(rbn); } }
/// <summary> /// Функция реализует работу децентрализованной балансировки /// c элементами централизованной /// </summary> void DeCentralizedHandlerType2() { NotBalancedHandler(); if (GeneralRegions()) { int[] dev = deviation_average_weight(compute_mean_weigth()); for (int i = 0; i < RegionsCount; i++) { RBN rbn_i = (RBN)Regions[i]; for (int j = 0; (j < RegionsCount); j++) { if (i != j) { RBN rbn_j = (RBN)Regions[j]; if (dev[i] > dev[j] && !rbn_j.QueueIsFull() && !rbn_i.QueueIsEmpty()) { rbn_j.SetNewQuery(rbn_i.GetLastQueryFromQueue()); } if (dev[i] < dev[j] && !rbn_i.QueueIsFull() && !rbn_j.QueueIsEmpty()) { rbn_i.SetNewQuery(rbn_j.GetLastQueryFromQueue()); } } } SendAns(rbn_i); } } for (int i = 0; i < RegionsCount; i++) { RBN rbn = (RBN)Regions[i]; if (rbn.IsSleep() && !GeneralRegions()) { rbn.general = true; } SendAns(rbn); } }