IdentityServer / IdentityServer4

OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
https://identityserver.io
Apache License 2.0
9.23k stars 4.02k forks source link

Poor performance #5373

Closed MDzyga closed 3 years ago

MDzyga commented 3 years ago

Issue / Steps to reproduce the problem

  1. Configure IdentityServer to use ConfigurationDbContext
  2. Configure Identityserver to use encrypted SQLite database with EF Core and IdentityDbContext
  3. Prepare simple migrations - at least 1 client, 1 role, 2 users, 1 role, 4 scopes
  4. Send request for token with grant type password

Packages

IdentityServer 4.1.2 .NET Core 5 Microsoft.EntityFrameworkCore 5.0.11 Microsoft.EntityFrameworkCore.Sqlite 5.0.11 SQLitePCLRaw.bundle_e_sqlcipher 2.0.6 System.Data.SQLite.Core 1.0.115

Relevant parts of the log file

[09:46:39 WRN] Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'
[09:46:39 DBG] Found [] identity scopes in database
[09:46:39 WRN] Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'
[09:46:39 DBG] Found [] API resources in database
[09:46:39 WRN] Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'
FullStackIndie commented 3 years ago

services.AddDbContext(options => { // Use SqlLite instead of UseNpgsql options.UseNpgsql(Configuration["YourDatabaseConnection"], // this will speed up the performance by making multiple small calls to the database instead of 1 huge one options => options.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery) // enbales retries on failed commands .EnableRetryOnFailure( maxRetryCount: 4, maxRetryDelay: TimeSpan.FromSeconds(1), errorCodesToAdd: new string[] { })); // enables better logging for development - dont use in production options.EnableSensitiveDataLogging(true); // enables better logging for development - dont use in production options.EnableDetailedErrors(true); // I have never used this but the error in your log said to configure this so this is how you do it options.ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning)); });

Copy this code into your code editor for better readability - Hope this helps

MDzyga commented 3 years ago

Thanks, warning dissapered after setting UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery) in options.ConfigureDbContext

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.