abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.76k stars 3.41k forks source link

Redis Cache verry slow #17851

Open thanhtai9606 opened 11 months ago

thanhtai9606 commented 11 months ago

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

maliming commented 11 months ago

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

thanhtai9606 commented 11 months ago

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()
maliming commented 11 months ago

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

thanhtai9606 commented 11 months ago

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??

maliming commented 11 months ago

You can check your app logs.

thanhtai9606 commented 10 months ago

You can check your app logs.

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

nva-avn-dng commented 7 months ago

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