I need an understanding and code architecture of how to run a time consuming web service in a separate child process. Is it good to run in a separate child process such kind of web service which will run longer. The web service will receive a pay load of upto like 2000 nested json objects, numbers could be less or more, and it will fetch the data and insert into the database. Below is just the code snippet just to give an idea.
router.post('/longRunningWebservice', function (req, res) {
//for loop to iterate 2000 json objects
//it has some queries to insert data
//it has some if conditions to check
//and finally res.send()
});
I need to understand and want to run the the code in a separate child process to make it more scalable, and also utilize the other cores.
other notes:
additional approach: Fork workers with all the same tasks (handle http and data processing), cluster will automatically handle load ballance and instead of for loop create a recursive function which process a single json object then call itself with setimmediate so the data processing will not block event loop and a single worker can handle multiple requests. easy way
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.