0

when I use:

`public call(Func<IDatabase, Task<T>> func){
  var task=func(redisInstance); 
  task.wait();
  return task.Result;
}`

call: call(client => redisInstance.SetMembersAsync(setName))

It works Fine, but when there are many requests 'CPU' usage increases;

but in second case:

`public async call2(Func<IDatabase, Task<T>> func){
   var task=func(redisInstance); 
   return await task.Result;
}`

call: call2(async client => await redisInstance.SetMembersAsync(setName))

CPU is ok but responses take much time;

any Ideas about this case? what is wrong in second method?

vakho papidze
  • 465
  • 3
  • 12

1 Answers1

0

There are 2 things I think you could do to improve the wall-clock time speed under load.

  1. There are 2 awaits, and this is because you have double wrapped the result, so it's now Task<Task<T>>. Change your call to:

    call2(client => redisInstance.SetMembersAsync(setName))
    
  2. You could optimize by removing the implicit synchronization of the continuation after awaiting, by using .ConfigureAwait(false), so change your await to:

    return await task.ConfigureAwait(false);
    
Stuart
  • 5,358
  • 19
  • 28