I am working with a Node server (running on Node 8) that runs using Express. This server only serves static files (with the express.static
middleware). This configuration is given to it upon startup:
node --max-http-header-size=16384 dist/myServer.js
This server receives thousands of requests every minute, and recently, each request has close to 16k sized headers.
Our server has had much higher CPU usage than usual lately - could this be a consequence of sending too many headers in each of our requests? What are the consequences of sending large amounts of headers in HTTP requests to a Node server?
CodePudding user response:
Sending lots of large headers causes the following:
- More memory used for each incoming http request
- More network bandwidth used for each incoming http request
- More CPU used to read and parse the headers on each incoming http request
- Since headers are typically parsed into smaller pieces, this means more memory allocations and then subsequently more garbage collection which can also result in more CPU usage.
I'm just wondering if this could be the cause of our recent CPU usage spiking lately, and if it's worth it to investigate lowering the number of headers sent to this server.
Yes, it is worth investigating whether these are contributing to your usage spike as lots of headers that you don't actually need are definitely contributing to wasted resources by your server. How much they are contributing is hard to say.
As a test, you could configure an nginx proxy in front of your server that is configured to strip all the headers you don't need before passing them to your server and see how much that changes your server load.
Or if you have any control over the existing reverse proxy, then modify its configuration to remove the headers you don't need.