keycloak: Admin UI incredibly slow with 300 realms
Before reporting an issue
- I have searched existing issues
 - I have reproduced the issue with the latest release
 
Area
admin/ui
Describe the bug
Our setup consists of hundreds of reals.
Since updating to Keycloak 20.0.5 the admin ui takes a really long time to fetch the list of tenants for the dropdown.
I reviewed the requests visible in the developer tools of chrome and identified the following request:
$ time curl 'http://localhost:42300/auth/admin/realms?briefRepresentation=true'   -H 'Accept: application/json, text/plain, */*'   -H 'Accept-Language: en-US,en;q=0.9,de;q=0.8'   -H 'Authorization: bearer REDACTED'   -H 'Connection: keep-alive'   -H 'DNT: 1'   -H 'Sec-Fetch-Dest: empty'   -H 'Sec-Fetch-Mode: cors'   -H 'Sec-Fetch-Site: same-origin'   -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'   -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"'   -H 'sec-ch-ua-mobile: ?0'   -H 'sec-ch-ua-platform: "Linux"'   --compressed
[{"id":"01038bb4-9b26-451e-8943-89d2c31436d2","realm":"REDACTED","enabled":true},....]
real	1m47,238s
user	0m0,007s
sys	0m0,009s
As you can see, that requires over 107 seconds to fetch the 307 tenants of that system. Everytime i relogin to the master realm, i have to spend a few minutes 😃 (with Keycloak 17, this needed ~15 seconds)
Version
20.0.5
Expected behavior
Make the admin-ui usable with 3 seconds 😃
Actual behavior
See bug description
How to Reproduce?
Create 500 realms.
Anything else?
n/a
### Tasks
- [ ] https://github.com/keycloak/keycloak/issues/21555
- [ ] https://github.com/keycloak/keycloak/issues/21553
About this issue
- Original URL
 - State: closed
 - Created a year ago
 - Comments: 28 (16 by maintainers)
 
Thinking out load around many realms scalability in admin console. There seems to be two primary issues:
Listing realms due to realm drop-down - solution here I think is obvious and add pagination for the realms + some search/sever-side filtering
WhoAmI endpoint - honestly don’t know why it’s adding roles for all realms, as the admin console is only displaying one realm at a time. So perhaps this can be relatively easily resolved by the whoAmI endpoint returning only roles the admin has for the currently selected realm
There’s a few other things that may be issues with scaling large amounts of realms, but fixing those two issues should be a good start.
Another problem seems to be the
/auth/admin/master/console/whoamiit loads all realms with their permissions for the given user and also takes a very long time the more realms you have.closing as all tasks are done
A workaround is to not use the dropdown to switch to another realm, but instead type it in the address bar
We are experiencing the same issues. We have appx 300 realms now. Is there any known workarounds at the moment?
Should have checked the existing issues first. Seems like it is already known: https://github.com/keycloak/keycloak/issues/17455