[keycloak-dev] Fwd: All realms will all linked entities being read at bootstrap

Мартынов Илья imartynovsp at gmail.com
Wed Nov 27 02:25:29 EST 2019


Hello,

KC startups longer then default JBoss 5 min timeout and got rolled back,
~300 security realms created.
>From jstack, I see application is busy with multiple queries initiated by
all realms fetch
from org.keycloak.services.managers.UserStorageSyncManager#bootstrapPeriodic

Sequence is following:
 1. KeycloakApplication.setupScheduledTasks is called on bootstrap
 2. All realms are fetched inside UserStorageSyncManager#bootstrapPeriodic
 3. During each realm fetch, RealmEntity is wrapped to CachedRealm by
RealmCacheSession#getRealm
 4. In CachedRealm constructor, it reads all RealmEntity collections
 5. Sql selects fired for all RealmEntity collections
(RealmAttributeEntity, AuthenticationFlowEntity, RequiredCredentialEntity,
etc)

I see there was optimization to fetch only realms with user storages:
https://issues.jboss.org/browse/KEYCLOAK-8555. This didn't help me because
I have user federation provider in each realm.
Also I see hibernate 1st level cache clear was advised here:
https://github.com/keycloak/keycloak/pull/6012. This also did not help,
probably because too much data is being read.

I suggest to modify realm-extraction code at
UserStorageSyncManager#bootstrapPeriodic so it will select only required
info from DB. I am ready to develop this change, what do you think about it?


More information about the keycloak-dev mailing list