Open Closed

The abp permission cache PermissionGrants loads very slowly during the first login, but very quickly during the second login. When the permission cache is manually cleared, it slows down again #9767


User avatar
0
heshengli created

abp权限缓存PermissionGrants,第一次登录加载很慢,第二次很快,当手动清除权限缓存后,又变慢

修改源码,添加耗时日志


6 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • The first login is slow because ABP loads all permission grants from the database and builds the permission cache (PermissionGrants). This is expected behavior, especially if you have a large number of permission grants (as shown in your screenshot: 204,034 entries).
    • The second login is fast because the permission data is served from the cache, not the database.
    • When you manually clear the permission cache, the next login is slow again because ABP must reload all permission grants from the database to rebuild the cache.

    This behavior is typical for ABP's distributed permission cache. The initial load is expensive if you have a large number of permission grants, but subsequent requests are fast due to caching.

    Recommendations:

    1. Reduce the number of permission grants if possible (e.g., avoid assigning permissions at the user level unless necessary; prefer role-based permissions).
    2. Ensure your cache (e.g., Redis) is properly configured and performant.
    3. If you must clear the cache, be aware that the first request after clearing will always be slower.

    Sources:

    • https://abp.io/support/questions/6533
    • https://abp.io/support/questions/3386

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你有多少个权限项目?

    第一次的权限检查发生在哪里? 菜单检查吗?

  • User Avatar
    0
    heshengli created

    接近4000个权限,50个角色,500用户,每次登录,PermissionGrants Cache,客户端4000,角色4000,用户4000,然后去重。第一登录慢,出现白屏,第二次快点,手动删除缓存,又变慢

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    请打开Debug日志看看sql的查询, 我们在之后的版本中改成了批量查询缓存和数据库.

    var loggerConfiguration = new LoggerConfiguration()
        .MinimumLevel.Debug()
        .Enrich.FromLogContext()
        .WriteTo.Async(c => c.File("Logs/logs.txt"))
    

    https://abp.io/support/questions/8622/How-to-enable-Debug-logs-for-troubleshoot-problems

  • User Avatar
    0
    heshengli created

    .har文件发你邮箱不,7.2.2 后权限修改代码,copy 会722 重写编译,替换722的权限模块代码可以不

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    不需要har文件, 只需要debug日志. 包括EF Core的Information日志.

    你可以替换权限模块的任何内置服务.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 05, 2025, 09:28