Bottleneck when using auth/admin/realms/myrealm/users in my app

I am running a script which requests the master token before requesting the list of users for a realm. I perform this request in a tight loop 100 times and output the time it takes to perform the "auth/admin/realms/mine/users?first=0&max=1000" request.

When testing with a locally installed keycloak docker, a single request is taking 4.0 seconds. If I run 5 instances of this script at the same time, a single request takes around 10 seconds.
And if I run 10 instances, it jumps to 20 seconds before a reply is received.

  • The command '/bin/sh -c sudo pip3 install -r requirements.txt' returned a non-zero code: 1
  • Multi Maven Module Spring MVC Project to Spring Boot
  • How do I uninstall docker-compose?
  • thrift + hbase exception (in docker containers)
  • docker postgres, fail to map volume in windows
  • Unable to start jetty container on Docker cloud
  • Therefore, I have a serious bottleneck in my webapp on the page where I list all user information and was wondering how I might go about solving this problem.

    I am running keycloak 2.5.0.Final. My java home is /usr/lib/jvm/java-1.8.0-openjdk- authorizationPersister = jpa.

    My script:

    import requests
    keyCloakUrl = ""
    for i in range(100):
        session = requests.Session()
        r =
            keyCloakUrl +"auth/realms/master/protocol/openid-connect/token", 
        master_token = json.loads(r.content)['access_token']
        r = s.get(
            keyCloakUrl + "auth/admin/realms/mine/users?first=0&max=1000",
            headers={'Authorization':'Bearer '+master_token}

    My dockerfile:

    FROM jboss/keycloak-mysql:2.5.0.Final
    ARG db2
    ADD deps/ /opt/jboss/keycloak/
    RUN /opt/jboss/keycloak/ 
    CMD ["-b", "", "-bmanagement", "", "-Djboss.socket.binding.port-offset=2"]


    I also tried measuring the time for the “auth/realms/master/protocol/openid-connect/token” request. This is 0.1 seconds per request with only one instance of the script running and 0.8 seconds with 10 instances running.

  • File Not Found when running Laravel with Nginx using LaraDock
  • Connect to mongodb on centos7 docker image
  • Call rabbitmq from nodejs
  • Docker/Dockerfile: Using ENTRYPOINT for git clone
  • docker-compose not picking updated code
  • Execute docker commands from java/jsp/html page
  • One Solution collect form web for “Bottleneck when using auth/admin/realms/myrealm/users in my app”

    Maybe it is a silly observation, but did you try to increase you JVM heap in your docker configs? Like:

    CMD java -XX:+PrintFlagsFinal -XX:+PrintGCDetails $JAVA_OPTIONS -jar java-container.jar

    There is a fantastic blog that explain the memory issue with the JVM and docker here

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.