I'm working on Node.js to build the server side RESTApi. Node works fine when I tested by myself. But when it is really out there it could still facing the overflow problems. When there are lots of requests, say there are more than 5 child_process (spawn) working at the same time, each process is taking longer time, basically slow down everything.
My idea is to check if the current process is below a certain limit (like, limit to 3 processes at a time), if it exceed the limit, I save the requests into an array, and whenever the current processes is below the limit, I use .shift() to pop the oldest one in the array and process it.
However when it comes to Promises, it becomes difficult as I don't know if we can store a Promise into an array or not, or whether I should simply let the process pause for seconds which I don't think it is a good idea.
What is the normal way if you want to hold a promise and return the promise to client in future?
Sorry if I didn't state this clear. Here is a summary of my doubts: 1. Can we save a promise for future use? 2. Do we save them in arrays? 3. Shall I use other methods to hold the promise, like, using sleep() or simply a while loop to wait until this process is proceed?
Thank you!