O'Reilly logo

TypeScript Microservices by Parth Ghiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CPU profiling

Chrome Developer Tools has some very nice options that are not just limited to debugging. We can also leverage memory allocation, CPU profiling, and so on. Let's dig deep into CPU profiling. For the sake of understanding the tool, we will spin up a program that consumes heavy CPU usage:

  1. Create any express app and create one random route, which basically iterates 100 times and allocates a buffer 108 in the memory. You can follow the code in chapter 8/cpu-profiling-demo:
private $alloc(){  Buffer.alloc(1e8, 'Z');}router.get('/check-mem',  (req, res, next) => {    let check = 100;    while (check--) {      this.$alloc()    }    res.status(200).send('I am Done');  })
  1. The next step is to run the Node.js process in Chrome DevTools. To do so, just ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required