Skip to content

registerUserKeys takes long time to finish in large environment #14957

Backlog

Description

@weizhouapache

problem

registerUserKeys takes several minutes to finish in an environment with a large number of users, while getUserKeys for the same user returns in a few seconds.

In the management server log of a slow request there are two gaps of about 105 seconds each. Creating the key pair itself takes less than 0.1 seconds.

The cause is in RegisterUserKeysCmd.getEntityOwnerId(). It calls QueryService.searchForAccessibleUsers(), which loads every visible user (no pagination) and, for each user, runs two DB lookups and a role-type check. The cost is linear in the number of users. See the comment below for details and measurements.

versions

ACS 4.23

The steps to reproduce the bug

  1. Have an environment with a large number of users (tens of thousands).
  2. Call registerUserKeys with the id of any user, as root admin.
  3. Compare with getUserKeys for the same user.

Expected: both return quickly.
Actual: registerUserKeys takes minutes. In a test environment it grew from about 1.7 s with 5 users to about 5.5 s with 3,000 users.

What to do about it?

Check only the target user in getEntityOwnerId() instead of listing all accessible users.

Activity

  1. weizhouapache commented on Dec 2, 2026

    @weizhouapache
    MemberAuthor

    Root cause

    This comes from the API key pair restructure (#9504), which introduced searchForAccessibleUsers() and its use in RegisterUserKeysCmd.getEntityOwnerId().

    RegisterUserKeysCmd.getEntityOwnerId() calls QueryService.searchForAccessibleUsers() only to check whether the target user is accessible. That method loads every visible user and, for each one, does two DB lookups plus a role-type check, so the cost is linear in the number of users. GetUserKeysCmd.getEntityOwnerId() only does a single findById.

    In the log of a slow request (root admin caller) there are two ~105 s gaps, one per evaluation of getEntityOwnerId(); creating the key pair takes < 0.1 s.

    Reproduction

    registerUserKeys (root admin) in a test environment:

    active users 5 1005 2005 3005
    time 1.65 s 2.90 s 4.48 s 5.46 s

    A linear fit gives about 1.36 ms per user. Extrapolated (not measured) per request:

    active users 10,000 30,000 50,000 70,000
    estimated time ~15 s ~43 s ~70 s ~97 s

    Real environments can be slower (DB latency, hardware); the reported ~3-4 minutes is in line with this order of magnitude. Non-root callers also pay ~5 s for checkRoleEscalation, which depends on role permissions.

    Proposed fix

    Check only the target user in getEntityOwnerId() (e.g. validateCallingUserHasAccessToDesiredUser). Not yet validated on a large data set.

  2. changed the title [-]registerUserKeys takes long time to finish in large env[/-] [+]registerUserKeys takes long time to finish in large environment[/+] on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions