Identity Server warmup #457
-
|
Hi, we have a constant load of multiple requests per second hitting our IdentityServer. When releasing our IdentityServer or scaling out, we notice that the first calls suffer from an increased latency. We have health probes implemented and traffic only arrives on the new instances once the health probes report healthy. I was wondering what we can do during startup to warmup the instance. Could we warmup the caches for example? Thanks in advance Jeroen |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
You can perform some tasks to help speed up incoming requests, yes. Preloading cached dataDuring the startup phase, after initializing IdentityServer's services and pipeline, you can preload the client and resource data. Note that var builder = WebApplication.CreateBuilder(args);
var app = builder
.ConfigureServices()
.ConfigurePipeline();
// Resolve a scope to retrieve an IClientStore and IResourceStore
await using (var scope = app.Services.CreateAsyncScope())
{
var clientStore = scope.ServiceProvider.GetRequiredService<IClientStore>();
string[] clientsToCache = ["client1", "client2"];
foreach (var clientId in clientsToCache)
{
// load and cache the most-requested clients by ID
await clientStore.FindEnabledClientByIdAsync(clientId);
}
// load and cache all identity resources, API scopes and API resources
var resourceStore = scope.ServiceProvider.GetRequiredService<IResourceStore>();
await resourceStore.GetAllResourcesAsync();
}
app.Run();Trigger the
|
Beta Was this translation helpful? Give feedback.
-
|
Hi @wcabus, Thanks for the input. I implemented preloading of resources, clients and keys in combination with a startup probe that reports healthy once the preloading is finished. That drastically improved the latency on the first calls after a release or after scaling out. To preload the keys I used the Kind regards Jeroen |
Beta Was this translation helpful? Give feedback.
You can perform some tasks to help speed up incoming requests, yes.
Preloading cached data
During the startup phase, after initializing IdentityServer's services and pipeline, you can preload the client and resource data. Note that
IClientStoredoes not offer a way to load (or cache) all client data at once, so I would only focus on the most-requested clients and cache those using their client ID: