When configuring RetryOnFailure what is the maxRetryDelay parameter

entity-framework-core

Question

I'm using Entity Framework Core 2.2 and i decided to follow some blog sugestion and enable retry on failure:

services.AddDbContext<MyDbContext>( options =>
    options.UseSqlServer(Configurations["ConnectionString"]),
    sqlServerOptionsAction: sqlOptions =>
    {
        sqlOptions.EnableRetryOnFailure(
        maxRetryCount: 10,
        maxRetryDelay: TimeSpan.FromSeconds(5),
        errorNumbersToAdd: null);
    });

My question is what is the maxRetryDelay argument for? I would expect it to be the delay time between retries, but the name implies its the maximum time, does that mean i can do my 10 retries 1 second apart and not 5 seconds apart as i desire?

1
2
4/24/2019 9:45:46 AM

Accepted Answer

The delay between retries is randomized up to the value specified by maxRetryDelay.

This is done to avoid multiple retries occuring at the same time and overwhelming a server. Imagine for example 10K requests to a web service failing due to a network issue and retrying at the same time after 15 seconds. The database server would get a sudden wave of 15K queries.

By randomizing the delay, retries are spread across time and client.

The delay for each retry is calculated by ExecutionStragegy.GetNextDelay. The source shows it's a random exponential backoff.

The default SqlServerRetryingExecutionStrategy uses that implementation. A custom retry strategy could use a different implementation

3
4/24/2019 10:21:16 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow