Admin UI: slow response time listing second user page#45171
Admin UI: slow response time listing second user page#45171ahus1 merged 3 commits intokeycloak:mainfrom
Conversation
Fixes keycloak#44860 Signed-off-by: Pedro Ruivo <[email protected]>
|
@pruivo - great work, and also great documentation to show the results. The comment from @sguilhen reminded me that there might be one more possible optimization: If you do a So if one would rephrase the question from "give me the number of users" to "give me the number of users, but don't count more than X entries", At the same time, I think the results of this PR are good enough, and I'll be happy to fully review and merge it once the build is green. At the moment, it seems to be blocked by Maven central not returning artifacts reliably. |
|
@ahus1 unfortunately, you cannot do In any case, that trick is slower with my dataset (am I doing it right?). Using the PgAdmin explain feature, I get the following response times (the first one is the query that Hibernate creates)
|
|
@pruivo - thank you for the additional input. The SQL looks good, but explain vs the real execution might still differ. It might not make much of a different for 1 M users, maybe only when we go to 30 M users. Let's assume the current changes are good enough and proceed with PR as you originally suggested. |
Signed-off-by: Pedro Ruivo <[email protected]>
Signed-off-by: Alexander Schwartz <[email protected]>
ahus1
left a comment
There was a problem hiding this comment.
Hello Pedro thank you for the PR. I've reviewed it, and just moved one old comment and added one more comment about the "why" for the count.
This PR looks good to me and ready to be merged. If you agree and mark it as ready-to-review, I'll be happy to merge it. Thanks!
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.webauthn.passwordless.PasskeysUsernameFormTest#webauthnLoginWithDiscoverableKey_reauthentication |
Fixes #44860
Performance in local environment
I'm using a single Keycloak instance with PostgreSQL 17 running in Podman. I have a single realm and 1 million users. The time it takes to list the users is computed from the browser.
Baseline - main branch
About 1.6 seconds.
Only the
JpaUserProvideroptimizationThe reasoning behind this change is that
count distinctis an expensive operation for a database and can be skipped if the query does not involve any joins with other tables. I got a 5x faster response time.This Pull Request
I went a step further and modified
UserStorageManagerto minimize executing the count where possible. In my deployment, the count is skipped altogether. If LDAP or any other external user storage is available, the count is still invoked, but I "optimized" by avoiding invoking count on the last storage provider from the list 🤞.It is around 50x faster 🥳