abp icon indicating copy to clipboard operation
abp copied to clipboard

Redis Cache verry slow

Open thanhtai9606 opened this issue 1 year ago • 7 comments

Description

When I create an application netcore combine with Redis Cache + db mssql it request verry fast approximately 24k req/second?? But When I use redis in abp in service it very slow 1.8k req/second ?? it similary request from db?? I already debug it ok get value from redis, But it very slow???

Configuration

Net 7 and Abp Version 7.0.0

Regression?

My Code

     // var cacheDb = await _cache.GetOrAddAsync(
                //                 id, //Guid type used as the cache key
                //                 async () => ObjectMapper.Map<FileItem, FileItemDto>(await _fileManager.GetFileInfoAsync(id)),
                //                 () => new DistributedCacheEntryOptions
                //                 {
                //                     AbsoluteExpiration = DateTimeOffset.Now.AddHours(1)
                //                 }
                //             );

        var cacheDb = await _cache.GetAsync(id);
        if (cacheDb != null)
        {
            return cacheDb;
        }
        else
        {

        var data = ObjectMapper.Map<FileItem, FileItemDto>(await _fileManager.GetFileInfoAsync(id));
         await _cache.SetAsync(id,data);
            return data;

Analysis

thanhtai9606 avatar Oct 12 '23 04:10 thanhtai9606

Please set Debug as your log level and check the logs.

maliming avatar Oct 12 '23 04:10 maliming

Please set Debug as your log level and check the logs.

it ok no error. But It can not process a lot of request base redis, very slow?? I tried it with oha just over 1.8k request/second

[13:40:43 ERR] A task was canceled.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Volo.Abp.Threading.SemaphoreSlimExtensions.LockAsync(SemaphoreSlim semaphoreSlim, CancellationToken cancellationToken)
   at Volo.Abp.Caching.DistributedCache`2.GetOrAddAsync(TCacheKey key, Func`1 factory, Func`1 optionsFactory, Nullable`1 hideErrors, Boolean considerUow, CancellationToken token)
   at Becamex.ArchiveCenter.DictionaryAppService.GetAsync(Guid id) in /home/nemo/apps/source/develop/archive-center-backend/src/Becamex.ArchiveCenter.Application/Dictionaries/DictionaryAppService.cs:line 31
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.GlobalFeatures.GlobalFeatureInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()

thanhtai9606 avatar Oct 12 '23 06:10 thanhtai9606

Can you share the detailed steps so I can reproduce this?

maliming avatar Oct 17 '23 01:10 maliming

Can you share the detailed steps so I can reproduce this?

When I reduce (remove) middlewares default by abp, It better over 7k req/sec?? May be middlewares leading to performance??

thanhtai9606 avatar Oct 18 '23 02:10 thanhtai9606

You can check your app logs.

maliming avatar Oct 18 '23 05:10 maliming

You can check your app logs.

I already checked app logs, But no special problems??

thanhtai9606 avatar Oct 25 '23 07:10 thanhtai9606

I also met this issue. I think when too much request the method semaphoreslim.lockasync lock cache key. I deploy on cluster with load balancer

nva-avn-dng avatar Feb 07 '24 03:02 nva-avn-dng