Async JS libraries benchmarks on AWS EC2

Jacopo Daeli
3 min readSep 27, 2016

Post previously featured on my old blog, posted on 01/17/2016.

I don’t want to write thousands of words about Async Javascript libraries performance. By the way, I benchmarked, using bluebird/benchmark, the most popular Async Javascript libraries on different AWS EC2 instance types. This article reports the results I obtained.

Introduction

What are promises ?

A Promise represents a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers to an asynchronous action’s eventual success value or failure reason [Mozilla documentation].
Promises provide a simpler alternative for executing, composing, and managing asynchronous operations when compared to traditional callback-based approaches.

Promises vs Callbacks

Before start with the real performance analysis, I want remember how more beautiful your code will look using promises instead callbacks.

Promises allow you to write this

fs.readFile('package.json', (err, val) => {  
if (err) return console.error(err.message)
try {
val = JSON.parse(val)
console.log(val.name)
} catch (e) {
console.error(e.message)
}
})

like this

fs.readFileAsync('package.json')  
.then(JSON.parse)
.then(val => console.log(val.name))
.catch(e => console.error(e.message))

where fs.readFileAsync return a Promise object.

Benchmarks

I benchmarked both sequential and parallel async operations on three different AWS EC2 instances type: t2.small, m4.large and c3.8xlarge.

Sequential

Sequential — t2.small
Sequential — m4.large
Sequential — c3.8xlarge

Parallel

Parallel — t2.small
Parallel — m4.large
Parallel — c3.8xlarge

Conclusion

Logically, native callbacks are the most performant. Unfortunately writing applications using only callback can easily get very messy.

Native ES6 promises are far to be performant. The best of the performance is achieved using bluebird promises and neo-async.

Because I think Promises control flow is the cleanest one, bluebird seems to me the best choice for handling async operations in Javascript today when performance is required.

When performance is not required, and you want to reduce the number of dependencies in your project, Native ES6 promises are definitely the answer.

--

--

Jacopo Daeli

I’m a Computer Scientist, Software Engineer and Hacker, passionate about web technologies with a vocation for writing beautiful and clean code.