public async Task <OccupyResponse> OccupyAsync(OccupyRequest request) { var result = await _context.OccupyAsync(new OccupyInstance(this.GetActorId().GetGuidId(), request.PartitionId, request.ServiceInstanceName), _cancellation); //calculate a seed value to the nearest 100ms to stagger the due time of the different actors. //this prevents from all actors occupied within milliseconds of each other from all vacating at exactly the same time //which will cause a deadlock on the pool actor. var expirationQuanta = await _repository.GetExpirationQuantaAsync(_cancellation); var intervalMs = (int)Math.Round(expirationQuanta.TotalMilliseconds / 5); var dueMs = ((int)Math.Round((GetInstanceId().GetHashCode() % 1000) / 100.0) * 100) + intervalMs; await RegisterReminderAsync("expiration-quanta", null, TimeSpan.FromMilliseconds(dueMs), TimeSpan.FromMilliseconds(intervalMs)); return(new OccupyResponse(result.ServiceName)); }