DEV Community

Alessandro Pio Ardizio
Alessandro Pio Ardizio

Posted on

Poolifier as Node.js thread/cluster pool

Back in the days there was no chance to have a custom thread pool in a Node.js application.
From Node.js version 10 ( experimental ) a great module was provided, the worker_threads module. 
Worker_threads module enables the use of threads that execute JavaScript in parallel.

The Beginning

Since that I am familiar with Java programming language, I immediately started to look for thread pool implementations just like are present in java.
There was only one small and not exhaustive thread pool at that time, so I started to implement poolifier.
I choosed to implement two thread pools, a fixed-size thread pool and a dynamic-size thread pool so that users could tune and choose which one fits better for their applications.

Growth of the poolifier project

Poolifier initially got some downloads and interest but when I really was not sharing to much about it, I found out that the number of downloads increased a lot, few months later users started to ask for new features and small fixes.

Community

Some contributions started to come into the project, in particular two people have being ( and still now are ) much much active to improve the project adding new features and enhancements.
By the way, special thanks to Shinigami92 and Jerome Benoit to help on the project so much !!!

Poolifier v2

All the commitment on the project resulted in a new fresh version with enhancements and new features.
New features
-Cluster pools( pools of processes) are now available
-New worker selection strategies available

Enhancements

  • Performance enhancements
  • Project re-written in typescript
  • Enhancement on internal code and variable names
  • Add static code analysis with Sonar, and changed coveralls in favor of Sonar, this also covers security
  • Production code minification for production to increase performances
  • Added unit test cases
  • Bug fixing

Benchmarks

While poolifier was growing, other people ( including some Node.js gurus ) implemented new thread pools, so currently there are more and more thread pool implementations.
Due to that we choosed to measure the performance on a CPU intensive task for each of the most used thread pools and those are our results.
We chose to use hyperfine because it allows to run isolated Node.js processes so that each pool does not impact each other.
External pools ( we choosed the most popular that we found ) with which we compared the poolifier results:

Those are our results running for each pool a CPU intensive task 100k times :

Alt Text

More info on how to run this benchmark on your own are available here.

Conclusion

So based on the benchmarks poolifier seems to be the fastest thread pool and well suited to run Node.js CPU intensive tasks and now it comes with fresh new features to try and an active community.
We will measure poolifier versus other pools with more and more task types ( that could fit better on processes pools instead of thread pools )going forward !!!
What you wait? Try poolifier! Leave a star, consider to contribute, ask a question !!!

Thanks to read this post, if you liked it please share.

Top comments (0)