Exemple #1
0
        private static void CollectActivations(IReadOnlyDictionary <string, string> options, IEnumerable <string> args)
        {
            var    silos           = args.Select(ParseSilo).ToArray();
            int    ageLimitSeconds = 0;
            string s;

            if (options.TryGetValue("age", out s))
            {
                int.TryParse(s, out ageLimitSeconds);
            }

            var ageLimit = TimeSpan.FromSeconds(ageLimitSeconds);

            if (ageLimit > TimeSpan.Zero)
            {
                systemManagement.ForceActivationCollection(silos, ageLimit);
            }
            else
            {
                systemManagement.ForceGarbageCollection(silos);
            }
        }
Exemple #2
0
        public async Task RunExperiment(IGrainFactory grainFactory, string expId = "DummyExperimentID", AnalysisRootKind rootKind = AnalysisRootKind.Default)
        {
            try
            {
                this.ExperimentID = expId;

                // await systemManagement.ForceActivationCollection(System.TimeSpan.MaxValue);
                AnalysisClient.ErrorMessage = "OK so far";

                var myStatsGrain = StatsHelper.GetStatGrain(grainFactory);
                await myStatsGrain.ResetStats();

#if COMPUTE_STATS
                this.series = 0;

                // Repeat every 30 seconds.
                IObservable <long> observable = System.Reactive.Linq.Observable.Interval(TimeSpan.FromSeconds(60));

                // Token for cancelation
                CancellationTokenSource source = new CancellationTokenSource();

                Action action = (async() => await this.SaveUpdateInfo(myStatsGrain));

                // Subscribe the obserable to the task on execution.
                observable.Subscribe(x => { Task task = new Task(action); task.Start(); }, source.Token);
#endif
                this.stopWatch = Stopwatch.StartNew();

                AnalysisClient.ExperimentStatus = ExperimentStatus.Compiling;

                this.analyzer.RootKind = rootKind;
                await this.analyzer.InitializeOnDemandOrleansAnalysis();

                await this.analyzer.WaitForOnDemandOrleansAnalysisToBeReady();

                var compilationElapsedTime = stopWatch.ElapsedMilliseconds;

                if (AnalysisClient.ExperimentStatus == ExperimentStatus.Cancelled)
                {
                    AnalysisClient.ErrorMessage = "Cancelled by user";
                    return;
                }

                AnalysisClient.ExperimentStatus = ExperimentStatus.Running;

                await this.analyzer.ContinueOnDemandOrleansAnalysis();

                AnalysisClient.ExperimentStatus = ExperimentStatus.ComputingResults;

                this.stopWatch.Stop();
#if COMPUTE_STATS
                source.Cancel();
#endif
                var totalRecvNetwork = 0L;
                var totalSentLocal   = 0L;
                var totalSentNetwork = 0L;
                var totalRecvLocal   = 0L;

                var totalAct   = 0L;
                var totalDeact = 0L;
                var time       = DateTime.Now;
                var acummulatedPerSiloMemoryUsage = 0L;
                var maxPerSiloMemoryUsage         = 0L;
                var acummulatedPerSiloCPUUsage    = 0D;
                var maxPerSiloCPUUsage            = 0D;

                var methods = await this.SolutionManager.GetReachableMethodsCountAsync();

                this.systemManagement = grainFactory.GetGrain <IManagementGrain>(SYSTEM_MANAGEMENT_ID);
                await systemManagement.ForceGarbageCollection(null);

                var hosts = await systemManagement.GetHosts();

                var averagePerSiloMemoryUsage = 0L;

                var orleansStats = await systemManagement.GetRuntimeStatistics(null);

#if COMPUTE_STATS
                //var silos = hosts.Keys.ToArray();


                //this.methods = -1;

                // var messageMetric = new MessageMetrics();

                //var myStatsGrain = StatsHelper.GetStatGrain(grainFactory);
                var silosEnumeration = await myStatsGrain.GetSilos();

                var silos             = silosEnumeration.ToArray();
                var siloComputedStats = new SiloComputedStats[silos.Length];
                var silosSize         = silos.Length;
                for (var i = 0; i < silos.Length; i++)
                {
                    var silo       = silos[i];
                    var addrString = silo; /*/silo.Endpoint.Address.ToString();*/
                    siloComputedStats[i] = new SiloComputedStats();

                    siloComputedStats[i].TotalSentLocalSilo += await myStatsGrain.GetSiloLocalMsgs(addrString);

                    siloComputedStats[i].TotalRecvLocalSilo += await myStatsGrain.GetSiloLocalMsgs(addrString);

                    siloComputedStats[i].TotalSentNetworkSilo += await myStatsGrain.GetSiloNetworkSentMsgs(addrString);

                    siloComputedStats[i].TotalRecvNetworkSilo += await myStatsGrain.GetSiloNetworkReceivedMsgs(addrString);

                    siloComputedStats[i].MemoryUsage += await myStatsGrain.GetSiloMemoryUsage(addrString);

                    var activationDic = await myStatsGrain.GetActivationsPerSilo(addrString);

                    var deactivationDic = await myStatsGrain.GetDeactivationsPerSilo(addrString);

                    var activations   = activationDic.Sum(items => items.Value);
                    var deactivations = deactivationDic.Sum(items => items.Value);
                    siloComputedStats[i].TotalActivations    += activations;
                    siloComputedStats[i].TotalDeactivations  += deactivations;
                    siloComputedStats[i].TotalClientMessages += await myStatsGrain.GetTotalClientMsgsPerSilo(addrString);

                    // totalAct += orleansStats[i].ActivationCount;
                    totalAct   += activations;
                    totalDeact += deactivations;

                    //AddSiloMetric(silos[i], siloComputedStats[i], time, machines);
                    // Save results in per silo table
                    if (orleansStats.Length <= i)
                    {
                        throw new IndexOutOfRangeException(String.Format("OrlenasStats Lenght is {0} and silos Lenght is {1}", orleansStats.Length, silos.Length));
                    }

                    AddSiloMetricWithOrleans(silos[i], orleansStats[i], siloComputedStats[i], time, machines);

                    totalSentNetwork += siloComputedStats[i].TotalSentNetworkSilo;
                    totalRecvNetwork += siloComputedStats[i].TotalRecvNetworkSilo;

                    totalSentLocal += siloComputedStats[i].TotalSentLocalSilo;
                    totalRecvLocal += siloComputedStats[i].TotalSentLocalSilo;

                    acummulatedPerSiloMemoryUsage += orleansStats[i].MemoryUsage;
                    acummulatedPerSiloCPUUsage    += orleansStats[i].CpuUsage;

                    if (maxPerSiloMemoryUsage < orleansStats[i].MemoryUsage)
                    {
                        maxPerSiloMemoryUsage = orleansStats[i].MemoryUsage;
                    }

                    if (maxPerSiloCPUUsage < orleansStats[i].CpuUsage)
                    {
                        maxPerSiloCPUUsage = orleansStats[i].CpuUsage;
                    }
                }

                var avgLatency = await myStatsGrain.GetAverageLatency();

                var maxLatency = await myStatsGrain.GetMaxLatency();

                var maxLatencyMsg = await myStatsGrain.GetMaxLatencyMsg();

                var totalMessages = await myStatsGrain.GetTotalMessages();

                var clientMessages = await myStatsGrain.GetTotalClientMessages();
#else
                var avgLatency    = 0;
                var maxLatency    = 0;
                var maxLatencyMsg = "";

                var totalMessages  = 0;
                var clientMessages = 0;
                for (int i = 0; i < this.machines; i++)
                {
                    if (maxPerSiloMemoryUsage < orleansStats[i].MemoryUsage)
                    {
                        maxPerSiloMemoryUsage = orleansStats[i].MemoryUsage;
                    }
                    acummulatedPerSiloMemoryUsage += orleansStats[i].MemoryUsage;
                }
                var silosSize = this.machines; // hosts.Keys.Count;
#endif
                averagePerSiloMemoryUsage = acummulatedPerSiloMemoryUsage / silosSize;

                var testFullName = this.subject;
                var results      = new SubjectExperimentResults()
                {
                    ExpID                     = expId,
                    Time                      = time,
                    Subject                   = testFullName,
                    Machines                  = machines,
                    Methods                   = methods,
                    Messages                  = totalMessages,
                    ClientMessages            = clientMessages, // SolutionAnalyzer.MessageCounter,
                    CompilationTime           = compilationElapsedTime,
                    ElapsedTime               = stopWatch.ElapsedMilliseconds,
                    Activations               = totalAct,
                    Deactivations             = totalDeact,
                    Observations              = "From web",
                    PartitionKey              = expId + " " + testFullName, //  + " " + time.ToFileTime().ToString(),
                    RowKey                    = testFullName + " " + time.ToFileTime().ToString(),
                    TotalRecvNetwork          = totalRecvNetwork,
                    TotalSentLocal            = totalSentLocal,
                    TotalSentNetwork          = totalSentNetwork,
                    TotalRecvLocal            = totalRecvLocal,
                    AverageLatency            = avgLatency,
                    MaxLatency                = maxLatency,
                    MaxLatencyMsg             = maxLatencyMsg,
                    AveragePerSiloMemoryUsage = averagePerSiloMemoryUsage,  // acummulatedPerSiloMemoryUsage / silosSize,
                    AveragePerSiloCPUUsage    = acummulatedPerSiloCPUUsage / silosSize,
                    MaxPerSiloMemoryUsage     = maxPerSiloMemoryUsage,
                    MaxPerSiloCPUUsage        = maxPerSiloCPUUsage
                };

                // Save results in main table
                this.AddSubjetResults(results);

                //SaveResults(@"Y:\");

                AnalysisClient.ExperimentStatus = ExperimentStatus.Ready;
                AnalysisClient.ErrorMessage     = "OK";
                Logger.LogWarning(GrainClient.Logger, "AnalysisClient", "RunExperiment", "Finished OK");
            }
            catch (Exception ex)
            {
                var innerEx = ex;
                while (innerEx is AggregateException)
                {
                    innerEx = innerEx.InnerException;
                }
                AnalysisClient.ErrorMessage = "Error connecting to Orleans: " + innerEx + " at " + DateTime.Now;

                AnalysisClient.ExperimentStatus = ExperimentStatus.Failed;
                Logger.LogError(GrainClient.Logger, "AnalysisClient", "RunExperiment", "Finished with ERRORS {0}", ex);

                throw ex;
            }
        }