StackExchange / StackExchange/StackExchange.Redis
performance advise
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.2k
- Forks
- 1.6k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
Hello,
Assuming funcAsync are mainly readAsync / writeAsync calls to Redis using the StackExchange.Redis client -
which implementation of BatchExecuteAsync would be preferrable for better throughput / efficiency etc. ( especially when considering nature of the multiplexing going on behind the scenes ) ?
Thanks
public static async Task BatchedExecuteAsync<TItem>(this List<TItem> items, Func<TItem, Task> funcAsync, int amountOfParallelism)
{
var tasks = new List<Task>(amountOfParallelism);
int index = 0;
for (var i = 0; i < amountOfParallelism; i++)
{
tasks.Add(Task.Run(async () =>
{
while (true)
{
TItem item;
lock (tasks)
{
if (index >= items.Count)
{
break;
}
item = items[index];
index++;
}
await funcAsync(item);
}
}));
}
await Task.WhenAll(tasks);
}
public static async Task BatchedExecuteAsync<TItem>(this IEnumerable<TItem> items, Func<TItem,Task> funcAsync, int amountOfParallelism)
{
var tasks = new List<Task>(amountOfParallelism);
foreach (var item in items)
{
tasks.Add(funcAsync ( item));
if (tasks.Count == amountOfParallelism)
{
await Task.WhenAll(tasks);
tasks.Clear();
}
}
if (tasks.Count > 0)
{
await Task.WhenAll(tasks);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the two BatchedExecuteAsync implementations shown in the issue and review StackExchange.Redis guidance on async operations and multiplexing. Done would require a maintainer-backed recommendation or documented guidance; the issue names no repository files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, redis
- Domain
- databases, performance
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100