Several years ago, I was called out by a customer to help them resolve some performance issues they were having in their Node.js application. They wer

Optimise Node.js performance by avoiding broken promises

submited by
Style Pass
2021-06-05 15:00:07

Several years ago, I was called out by a customer to help them resolve some performance issues they were having in their Node.js application. They were experiencing massive event loop blocking issues in their server, getting a whole 5 requests per second — and, in one extreme case, an event loop delay of over one minute!

After reviewing some of the preliminary background details, the first question I asked them was simple: “Are you using Promises?” When they all looked at me and said “yes”, my immediate response, without even looking at their code first, was, “Then you’re likely using them wrong”. It was a bold statement. I spent the next three days onsite with them going through their code in detail helping to find the specific issues and proving that initial bold assertion correct — their codebase was full of misuses of promises and async await.

That engagement, and many more similar ones, prompted me to develop the “Broken Promises” workshop that Matteo Collina and I present to customers and periodically at conferences. Here, I want to pull back the curtain on that workshop just a bit to help folks better understand one of the most critical aspects of Node.js performance: Understanding how Node.js schedules asynchronous execution.

Leave a Comment