Beispiel #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);
            }
        }
        public async Task ManualCollectionShouldNotCollectBusyActivations()
        {
            Initialize(DEFAULT_IDLE_TIMEOUT);

            TimeSpan  shortIdleTimeout  = TimeSpan.FromSeconds(1);
            const int idleGrainCount    = 500;
            const int busyGrainCount    = 500;
            var       idleGrainTypeName = typeof(IdleActivationGcTestGrain1).FullName;
            var       busyGrainTypeName = typeof(BusyActivationGcTestGrain1).FullName;

            List <Task> tasks0 = new List <Task>();
            List <IBusyActivationGcTestGrain1> busyGrains = new List <IBusyActivationGcTestGrain1>();

            logger.Info("ManualCollectionShouldNotCollectBusyActivations: activating {0} busy grains.", busyGrainCount);
            for (var i = 0; i < busyGrainCount; ++i)
            {
                IBusyActivationGcTestGrain1 g = this.testCluster.GrainFactory.GetGrain <IBusyActivationGcTestGrain1>(Guid.NewGuid());
                busyGrains.Add(g);
                tasks0.Add(g.Nop());
            }
            await Task.WhenAll(tasks0);

            bool[]      quit       = new bool[] { false };
            Func <Task> busyWorker =
                async() =>
            {
                logger.Info("ManualCollectionShouldNotCollectBusyActivations: busyWorker started");
                List <Task> tasks1 = new List <Task>();
                while (!quit[0])
                {
                    foreach (var g in busyGrains)
                    {
                        tasks1.Add(g.Nop());
                    }
                    await Task.WhenAll(tasks1);
                }
            };

            Task.Run(busyWorker).Ignore();

            logger.Info("ManualCollectionShouldNotCollectBusyActivations: activating {0} idle grains.", idleGrainCount);
            tasks0.Clear();
            for (var i = 0; i < idleGrainCount; ++i)
            {
                IIdleActivationGcTestGrain1 g = this.testCluster.GrainFactory.GetGrain <IIdleActivationGcTestGrain1>(Guid.NewGuid());
                tasks0.Add(g.Nop());
            }
            await Task.WhenAll(tasks0);

            int activationsCreated = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, idleGrainTypeName) + await TestUtils.GetActivationCount(this.testCluster.GrainFactory, busyGrainTypeName);

            Assert.Equal(idleGrainCount + busyGrainCount, activationsCreated);

            logger.Info("ManualCollectionShouldNotCollectBusyActivations: grains activated; waiting {0} sec (activation GC idle timeout is {1} sec).", shortIdleTimeout.TotalSeconds, DEFAULT_IDLE_TIMEOUT.TotalSeconds);
            await Task.Delay(shortIdleTimeout);

            TimeSpan everything = TimeSpan.FromMinutes(10);

            logger.Info("ManualCollectionShouldNotCollectBusyActivations: triggering manual collection (timespan is {0} sec).", everything.TotalSeconds);
            IManagementGrain mgmtGrain = this.testCluster.GrainFactory.GetGrain <IManagementGrain>(0);
            await mgmtGrain.ForceActivationCollection(everything);


            logger.Info("ManualCollectionShouldNotCollectBusyActivations: waiting {0} sec (activation GC idle timeout is {1} sec).", WAIT_TIME.TotalSeconds, DEFAULT_IDLE_TIMEOUT.TotalSeconds);
            await Task.Delay(WAIT_TIME);

            // we should have only collected grains from the idle category (IdleActivationGcTestGrain).
            int idleActivationsNotCollected = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, idleGrainTypeName);

            int busyActivationsNotCollected = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, busyGrainTypeName);

            Assert.Equal(0, idleActivationsNotCollected);
            Assert.Equal(busyGrainCount, busyActivationsNotCollected);

            quit[0] = true;
        }