Skip to content

Commit

Permalink
Merged PR 1177: [CC v2.1] Optimize GetUserDataEntitiesByIds Activity
Browse files Browse the repository at this point in the history
**Issue :** Fan In/Fan Out pattern in GetUserDataEntitiesByIds is creating multiple function, exhausting free function execution count, and adding 0.20$ extra cost for every 1 million messages sent.

**Changes :** Get the user data sequentially for each group members.
This change is targeting to bring down function execution count by 50% and the overall function cost.
  • Loading branch information
Priyank Saxena authored and aosolis committed Oct 16, 2020
1 parent 9d226a8 commit d94ee82
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ public async Task<IEnumerable<UserDataEntity>> RunAsync(
{
try
{
var tasks = new List<Task<UserDataEntity>>();
foreach (var aadId in userAadIds)
{
var task = context.CallActivityWithRetryAsync<UserDataEntity>(
nameof(GetUserDataEntitiesByIdsActivity.GetUserDataEntityAsync),
ActivitySettings.CommonActivityRetryOptions,
aadId);
tasks.Add(task);
}

var userEntities = await Task.WhenAll(tasks);
return userEntities;
return await context.CallActivityWithRetryAsync<IEnumerable<UserDataEntity>>(
nameof(GetUserDataEntitiesByIdsActivity.GetUserDataEntitiesAsync),
ActivitySettings.CommonActivityRetryOptions,
userAadIds);
}
catch (Exception ex)
{
Expand All @@ -70,14 +62,21 @@ public async Task<IEnumerable<UserDataEntity>> RunAsync(
/// This method represents the "get user data entity" durable activity.
/// It gets installed user data.
/// </summary>
/// <param name="aadId">User's Aad Id.</param>
/// <param name="userAadIds">list of user Aad Id.</param>
/// <returns>It returns the installed user data entity.</returns>
[FunctionName(nameof(GetUserDataEntityAsync))]
public async Task<UserDataEntity> GetUserDataEntityAsync(
[ActivityTrigger] string aadId)
[FunctionName(nameof(GetUserDataEntitiesAsync))]
public async Task<IEnumerable<UserDataEntity>> GetUserDataEntitiesAsync(
[ActivityTrigger] IEnumerable<string> userAadIds)
{
return await this.userDataRepository.
GetAsync(UserDataTableNames.UserDataPartition, aadId);
var userDataEntities = new List<UserDataEntity>();
foreach (var aadId in userAadIds)
{
var userDataEntity = await this.userDataRepository.
GetAsync(UserDataTableNames.UserDataPartition, aadId);
userDataEntities.Add(userDataEntity);
}

return userDataEntities;
}
}
}

0 comments on commit d94ee82

Please sign in to comment.