Skip to content

Commit

Permalink
Increase default context pool size from 128 to 1024
Browse files Browse the repository at this point in the history
Closes #24849
  • Loading branch information
roji committed May 10, 2021
1 parent cc09604 commit 1fb5047
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
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

0 comments on commit 1fb5047

Please sign in to comment.