示例#1
0
        /// <summary>
        /// Checks each actor for expiration and purges if allowed.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        async Task PurgeActorsAsync(CancellationToken cancellationToken)
        {
            logger.Information("Running state actor purge.");

            var more = (ContinuationToken)null;
            var keep = 0;
            var remv = 0;

            do
            {
                // get a page of actors
                var page = await StateProvider.GetActorsAsync(128, more, cancellationToken);

                more = page.ContinuationToken;

                // potentially purge actors
                foreach (var actorId in page.Items)
                {
                    if (await TryPurgeActorAsync(actorId, cancellationToken))
                    {
                        remv++;
                    }
                    else
                    {
                        keep++;
                    }
                }
            }while (more != null && cancellationToken.IsCancellationRequested == false);

            // report count of known active actors
            logger.Information("Removed {RemovedCount} actors during purge, kept {KeepCount} actors.", remv, keep);
            Partition.ReportLoad(new[] { new LoadMetric("AspNetStateService.ActiveSessionCount", keep) });
        }
        public async Task <IEnumerable <int> > GetCountsAsync(CancellationToken cancellationToken)
        {
            ContinuationToken continuationToken = null;

            var result = new List <int>();

            do
            {
                var page = await StateProvider.GetActorsAsync(10000, continuationToken, cancellationToken);

                foreach (var actorId in page.Items)
                {
                    var state = await StateProvider.LoadStateAsync <int>(
                        actorId : actorId,
                        stateName : "count",
                        cancellationToken : cancellationToken);

                    result.Add(state);
                }

                continuationToken = page.ContinuationToken;
            } while (continuationToken != null);

            return(result);
        }
示例#3
0
        public async Task <IEnumerable <Student> > GetStudentsAsync(CancellationToken cancellationToken)
        {
            var ids = new List <Guid>();
            ContinuationToken continuationToken = null;

            do
            {
                var page = await StateProvider.GetActorsAsync(int.MaxValue, continuationToken, cancellationToken);

                ids.AddRange(page.Items.Select(actorId => actorId.GetGuidId()));

                continuationToken = page.ContinuationToken;
            } while (continuationToken != null);

            var tasks = ids.Select(id => GetStudentAsync(id, cancellationToken));

            return(await Task.WhenAll(tasks));
        }
示例#4
0
        //To test performance of paging.
        public async Task <IEnumerable <Guid> > GetAllGuids(int numItemsToReturn, CancellationToken cancellationToken)
        {
            ContinuationToken continuationToken = null;

            var ids = new List <Guid>();

            do
            {
                var page = await
                           StateProvider.GetActorsAsync(numItemsToReturn, continuationToken, cancellationToken);

                foreach (var actorId in page.Items)
                {
                    ids.Add(actorId.GetGuidId());
                }

                continuationToken = page.ContinuationToken;
            } while (continuationToken != null);

            return(ids);
        }
示例#5
0
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            await base.RunAsync(cancellationToken);

            if (cancellationToken.CanBeCanceled)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            ContinuationToken continuationToken = null;

            do
            {
                var page = await StateProvider.GetActorsAsync(int.MaxValue, continuationToken, cancellationToken);

                foreach (var actorId in page.Items)
                {
                    _cache.AddOrUpdate(actorId.GetGuidId(), new object(), (id, o) => o);
                }

                continuationToken = page.ContinuationToken;
            } while (continuationToken != null);
        }