Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase default context pool size from 128 to 1024 #24870

Merged
1 commit merged into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static IServiceCollection AddDbContext<TContextService, TContextImplement
/// will not be called.
/// </para>
/// </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 1024. </param>
/// <returns> The same service collection so that multiple calls can be chained. </returns>
public static IServiceCollection AddDbContextPool<TContext>(
this IServiceCollection serviceCollection,
Expand Down Expand Up @@ -187,7 +187,7 @@ public static IServiceCollection AddDbContextPool<TContext>(
/// will not be called.
/// </para>
/// </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 1024. </param>
/// <returns> The same service collection so that multiple calls can be chained. </returns>
public static IServiceCollection AddDbContextPool<TContextService, TContextImplementation>(
this IServiceCollection serviceCollection,
Expand Down Expand Up @@ -241,7 +241,7 @@ public static IServiceCollection AddDbContextPool<TContextService, TContextImple
/// will not be called.
/// </para>
/// </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 1024. </param>
/// <returns> The same service collection so that multiple calls can be chained. </returns>
public static IServiceCollection AddDbContextPool<TContext>(
this IServiceCollection serviceCollection,
Expand Down Expand Up @@ -292,7 +292,7 @@ public static IServiceCollection AddDbContextPool<TContext>(
/// will not be called.
/// </para>
/// </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 1024. </param>
/// <returns> The same service collection so that multiple calls can be chained. </returns>
public static IServiceCollection AddDbContextPool<TContextService, TContextImplementation>(
this IServiceCollection serviceCollection,
Expand Down Expand Up @@ -814,7 +814,7 @@ public static IServiceCollection AddDbContextFactory<TContext, TFactory>(
/// will not be called.
/// </para>
/// </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 1024. </param>
/// <returns> The same service collection so that multiple calls can be chained. </returns>
public static IServiceCollection AddPooledDbContextFactory<TContext>(
this IServiceCollection serviceCollection,
Expand Down Expand Up @@ -858,7 +858,7 @@ public static IServiceCollection AddPooledDbContextFactory<TContext>(
/// will not be called.
/// </para>
/// </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 1024. </param>
/// <returns> The same service collection so that multiple calls can be chained. </returns>
public static IServiceCollection AddPooledDbContextFactory<TContext>(
this IServiceCollection serviceCollection,
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Infrastructure/PooledDbContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PooledDbContextFactory(IDbContextPool<TContext> pool)
/// Initializes a new instance of the <see cref="PooledDbContextFactory{TContext}" /> class.
/// </summary>
/// <param name="options"> The options to use for contexts produced by this factory. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 128. </param>
/// <param name="poolSize"> Sets the maximum number of instances retained by the pool. Defaults to 1024. </param>
public PooledDbContextFactory(DbContextOptions<TContext> options, int poolSize = DbContextPool<DbContext>.DefaultPoolSize)
{
var optionsBuilder = new DbContextOptionsBuilder<TContext>(options);
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Internal/DbContextPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DbContextPool<TContext> : IDbContextPool<TContext>, IDisposable, IA
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public const int DefaultPoolSize = 128;
public const int DefaultPoolSize = 1024;

private readonly ConcurrentQueue<IDbContextPoolable> _pool = new();

Expand Down
6 changes: 3 additions & 3 deletions test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void Validate_pool_size_default()
using var scope = serviceProvider.CreateScope();

Assert.Equal(
128,
1024,
scope.ServiceProvider
.GetRequiredService<PooledContext>()
.GetService<IDbContextOptions>()
Expand All @@ -276,7 +276,7 @@ public void Validate_pool_size_with_service_interface_default()
using var scope = serviceProvider.CreateScope();

Assert.Equal(
128,
1024,
((DbContext)scope.ServiceProvider
.GetRequiredService<IPooledContext>())
.GetService<IDbContextOptions>()
Expand All @@ -291,7 +291,7 @@ public void Validate_pool_size_with_factory_default()
using var context = serviceProvider.GetRequiredService<IDbContextFactory<PooledContext>>().CreateDbContext();

Assert.Equal(
128,
1024,
context.GetService<IDbContextOptions>()
.FindExtension<CoreOptionsExtension>().MaxPoolSize);
}
Expand Down