Profiling memory
This chapter has mostly focused on CPU performance, but leaks can also be for overall performance or even cause downtime.
In this final recipe, we'll look at memory profiling and fixing a memory leak.
Getting ready
We'll be using Chrome Devtools in this recipe, so if we don't have Google Chrome Browser installed, we'll need to download and install the relevant binaries our operating system (head to https://www.google.com/chrome to get started).
If we haven't already installed autocannon
we'll be using it in this recipe:
$ npm install -g autocannon
We're going to profile a server that gives us a unique, Star Wars inspired name.
Let's create a folder and install relevant dependencies:
$ mkdir name-server
$ cd name-server
$ npm init -y
$ npm install --save starwars-names
Now we'll create a file called index.js
with the following code:
const http = require('http') const starwarsName = require('starwars-names').random const names = {} http.createServer((req, res) => { res.end...