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.

  • Avoiding port conflicts between docker-compose.yml configurations?
  • Ubuntu/UFW: How to tell Docker not to expose all ports?
  • Docker with a Rails App-Workers not running
  • How do I give an own ip address to docker for Windows container?
  • Docker. Connect from one container to another container with mysql
  • Deploying Flask app with Docker on Elastic Beanstalk: resource creation cancelled error
  • 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.

  • Installing on Ubuntu 14.04LTS
  • Error 500 when running exec start with Docker Remote API
  • Docker hanging requiring reboot
  • Is it recommended to run docker swarm on single node?
  • Does Kubernetes download Docker image automatically?
  • the approach to restore a pre-configured docker image
  • 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.