Пример #1
0
 public RunConfiguration(SimulationSize simulationSize,
                         StartUtilizationPercent startPercent,
                         LoadChangeAction changeAction,
                         LoadPrediction loadPrediction,
                         Strategies strategy,
                         AuctionTypes pushAuctionType, AuctionTypes pullAuctionType,
                         SchedulingAlgorithm schedulingAlgorithm,
                         TestedHosts testedHosts,
                         ContainersType containersType,
                         bool networkDealy,
                         int trialId)
 {
     LoadPrediction      = loadPrediction;
     SimulationSize      = simulationSize;
     StartPercent        = startPercent;
     Strategy            = strategy;
     PushAuctionType     = pushAuctionType;
     PullAuctionType     = pullAuctionType;
     SchedulingAlgorithm = schedulingAlgorithm;
     ChangeAction        = changeAction;
     TestedHosts         = testedHosts;
     ContainersType      = containersType;
     NetworkDealy        = networkDealy;
     TrialId             = trialId;
 }
Пример #2
0
 public ContainerFactory(ContainersType containertype, SimulationSize simulationSize, LoadPrediction predictionStrategy)
 {
     Containertype           = containertype;
     _simulationSize         = simulationSize;
     this.predictionStrategy = predictionStrategy;
     random = new Random(Guid.NewGuid().GetHashCode());
 }
        public void PredictionConstructedFromDictionaryTest()
        {
            var initDic = new Dictionary <byte, int[]>
            {
                {
                    (byte)FeedbackName.PeerCount, new[]
                    {
                        0, 104, 0,
                        1, 209, 104,
                        2, 314, 209,
                        3, 419, 314,
                        4, 524, 419,
                        5, 629, 524,
                        6, 734, 629,
                        7, 838, 734,
                        8, 943, 838,
                        9, int.MaxValue, 943
                    }
                }
            };
            var prediction         = new LoadPrediction(10, initDic);
            var loadStatsCollector = new LoadStatsCollector();

            TestBody(loadStatsCollector, prediction);
        }
Пример #4
0
 public HostLoadManager(int machineId, Load maxLoad, LoadPrediction loadPrediction, NetworkInterfaceCard networkCard, ContainerTable containerTable)
 {
     _maxLoad              = maxLoad;
     _networkCard          = networkCard;
     _osLoad               = new Load(maxLoad.CpuLoad * 0.01, 100, 0);
     _containerTable       = containerTable;
     MachineId             = machineId;
     CurrentLoadPrediction = loadPrediction;
 }
        public void FactorLessThanZeroTest()
        {
            var initDic = new Dictionary <byte, int[]>
            {
                {
                    (byte)FeedbackName.PeerCount, new[]
                    {
                        0, 104, 0,
                        1, 209, 104,
                        2, 314, 209,
                        3, 419, 314,
                        4, 524, 419,
                        5, 629, 524,
                        6, 734, 629,
                        7, 838, 734,
                        8, 943, 838,
                        9, int.MaxValue, 943
                    }
                }
            };
            var prediction         = new LoadPrediction(10, initDic);
            var loadStatsCollector = new LoadStatsCollector(0.8f);

            Dictionary <byte, int[]> updatedLevels;

            loadStatsCollector.UpdatePrediction(204, FeedbackLevel.Lowest, out updatedLevels);
            if (updatedLevels != null && updatedLevels.Count > 0)
            {
                prediction.UpdatePredictionLevels(updatedLevels);
                updatedLevels.Clear();
            }
            Assert.That(prediction.Output == FeedbackLevel.Lowest);

            prediction.SetPeerCount(185);
            Assert.That(prediction.Output == FeedbackLevel.Level1);

            prediction.SetPeerCount(183);
            Assert.That(prediction.Output == FeedbackLevel.Lowest);

            prediction.SetPeerCount(300);
            Assert.That(prediction.Output == FeedbackLevel.Level2);


            loadStatsCollector.UpdatePrediction(199, FeedbackLevel.Level2, out updatedLevels);
            if (updatedLevels != null && updatedLevels.Count > 0)
            {
                prediction.UpdatePredictionLevels(updatedLevels);
                updatedLevels.Clear();
            }

            prediction.SetPeerCount(200);
            Assert.That(prediction.Output == FeedbackLevel.Level1);

            prediction.SetPeerCount(202);
            Assert.That(prediction.Output == FeedbackLevel.Level2);
        }
Пример #6
0
 public HostFactory(Load hostLoad, NetworkSwitch networkSwitchObject,
                    LoadPrediction loadPrediction, Strategies currentStrategy,
                    ContainersType containerTypes, SimulationSize simulationSize) : base(networkSwitchObject)
 {
     this.hostLoad        = hostLoad;
     _networkSwitchObject = networkSwitchObject;
     this.loadPrediction  = loadPrediction;
     this.currentStrategy = currentStrategy;
     this.containerTypes  = containerTypes;
     this.simulationSize  = simulationSize;
 }
Пример #7
0
 public Container(int containerId, Load containerLoad, LoadPrediction currentLoadPrediction)
 {
     _calculator           = new CheckpointAndResotoreCalculator();
     ContainerId           = containerId;
     CurrentLoadPrediction = currentLoadPrediction;
     //ImageId = imageId;
     //MaxLoad = maxLoad;
     NeededLoad = new Load(containerLoad);
     Started    = true;
     StartPrediction();
     ContainerType = ContainersType.N;
 }
Пример #8
0
        private void SetStateAndLoadPrediction(IRegisterGameServer request, bool reconnect)
        {
            this.UpdateLoadLevel(null, request.LoadLevelCount, request.LoadIndex);

            if (!this.SetServerState((ServerState)request.ServerState))
            {
                this.application.LoadBalancer.TryUpdateServer(this, this.LoadLevel, this.LoadBalancerPriority, this.State);
            }

            if (CommonSettings.Default.UseLoadPrediction && request.PredictionData != null)
            {
                this.prediction = new LoadPrediction(request.LoadLevelCount, request.PredictionData);
            }
        }
Пример #9
0
        public HostMachine(int id,
                           Load maxLoad, NetworkSwitch networkSwitch,
                           LoadPrediction currentLoadPrediction, Strategies strategy,
                           ContainersType containerType,
                           SimulationSize simulationSize) : base(id, networkSwitch)
        {
            if (containerType == ContainersType.D)
            {
                _containerTable = new DockerContainerTable(id, new ImageManager(this.CommunicationModule));
            }
            else
            {
                _containerTable = new ContainerTable(id);
            }
            _loadManager = new HostLoadManager(this.MachineId, maxLoad, currentLoadPrediction, this.CommunicationModule, _containerTable);
            switch (strategy)
            {
            case Strategies.WAshraf2017Auction:
                _handler = new WAshrafHostHandlerModule(CommunicationModule, _containerTable, _loadManager);

                break;

            case Strategies.WAshraf2017:
                _handler = new WAshrafHostHandlerModule(CommunicationModule, _containerTable, _loadManager);

                break;

            case Strategies.Zhao:
                _handler = new ZhaoHostHandler(CommunicationModule, _containerTable, _loadManager, Global.CommonLoadManager);

                break;

            case Strategies.ForsmanPush:
                _handler = new ForsmanHostHandler(CommunicationModule, _containerTable, _loadManager, StrategyActionType.PushAction, simulationSize);

                break;

            case Strategies.ForsmanPull:
                _handler = new ForsmanHostHandler(CommunicationModule, _containerTable, _loadManager, StrategyActionType.PullAction, simulationSize);
                break;

            case Strategies.Proposed2018:
                _handler = new ProposedHostHandlerModule(CommunicationModule, _containerTable, _loadManager);
                break;

            default:

                throw new ArgumentOutOfRangeException(nameof(strategy), strategy, null);
            }
        }
        //[Test]
        //public void ReloadingPredictionDataTest()
        //{
        //    var configFile = Path.Combine(Environment.CurrentDirectory, "Prediction.config");
        //    try
        //    {
        //        File.Copy(configFile, configFile + ".bak", true);

        //        var collector = new LoadStatsCollector(Environment.CurrentDirectory, "Prediction.config");
        //        var thresholds = collector.GetControllersThresholds();
        //        TestBody(collector, new LoadPrediction((int)FeedbackLevel.LEVELS_COUNT, thresholds));// some updates to values should happen

        //        collector.SaveToFile();

        //        var prediction = new LoadPrediction(Environment.CurrentDirectory, "Prediction.config");

        //        prediction.SetPeerCount(199);
        //        Assert.That(prediction.Output == FeedbackLevel.Level1);

        //        prediction.SetPeerCount(200);
        //        Assert.That(prediction.Output == FeedbackLevel.Level2);

        //        prediction.SetPeerCount(150);
        //        Assert.That(prediction.Output == FeedbackLevel.Level1);

        //        prediction.SetPeerCount(50);
        //        Assert.That(prediction.Output, Is.EqualTo(FeedbackLevel.Lowest));

        //    }
        //    finally
        //    {
        //        File.Copy(configFile + ".bak", configFile, true);
        //        File.Delete(configFile + ".bak");
        //    }
        //}

        private static void TestBody(LoadStatsCollector loadStatsCollector, LoadPrediction predictor)
        {
            Assert.That(predictor.Output == FeedbackLevel.Lowest);

            predictor.SetPeerCount(100);
            Assert.That(predictor.Output == FeedbackLevel.Lowest);

            Dictionary <byte, int[]> updatedLevels;

            loadStatsCollector.UpdatePrediction(100, FeedbackLevel.Lowest, out updatedLevels);
            if (updatedLevels != null && updatedLevels.Count > 0)
            {
                predictor.UpdatePredictionLevels(updatedLevels);
                updatedLevels.Clear();
            }
            Assert.That(predictor.Output == FeedbackLevel.Lowest);

            predictor.SetPeerCount(200);
            Assert.That(predictor.Output == FeedbackLevel.Level1);

            loadStatsCollector.UpdatePrediction(200, FeedbackLevel.Lowest, out updatedLevels);
            if (updatedLevels != null && updatedLevels.Count > 0)
            {
                predictor.UpdatePredictionLevels(updatedLevels);
                updatedLevels.Clear();
            }

            Assert.That(predictor.Output == FeedbackLevel.Lowest);

            loadStatsCollector.UpdatePrediction(200, FeedbackLevel.Level2, out updatedLevels);
            if (updatedLevels != null && updatedLevels.Count > 0)
            {
                predictor.UpdatePredictionLevels(updatedLevels);
                updatedLevels.Clear();
            }

            Assert.That(predictor.Output, Is.EqualTo(FeedbackLevel.Level2));

            predictor.SetPeerCount(198);
            Assert.That(predictor.Output, Is.EqualTo(FeedbackLevel.Level1));
        }
        public MeasureValueHolder ReadDataFromDisk(string mainFile)
        {
            var                     config         = mainFile.Split('\\');
            SimulationSize          simulationSize = (SimulationSize)Convert.ToInt32(config[3]);
            StartUtilizationPercent perecent       =
                (StartUtilizationPercent)Enum.Parse(typeof(StartUtilizationPercent), config[4].Split('_')[0]);
            LoadChangeAction changeAction =
                (LoadChangeAction)Enum.Parse(typeof(LoadChangeAction), config[4].Split('_')[1]);

            LoadPrediction      loadPrediction      = (LoadPrediction)Enum.Parse(typeof(LoadPrediction), config[5]);
            SchedulingAlgorithm schedulingAlgorithm = (SchedulingAlgorithm)Enum.Parse(typeof(SchedulingAlgorithm), config[6]);
            Strategies          strategy            = (Strategies)Enum.Parse(typeof(Strategies), config[7].Split('_')[0]);
            ContainersType      containerType       = (ContainersType)Enum.Parse(typeof(ContainersType), config[7].Split('_')[1]);
            AuctionTypes        pushAuctionType     = (AuctionTypes)Enum.Parse(typeof(AuctionTypes), config[8].Split('_')[0]);
            AuctionTypes        pullAuctionType     = (AuctionTypes)Enum.Parse(typeof(AuctionTypes), config[8].Split('_')[1]);
            TestedHosts         testedHosts         = (TestedHosts)Enum.Parse(typeof(TestedHosts), config[9]);
            bool delay = bool.Parse(config[10]);

            int TrialId = int.Parse(config[11]);
            var conf    = new RunConfiguration(simulationSize, perecent, changeAction, loadPrediction, strategy, pushAuctionType, pullAuctionType, schedulingAlgorithm, testedHosts, containerType, delay, TrialId);
            MeasureValueHolder holder =
                new MeasureValueHolder(conf);

            using (StreamReader reader = new StreamReader(mainFile))
            {
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    var    line                        = reader.ReadLine().Split(',');
                    int    i                           = Convert.ToInt32(line[0]);
                    double entropy                     = Convert.ToDouble(line[1]);
                    double predictedEntropy            = Convert.ToDouble(line[2]);
                    double avgRealVolume               = Convert.ToDouble(line[3]);
                    double avgPredictedVolume          = Convert.ToDouble(line[4]);
                    double idealHostCount              = Convert.ToDouble(line[5]);
                    double noHosts                     = Convert.ToDouble(line[6]);
                    double underHosts                  = Convert.ToDouble(line[7]);
                    double overHosts                   = Convert.ToDouble(line[8]);
                    double normalHosts                 = Convert.ToDouble(line[9]);
                    double evacuatingHosts             = Convert.ToDouble(line[10]);
                    double migrations                  = Convert.ToDouble(line[11]);
                    double pushRequests                = Convert.ToDouble(line[12]);
                    double pushLoadAvailabilityRequest = Convert.ToDouble(line[13]);
                    double pullRequests                = Convert.ToDouble(line[14]);
                    double pullLoadAvailabilityRequest = Convert.ToDouble(line[15]);
                    double totalMessages               = Convert.ToDouble(line[16]);
                    double slaViolationsCount          = Convert.ToDouble(line[17]);
                    double slaViolationsPercent        = Convert.ToDouble(line[18]);

                    double         minNeeded        = Convert.ToDouble(line[19]);
                    double         maxNeeded        = Convert.ToDouble(line[20]);
                    double         power            = Convert.ToDouble(line[21]);
                    double         stdDev           = Convert.ToDouble(line[22]);
                    double         imagePulls       = Convert.ToDouble(line[23]);
                    double         communicatedSize = Convert.ToDouble(line[24]);
                    MeasuresValues m = new MeasuresValues(pushRequests, pullRequests, idealHostCount, noHosts,
                                                          migrations,
                                                          totalMessages, entropy, predictedEntropy, pushLoadAvailabilityRequest,
                                                          pullLoadAvailabilityRequest,
                                                          avgRealVolume, avgPredictedVolume, minNeeded, maxNeeded,
                                                          underHosts, overHosts, normalHosts, evacuatingHosts,
                                                          slaViolationsCount, slaViolationsPercent,
                                                          power, stdDev, imagePulls, communicatedSize);
                    holder.MeasuredValuesList.Add(m);
                }
            }

            var nfile = mainFile.Replace("All", "ConMig");

            using (StreamReader reader = new StreamReader(new FileStream(nfile, FileMode.Open)))
            {
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    var    line  = reader.ReadLine().Split(',');
                    int    conId = Convert.ToInt32(line[0]);
                    double count = Convert.ToDouble(line[1]);
                    double time  = Convert.ToDouble(line[2]);
                    holder.ContainerMeasureValuesList.Add(conId, new ContainerMeasureValue(conId, count, time));
                }
            }

            nfile = mainFile.Replace("All", "Hosts");
            using (StreamReader reader = new StreamReader(new FileStream(nfile, FileMode.Open)))
            {
                List <HostLoadInfo> list = new List <HostLoadInfo>();
                int current = 0;
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    //iteration,Id,cpu,mem,io,concount,cpuutil,memutil,ioutil,
                    var    line        = reader.ReadLine().Split(',');
                    int    it          = Convert.ToInt32(line[0]);
                    int    hostId      = Convert.ToInt32(line[1]);
                    double cpu         = Convert.ToDouble(line[2]);
                    double mem         = Convert.ToDouble(line[3]);
                    double io          = Convert.ToDouble(line[4]);
                    int    concount    = Convert.ToInt32(line[5]);
                    double cpuutil     = Convert.ToDouble(line[6]);
                    double memutil     = Convert.ToDouble(line[7]);
                    double ioutil      = Convert.ToDouble(line[8]);
                    double dataSizeOut = Convert.ToDouble(line[9]);
                    double dataSizeIn  = Convert.ToDouble(line[10]);

                    var linfo = new HostLoadInfo(hostId, new Load(cpu, mem, io), concount, cpuutil, memutil, ioutil, dataSizeOut, dataSizeIn);
                    if (it == current)
                    {
                        list.Add(linfo);
                    }
                    else
                    {
                        holder.HostMeasureValuesList.Add(new HostMeasureValues(list));
                        list.Clear();
                        list.Add(linfo);
                        current++;
                    }
                }
            }
            if (containerType == ContainersType.D)
            {
                nfile = mainFile.Replace("All", "PullsPerImage");
                using (StreamReader reader = new StreamReader(new FileStream(nfile, FileMode.Open)))
                {
                    reader.ReadLine();
                    while (!reader.EndOfStream)
                    {
                        var line    = reader.ReadLine().Split(',');
                        int ImageId = Convert.ToInt32(line[0]);
                        int Pulls   = Convert.ToInt32(line[1]);
                        holder.PullsPerImage.Add(ImageId, Pulls);
                    }
                }
            }

            return(holder);
        }
Пример #12
0
 public DockerContainer(int containerId, Load containerLoad, LoadPrediction currentLoadPrediction, int imageId)
     : base(containerId, containerLoad, currentLoadPrediction)
 {
     ImageId       = imageId;
     ContainerType = ContainersType.D;
 }