Keycloak load users












2














I need to load all users from Keycloak and insert (cache) them into my system via keycloak-admin-client. While querying small number of users are pretty quick, the speed exponentially grows. Loading of 500 users takes 8 seconds, but 3000 users takes up to 4 minutes and I need to load 13k+. It seems like the methods search(search, first,max) and list(first,max) behaves same.



 kc.realm(realmName).users().list(0, count)


I thought that doing the loading by chunks (list(0,1000) then (list(1001,2000))) would solve the problem but it take exactly same time to load 0,2000 than 1001,2000, which seems like Keycloak is querying all the users from beginning and then doing substring.



The question is: how to do the bulk (chunk, iterative) load of all users from Keycloak to another system? I would like to avoid touching Keycloak DB directly.



Thanks










share|improve this question





























    2














    I need to load all users from Keycloak and insert (cache) them into my system via keycloak-admin-client. While querying small number of users are pretty quick, the speed exponentially grows. Loading of 500 users takes 8 seconds, but 3000 users takes up to 4 minutes and I need to load 13k+. It seems like the methods search(search, first,max) and list(first,max) behaves same.



     kc.realm(realmName).users().list(0, count)


    I thought that doing the loading by chunks (list(0,1000) then (list(1001,2000))) would solve the problem but it take exactly same time to load 0,2000 than 1001,2000, which seems like Keycloak is querying all the users from beginning and then doing substring.



    The question is: how to do the bulk (chunk, iterative) load of all users from Keycloak to another system? I would like to avoid touching Keycloak DB directly.



    Thanks










    share|improve this question



























      2












      2








      2







      I need to load all users from Keycloak and insert (cache) them into my system via keycloak-admin-client. While querying small number of users are pretty quick, the speed exponentially grows. Loading of 500 users takes 8 seconds, but 3000 users takes up to 4 minutes and I need to load 13k+. It seems like the methods search(search, first,max) and list(first,max) behaves same.



       kc.realm(realmName).users().list(0, count)


      I thought that doing the loading by chunks (list(0,1000) then (list(1001,2000))) would solve the problem but it take exactly same time to load 0,2000 than 1001,2000, which seems like Keycloak is querying all the users from beginning and then doing substring.



      The question is: how to do the bulk (chunk, iterative) load of all users from Keycloak to another system? I would like to avoid touching Keycloak DB directly.



      Thanks










      share|improve this question















      I need to load all users from Keycloak and insert (cache) them into my system via keycloak-admin-client. While querying small number of users are pretty quick, the speed exponentially grows. Loading of 500 users takes 8 seconds, but 3000 users takes up to 4 minutes and I need to load 13k+. It seems like the methods search(search, first,max) and list(first,max) behaves same.



       kc.realm(realmName).users().list(0, count)


      I thought that doing the loading by chunks (list(0,1000) then (list(1001,2000))) would solve the problem but it take exactly same time to load 0,2000 than 1001,2000, which seems like Keycloak is querying all the users from beginning and then doing substring.



      The question is: how to do the bulk (chunk, iterative) load of all users from Keycloak to another system? I would like to avoid touching Keycloak DB directly.



      Thanks







      java keycloak keycloak-services






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 16:02









      marc_s

      569k12811001250




      569k12811001250










      asked Nov 22 at 15:43









      troger19

      175214




      175214
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I just realized that the parameters are first and max, so in order to iterate over users I need to increase only the first number and let the second one remains same. So the request would looks like this with looping only parameter first by increasing it by 100



          http://localhost:8180/auth/admin/realms/demorealm/users/?first=5500&max=100





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434349%2fkeycloak-load-users%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I just realized that the parameters are first and max, so in order to iterate over users I need to increase only the first number and let the second one remains same. So the request would looks like this with looping only parameter first by increasing it by 100



            http://localhost:8180/auth/admin/realms/demorealm/users/?first=5500&max=100





            share|improve this answer


























              0














              I just realized that the parameters are first and max, so in order to iterate over users I need to increase only the first number and let the second one remains same. So the request would looks like this with looping only parameter first by increasing it by 100



              http://localhost:8180/auth/admin/realms/demorealm/users/?first=5500&max=100





              share|improve this answer
























                0












                0








                0






                I just realized that the parameters are first and max, so in order to iterate over users I need to increase only the first number and let the second one remains same. So the request would looks like this with looping only parameter first by increasing it by 100



                http://localhost:8180/auth/admin/realms/demorealm/users/?first=5500&max=100





                share|improve this answer












                I just realized that the parameters are first and max, so in order to iterate over users I need to increase only the first number and let the second one remains same. So the request would looks like this with looping only parameter first by increasing it by 100



                http://localhost:8180/auth/admin/realms/demorealm/users/?first=5500&max=100






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 20:19









                troger19

                175214




                175214






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434349%2fkeycloak-load-users%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)