[Node.js] Pending HTTP requests lead to unresponsive nodeJS
This is a recap conclusion to the potential problems of a NodeJS program I worked on previously.
The program simulates thousands of clients navigating a website by sending thousands of http requests to a given API. The idea is to load test a particular API to make sure they can handle high traffic. Because we are simulating clients, it's important to keep track of the state of the simulated client as well. The problem with this program is it is buggy and becomes unresponsive from time to time (the only solution is to restart it). The problem was fixed by re-writing the entire program in Java, but it was regretful that I never had enough time to find the exact reason the nodeJS version of it failed.
The following are potential causes I suspect:
It is arguable that this can be solved by debugging and rewriting the code.
The program simulates thousands of clients navigating a website by sending thousands of http requests to a given API. The idea is to load test a particular API to make sure they can handle high traffic. Because we are simulating clients, it's important to keep track of the state of the simulated client as well. The problem with this program is it is buggy and becomes unresponsive from time to time (the only solution is to restart it). The problem was fixed by re-writing the entire program in Java, but it was regretful that I never had enough time to find the exact reason the nodeJS version of it failed.
The following are potential causes I suspect:
1. Exceptions
The NodeJS program was not written very neatly and stacked callbacks on top of callbacks on top of callbacks. This made it very difficult to keep track of exceptions and unexpected http responses are prone to happen. Sometimes, it is possible for an error to be uncaught and bubble to the core(topmost) Node.js event loop, which causes the NodeJS instance to terminate (crashing the program).It is arguable that this can be solved by debugging and rewriting the code.
2. File Descriptors Limit
When my nodeJS program sends thousands of request, many of the http responses might be slow or unresponsive if the API server is slow in replying the high traffic load. Because of this, the program might have reached the max file descriptors. File Descriptors can include a handle to an input or output resource, such as an network connection. The default limit of file descriptors a process can use is 1024, and a possible solution is to set it to unlimited.
It's important to note that if you are serving HTTP requests with HTTP responses, the file descriptors should open and close quickly. However, in my nodeJS program, I was sending a lot of requests at once, and therefore, it might not have open and closed fast enough. A potential solution is to request the same amount of requests, but in a longer period of time.
It is arguable that this can be solved by adding timeouts and better HTTP request options.
https://stackoverflow.com/questions/17033631/node-js-maxing-out-at-1000-concurrent-connections
https://stackoverflow.com/questions/23977693/node-js-concurrent-connection-limit
https://developer.ibm.com/technologies/node-js/articles/6-reasons-your-node-js-apps-are-failing/
https://stackoverflow.com/questions/42317561/node-app-unresponsive-after-certain-amount-of-time
It's important to note that if you are serving HTTP requests with HTTP responses, the file descriptors should open and close quickly. However, in my nodeJS program, I was sending a lot of requests at once, and therefore, it might not have open and closed fast enough. A potential solution is to request the same amount of requests, but in a longer period of time.
It is arguable that this can be solved by adding timeouts and better HTTP request options.
Conclusion
So I guess there's no actual reason to rewrite the program to Java. The only reason that makes sense is that the team had more Java developers, and no NodeJS/Javascript developers.
Resource:
https://www.imakewebsites.ca/posts/2018/03/06/node.js-too-many-open-files-and-ulimit/https://stackoverflow.com/questions/17033631/node-js-maxing-out-at-1000-concurrent-connections
https://stackoverflow.com/questions/23977693/node-js-concurrent-connection-limit
https://developer.ibm.com/technologies/node-js/articles/6-reasons-your-node-js-apps-are-failing/
https://stackoverflow.com/questions/42317561/node-app-unresponsive-after-certain-amount-of-time
Comments
Post a Comment