How many request we can make at a time using “request” middle ware in nodeJS application












0















I am running a cron job every 5 mins to get data from 3rd party API, It can be N number of request at a time from NodeJS application. Below are the details and code samples:



1> Running cron Job every 5 mins:



const cron = require('node-cron');
const request = require('request');
const otherServices= require('./services/otherServices');
cron.schedule("0 */5 * * * *", function () {
initiateScheduler();
});


2> Get the list of elements for which I want to initiate the request. Can receive N number of elements. I have called request function (getSingleElementUpdate()) in the forEach loop



var initiateScheduler = function () {
//Database call to get elements list
otherServices.moduleName()
.then((arrayList) => {
arrayList.forEach(function (singleElement, index) {
getSingleElementUpdate(singleElement, 1);
}, this);
})
.catch((err) => {
console.log(err);
})
}


3> Start initiating the request for singleElement. Please note I don't need any callback if I received a successful (200) response from the request. I just have to update my database entries on success.



var getSingleElementUpdate = function (singleElement, count) {
var bodyReq = {
"id": singleElement.elem_id
}
var options = {
method: 'POST',
url: 'http://example.url.com',
body: bodyReq,
dataType: 'json',
json: true,
crossDomain: true
};
request(options, function (error, response, body) {
if (error) {
if (count < 3) {
count = count + 1;
initiateScheduler(singleElement, count)
}
} else{
//Request Success
//In this: No callback required
// Just need to update database entries on successful response
}
});
}


I have already checked this:



request-promise: But, I don't need any callback after a successful request. So, I didn't find any advantage of implementing this in my code. Let me know if you have any positive point to add this.



I need your help with the following things:



I have checked the performance when I received 10 elements in arrayList of step 2. Now, the problem is I don't have any clear vision about what will happen when I start receiving 100 and 1000 of elements in step 2. So, I need your help in determining whether I need to update my code for that scenario or not or is there anything I missed out which degrade the performance. Also, How many maximum requests I can make at a time. Any help from you is appreciable.



Thanks!










share|improve this question





























    0















    I am running a cron job every 5 mins to get data from 3rd party API, It can be N number of request at a time from NodeJS application. Below are the details and code samples:



    1> Running cron Job every 5 mins:



    const cron = require('node-cron');
    const request = require('request');
    const otherServices= require('./services/otherServices');
    cron.schedule("0 */5 * * * *", function () {
    initiateScheduler();
    });


    2> Get the list of elements for which I want to initiate the request. Can receive N number of elements. I have called request function (getSingleElementUpdate()) in the forEach loop



    var initiateScheduler = function () {
    //Database call to get elements list
    otherServices.moduleName()
    .then((arrayList) => {
    arrayList.forEach(function (singleElement, index) {
    getSingleElementUpdate(singleElement, 1);
    }, this);
    })
    .catch((err) => {
    console.log(err);
    })
    }


    3> Start initiating the request for singleElement. Please note I don't need any callback if I received a successful (200) response from the request. I just have to update my database entries on success.



    var getSingleElementUpdate = function (singleElement, count) {
    var bodyReq = {
    "id": singleElement.elem_id
    }
    var options = {
    method: 'POST',
    url: 'http://example.url.com',
    body: bodyReq,
    dataType: 'json',
    json: true,
    crossDomain: true
    };
    request(options, function (error, response, body) {
    if (error) {
    if (count < 3) {
    count = count + 1;
    initiateScheduler(singleElement, count)
    }
    } else{
    //Request Success
    //In this: No callback required
    // Just need to update database entries on successful response
    }
    });
    }


    I have already checked this:



    request-promise: But, I don't need any callback after a successful request. So, I didn't find any advantage of implementing this in my code. Let me know if you have any positive point to add this.



    I need your help with the following things:



    I have checked the performance when I received 10 elements in arrayList of step 2. Now, the problem is I don't have any clear vision about what will happen when I start receiving 100 and 1000 of elements in step 2. So, I need your help in determining whether I need to update my code for that scenario or not or is there anything I missed out which degrade the performance. Also, How many maximum requests I can make at a time. Any help from you is appreciable.



    Thanks!










    share|improve this question



























      0












      0








      0








      I am running a cron job every 5 mins to get data from 3rd party API, It can be N number of request at a time from NodeJS application. Below are the details and code samples:



      1> Running cron Job every 5 mins:



      const cron = require('node-cron');
      const request = require('request');
      const otherServices= require('./services/otherServices');
      cron.schedule("0 */5 * * * *", function () {
      initiateScheduler();
      });


      2> Get the list of elements for which I want to initiate the request. Can receive N number of elements. I have called request function (getSingleElementUpdate()) in the forEach loop



      var initiateScheduler = function () {
      //Database call to get elements list
      otherServices.moduleName()
      .then((arrayList) => {
      arrayList.forEach(function (singleElement, index) {
      getSingleElementUpdate(singleElement, 1);
      }, this);
      })
      .catch((err) => {
      console.log(err);
      })
      }


      3> Start initiating the request for singleElement. Please note I don't need any callback if I received a successful (200) response from the request. I just have to update my database entries on success.



      var getSingleElementUpdate = function (singleElement, count) {
      var bodyReq = {
      "id": singleElement.elem_id
      }
      var options = {
      method: 'POST',
      url: 'http://example.url.com',
      body: bodyReq,
      dataType: 'json',
      json: true,
      crossDomain: true
      };
      request(options, function (error, response, body) {
      if (error) {
      if (count < 3) {
      count = count + 1;
      initiateScheduler(singleElement, count)
      }
      } else{
      //Request Success
      //In this: No callback required
      // Just need to update database entries on successful response
      }
      });
      }


      I have already checked this:



      request-promise: But, I don't need any callback after a successful request. So, I didn't find any advantage of implementing this in my code. Let me know if you have any positive point to add this.



      I need your help with the following things:



      I have checked the performance when I received 10 elements in arrayList of step 2. Now, the problem is I don't have any clear vision about what will happen when I start receiving 100 and 1000 of elements in step 2. So, I need your help in determining whether I need to update my code for that scenario or not or is there anything I missed out which degrade the performance. Also, How many maximum requests I can make at a time. Any help from you is appreciable.



      Thanks!










      share|improve this question
















      I am running a cron job every 5 mins to get data from 3rd party API, It can be N number of request at a time from NodeJS application. Below are the details and code samples:



      1> Running cron Job every 5 mins:



      const cron = require('node-cron');
      const request = require('request');
      const otherServices= require('./services/otherServices');
      cron.schedule("0 */5 * * * *", function () {
      initiateScheduler();
      });


      2> Get the list of elements for which I want to initiate the request. Can receive N number of elements. I have called request function (getSingleElementUpdate()) in the forEach loop



      var initiateScheduler = function () {
      //Database call to get elements list
      otherServices.moduleName()
      .then((arrayList) => {
      arrayList.forEach(function (singleElement, index) {
      getSingleElementUpdate(singleElement, 1);
      }, this);
      })
      .catch((err) => {
      console.log(err);
      })
      }


      3> Start initiating the request for singleElement. Please note I don't need any callback if I received a successful (200) response from the request. I just have to update my database entries on success.



      var getSingleElementUpdate = function (singleElement, count) {
      var bodyReq = {
      "id": singleElement.elem_id
      }
      var options = {
      method: 'POST',
      url: 'http://example.url.com',
      body: bodyReq,
      dataType: 'json',
      json: true,
      crossDomain: true
      };
      request(options, function (error, response, body) {
      if (error) {
      if (count < 3) {
      count = count + 1;
      initiateScheduler(singleElement, count)
      }
      } else{
      //Request Success
      //In this: No callback required
      // Just need to update database entries on successful response
      }
      });
      }


      I have already checked this:



      request-promise: But, I don't need any callback after a successful request. So, I didn't find any advantage of implementing this in my code. Let me know if you have any positive point to add this.



      I need your help with the following things:



      I have checked the performance when I received 10 elements in arrayList of step 2. Now, the problem is I don't have any clear vision about what will happen when I start receiving 100 and 1000 of elements in step 2. So, I need your help in determining whether I need to update my code for that scenario or not or is there anything I missed out which degrade the performance. Also, How many maximum requests I can make at a time. Any help from you is appreciable.



      Thanks!







      javascript node.js request






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 6:55







      Anand Vaidya

















      asked Nov 28 '18 at 5:03









      Anand VaidyaAnand Vaidya

      1901223




      1901223
























          1 Answer
          1






          active

          oldest

          votes


















          1














          AFAIK there is no hard limit on a number of request. However, there are (at least) two things to consider: your hardware limits (memory/CPU) and remote server latency (is it able to respond to all requests in 5 mins before the next batch). Without knowing the context it's also impossible to predict what scaling mechanism you might need.



          The question is actually more about app architecture and not about some specific piece of code, so you might want to try softwareengineering instead of SO.






          share|improve this answer
























          • Yes, You are right I must try asking there. Thanks! :)

            – Anand Vaidya
            Nov 28 '18 at 9:38













          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%2f53512457%2fhow-many-request-we-can-make-at-a-time-using-request-middle-ware-in-nodejs-app%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









          1














          AFAIK there is no hard limit on a number of request. However, there are (at least) two things to consider: your hardware limits (memory/CPU) and remote server latency (is it able to respond to all requests in 5 mins before the next batch). Without knowing the context it's also impossible to predict what scaling mechanism you might need.



          The question is actually more about app architecture and not about some specific piece of code, so you might want to try softwareengineering instead of SO.






          share|improve this answer
























          • Yes, You are right I must try asking there. Thanks! :)

            – Anand Vaidya
            Nov 28 '18 at 9:38


















          1














          AFAIK there is no hard limit on a number of request. However, there are (at least) two things to consider: your hardware limits (memory/CPU) and remote server latency (is it able to respond to all requests in 5 mins before the next batch). Without knowing the context it's also impossible to predict what scaling mechanism you might need.



          The question is actually more about app architecture and not about some specific piece of code, so you might want to try softwareengineering instead of SO.






          share|improve this answer
























          • Yes, You are right I must try asking there. Thanks! :)

            – Anand Vaidya
            Nov 28 '18 at 9:38
















          1












          1








          1







          AFAIK there is no hard limit on a number of request. However, there are (at least) two things to consider: your hardware limits (memory/CPU) and remote server latency (is it able to respond to all requests in 5 mins before the next batch). Without knowing the context it's also impossible to predict what scaling mechanism you might need.



          The question is actually more about app architecture and not about some specific piece of code, so you might want to try softwareengineering instead of SO.






          share|improve this answer













          AFAIK there is no hard limit on a number of request. However, there are (at least) two things to consider: your hardware limits (memory/CPU) and remote server latency (is it able to respond to all requests in 5 mins before the next batch). Without knowing the context it's also impossible to predict what scaling mechanism you might need.



          The question is actually more about app architecture and not about some specific piece of code, so you might want to try softwareengineering instead of SO.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 9:06









          Anton PastukhovAnton Pastukhov

          1978




          1978













          • Yes, You are right I must try asking there. Thanks! :)

            – Anand Vaidya
            Nov 28 '18 at 9:38





















          • Yes, You are right I must try asking there. Thanks! :)

            – Anand Vaidya
            Nov 28 '18 at 9:38



















          Yes, You are right I must try asking there. Thanks! :)

          – Anand Vaidya
          Nov 28 '18 at 9:38







          Yes, You are right I must try asking there. Thanks! :)

          – Anand Vaidya
          Nov 28 '18 at 9:38






















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53512457%2fhow-many-request-we-can-make-at-a-time-using-request-middle-ware-in-nodejs-app%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

          Lallio

          Futebolista

          Jornalista