Replies: 5 comments 7 replies
-
At least I think this point should be specifically documented. Currently I suggest the following codes before // ...
var app = builder.Build();
var redisDb = app.Services.GetRequiredService<IRedisDatabase>();
redisDb.Ping();
// ...
app.Run(); |
Beta Was this translation helpful? Give feedback.
-
Hi @LeaFrock I've partially documented that part here /~https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/doc/configuration/connection-pool.md when I'm saying
Probably a goog idea cold be to open all the connection in parallels (right now is made one by one by Moreover the connection array could be frozen in case of .NET 8 Let me test it |
Beta Was this translation helpful? Give feedback.
-
Another idea could be to create and extension method alled "WaitRedisConnectionsAndRun" or a sort of bootstrap tasks that wait redis |
Beta Was this translation helpful? Give feedback.
-
here a possible solution (tested) with parallel runs private void EmitConnections()
{
Parallel.For(0, redisConfiguration.PoolSize, index =>
{
var multiplexer = ConnectionMultiplexer.Connect(redisConfiguration.ConfigurationOptions);
if (redisConfiguration.ProfilingSessionProvider != null)
multiplexer.RegisterProfiler(redisConfiguration.ProfilingSessionProvider);
connections[index] = redisConfiguration.StateAwareConnectionFactory(multiplexer, logger);
});
} Let me know what u think |
Beta Was this translation helpful? Give feedback.
-
Hi @LeaFrock I'm going to release a new version that is using the parallelization of the pool inizialization in few minutes. Thanks |
Beta Was this translation helpful? Give feedback.
-
For the default DI of .NET, the official doc recommends:
Keep DI factories fast and synchronous
.But the DI extension here has a related problem when using
PoolSize
:As the
IRedisDatabase
is a singleton, the initialization will be executed in a single thread withlock
.When creating
RedisClientFactory
,RedisConnectionPoolManager
needs to be created, whose constructor contains a method called EmitConnections:Notice the
for
code lines, it takes an obvious amount of time to finish.Suppose the following scenario:
IRedisDatabase
are calledIRedisDatabase
; others have to waitRecently I've met this kind of crash problem on IIS, while ASP.NET Core is in-process hosted with a 32-bit work process mode, which offers only 4G virtual memory. The app throws an
OutOfMemoryException
finally while starting, as long as the concurrency in the meanwhile is high enough.Beta Was this translation helpful? Give feedback.
All reactions