Optimizing Node.js App
Use Load Balancer
nginx is a great when it comes to serving concurrent requests.
If your app receives hundreds of thousands requests — nginx is a way to go.
Nginx will ensure that none of your servers is overworked, which definitely will cause performance issues.
There are few load balancing algorithms:
- Round Robin — Requests are distributed across the group of servers sequentially.
- Least Connections — A new request is sent to the server with the fewest current connections to clients. The relative computing capacity of each server is factored into determining which one has the least connections.
- IP Hash — The IP address of the client is used to determine which server receives the request.
Nginx is Asynchronous — each request in Nginx can be executed concurrently(non blockig manner).
So one of the ways to impove your Node app performance — is nginx in front of the app.
Optimize your additional resources
When the browser encounters `<script>` tag or css — it makes additional request to the server. So if, suppose, we have 3 script tags — th browser will make 3 requests for those ones and wait untill all of them are loaded.
The only exception might be in case if you use async attribute:
`<script src=”demo_async.js” async></script>`
When you use it — the script will work as soon as it fully loaded by the browser.
So one more way to optimize the app — concatenate all the scripts into a single file(there are greate tools for that such as gulp) — as well as css files.