We've developed a Node.js Express app which uses Handlebars as a templating engine.
The problem is that it uses a lot of CPU and we can't understand why.
For example, it uses 25% CPU on single thread for a single user request.
The process is ran on a 8 core/16 thread CPU i9 9900K, and with pm2 with maximum instances (so, 16 instances). 2 GBs of RAM are allocated, out of 64.
We use Redis, but not so intensively on the page which is loaded; we use MariaDB with Sequelize but in the requested page there are no queries, everything is in cache.
We also serve our static files from Nginx (pre-minified and bundled).
The only problem I think it could be, is the continuous JSON parsing from Redis results (we parse each Redis result), but I can't disable it to test, because it's needed to get data for the loading of the page.
Node version: v12.16.1
npm: v6.14.5
(with only few issues in audit, not regarding performance)
We also tried load testing using Loader.io and ab command.
Command used for load testing: $ ab -t 50 -n 1000 -c 1000 [link]
in external server
CPU with this command goes up to 100% in almost all threads.
From profiling I just can't understand what's the matter of the problem, everything seems to be only "LazyCompiling". I tried everything, and Node V8 profiling isn't helping.
Can someone help us read this V8 profile log and maybe help finding the bottleneck?
Or does someone have alternative profiling techniques?
V8 logs (tested in single thread, but in 16 threads it's the same): https://pastebin.com/9NhyUDZB