Optimizing asynchronous functions
The Node.js runtime was built with I/O in mind, hence its asynchronous programming model. In the previous recipes of this chapter, we have explored how to diagnose performance issues within synchronous JavaScript functions.
It is possible, however, that a performance bottleneck occurs as part of an asynchronous workflow. In this recipe, we'll cover profiling and optimizing an asynchronous performance problem.
Getting ready
In this recipe, we will be diagnosing a bottleneck in an Express.js web server that communicates with a MongoDB database. For more information on MongoDB, refer to the Connecting and Persisting to MongoDB recipe in Chapter 7, Working with Databases:
- To start MongoDB, we'll use Docker (as we did in Chapter 7, Working with Databases). Ensuring that you have Docker running, enter the following command in your Terminal to provision a MongoDB database:
$ docker run --publish 27017:27017 --name node-mongo -...