<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alessandro Pio Ardizio</title>
    <description>The latest articles on DEV Community by Alessandro Pio Ardizio (@pioardi).</description>
    <link>https://dev.to/pioardi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F302726%2Fc9f93dcc-7aa7-4d21-83ef-fba59364fcb0.jpeg</url>
      <title>DEV Community: Alessandro Pio Ardizio</title>
      <link>https://dev.to/pioardi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pioardi"/>
    <language>en</language>
    <item>
      <title>Poolifier as Node.js thread/cluster pool</title>
      <dc:creator>Alessandro Pio Ardizio</dc:creator>
      <pubDate>Tue, 02 Mar 2021 07:29:07 +0000</pubDate>
      <link>https://dev.to/pioardi/poolifier-as-node-js-thread-cluster-pool-4onh</link>
      <guid>https://dev.to/pioardi/poolifier-as-node-js-thread-cluster-pool-4onh</guid>
      <description>&lt;p&gt;Back in the days there was no chance to have a custom thread pool in a Node.js application.&lt;br&gt;
From Node.js version 10 ( experimental ) a great module was provided, the &lt;a href="https://nodejs.org/docs/latest-v14.x/api/worker_threads.html" rel="noopener noreferrer"&gt;worker_threads&lt;/a&gt; module. &lt;br&gt;
Worker_threads module enables the use of threads that execute JavaScript in parallel.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Beginning
&lt;/h2&gt;

&lt;p&gt;Since that I am familiar with Java programming language, I immediately started to look for thread pool implementations just like are present in &lt;a href="https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html" rel="noopener noreferrer"&gt;java&lt;/a&gt;.&lt;br&gt;
There was only one small and not exhaustive thread pool at that time, so I started to implement &lt;a href="https://github.com/pioardi/poolifier" rel="noopener noreferrer"&gt;poolifier&lt;/a&gt;.&lt;br&gt;
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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Growth of the poolifier project
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Community
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
By the way, special thanks to &lt;a href="https://github.com/Shinigami92" rel="noopener noreferrer"&gt;Shinigami92&lt;/a&gt; and &lt;a href="https://github.com/jerome-benoit" rel="noopener noreferrer"&gt;Jerome Benoit&lt;/a&gt; to help on the project so much !!!&lt;/p&gt;

&lt;h2&gt;
  
  
  Poolifier v2
&lt;/h2&gt;

&lt;p&gt;All the commitment on the project resulted in a new fresh version with enhancements and new features.&lt;br&gt;
&lt;strong&gt;New features&lt;/strong&gt;&lt;br&gt;
-Cluster pools( pools of processes) are now available&lt;br&gt;
-New worker selection strategies available&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enhancements&lt;/strong&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Benchmarks
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
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.&lt;br&gt;
We chose to use hyperfine because it allows to run isolated Node.js processes so that each pool does not impact each other.&lt;br&gt;
External pools ( we choosed the most popular that we found ) with which we compared the poolifier results:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/piscinajs/piscina" rel="noopener noreferrer"&gt;piscina&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SUCHMOKUO/node-worker-threads-pool" rel="noopener noreferrer"&gt;SUCHMOKUO/node-worker-threads-pool&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/andywer/threads.js" rel="noopener noreferrer"&gt;threads.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are our results running for each pool a CPU intensive task 100k times :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F222p2549rvjws0trv544.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F222p2549rvjws0trv544.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More info on how to run this benchmark on your own are available &lt;a href="https://github.com/pioardi/poolifier/blob/master/benchmarks/README.md" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
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 !!!&lt;br&gt;
What you wait? Try poolifier! Leave a star, consider to contribute, ask a question !!!&lt;/p&gt;

&lt;p&gt;Thanks to read this post, if you liked it please share.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>performance</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Node js | Thread pool implementations</title>
      <dc:creator>Alessandro Pio Ardizio</dc:creator>
      <pubDate>Thu, 23 Jan 2020 09:33:27 +0000</pubDate>
      <link>https://dev.to/pioardi/node-js-thread-pool-implementations-1j41</link>
      <guid>https://dev.to/pioardi/node-js-thread-pool-implementations-1j41</guid>
      <description>&lt;p&gt;I develop two thread pool on top on worker_threads that you can use with an high level API &lt;a href="https://github.com/pioardi/poolifier"&gt;https://github.com/pioardi/poolifier&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;This project contain two thread pool implementations :&lt;/p&gt;

&lt;p&gt;The first implementation is a static thread pool , with a defined number of threads that are started at creation time and will be reused.&lt;/p&gt;

&lt;p&gt;The second implementation is a dynamic thread pool with a number of threads started at creation time ( these threads will be always active and reused) and other threads created when the load will increase ( with an upper limit, these threads will be reused when active ), the new created threads will be stopped after a configurable period of inactivity.&lt;/p&gt;

&lt;p&gt;I need your feedbacks and I would like your contribution on my project :)&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>github</category>
    </item>
    <item>
      <title>Nodejs | Thread pool implementations</title>
      <dc:creator>Alessandro Pio Ardizio</dc:creator>
      <pubDate>Wed, 22 Jan 2020 23:04:17 +0000</pubDate>
      <link>https://dev.to/pioardi/nodejs-thread-pool-implementations-41po</link>
      <guid>https://dev.to/pioardi/nodejs-thread-pool-implementations-41po</guid>
      <description>&lt;h1&gt;
  
  
  Node Thread Pool ⏫ 🔛
&lt;/h1&gt;

&lt;p&gt;Nodejs introduced worker_threads module to allow a better use of nodejs for CPU intensive tasks, but there is no official thread pool that allow to reuse threads. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;So I develop two thread pool on top on worker_threads that you can use with an high level API &lt;a href="https://github.com/pioardi/poolifier"&gt;https://github.com/pioardi/poolifier&lt;/a&gt; . &lt;br&gt;&lt;/p&gt;

&lt;p&gt;This project contain two thread pool implementations : &lt;br&gt;&lt;br&gt;
The first implementation is a static thread pool , with a defined number of threads that are started at creation time and will be reused.&lt;br&gt;&lt;br&gt;
The second implementation is a dynamic thread pool with a number of threads started at creation time ( these threads will be always active and reused) and other threads created when the load will increase ( with an upper limit, these threads will be reused when active ), the new created threads will be stopped after a configurable period of inactivity. &lt;br&gt;&lt;br&gt;
You have to implement your worker extending the ThreadWorker class&lt;br&gt;&lt;/p&gt;

&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install poolifier --save
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;h2 id="usage"&gt;Usage&lt;/h2&gt;

&lt;p&gt;You can implement a worker in a simple way , extending the class ThreadWorker :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ThreadWorker&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;poolifier&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;yourFunction&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// this will be executed in the worker thread,&lt;/span&gt;
  &lt;span class="c1"&gt;// the data will be received by using the execute method&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;MyWorker&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;ThreadWorker&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;yourFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;maxInactiveTime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;MyWorker&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Instantiate your pool based on your needed :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FixedThreadPool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;DynamicThreadPool&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;poolifier&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// a fixed thread pool&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;FixedThreadPool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./yourWorker.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;errorHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;onlineHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;worker is online&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// or a dynamic thread pool&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;DynamicThreadPool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./yourWorker.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;errorHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;onlineHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;worker is online&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;FullPool&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pool is full&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;// the execute method signature is the same for both implementations,&lt;/span&gt;
&lt;span class="c1"&gt;// so you can easy switch from one to another&lt;/span&gt;
&lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;({}).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;....&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;h2&gt;Considerations&lt;/h2&gt;
&lt;br&gt;
Performance is one of the main target of these thread pool implementations, we want to have a strong focus on this.&lt;br&gt;&lt;br&gt;
We already have a bench folder where you can find some comparisons.&lt;br&gt;
To choose your pool consider that with a FixedThreadPool or a DynamicThreadPool ( in this case is important the min parameter passed to the constructor) your application memory footprint will increase . &lt;br&gt;&lt;br&gt;
Increasing the memory footprint, your application will be ready to accept more CPU bound tasks, but during idle time your application will consume more memory. &lt;br&gt;&lt;br&gt;
One good choose from my point of view is to profile your application using Fixed/Dynamic thread pool , and to see your application metrics when you increase/decrease the num of threads. &lt;br&gt;&lt;br&gt;
For example you could keep the memory footprint low choosing a DynamicThreadPool with 5 threads, and allow to create new threads until 50/100 when needed, this is the advantage to use the DynamicThreadPool. &lt;br&gt;&lt;br&gt;
But in general , &lt;strong&gt;always profile your application &lt;/strong&gt;

&lt;h2&gt; Contribute &lt;/h2&gt;

&lt;p&gt;Pull requests, contributors and feedbacks are welcome , join the project :) &lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>workers</category>
    </item>
    <item>
      <title>Open source project feedbacks</title>
      <dc:creator>Alessandro Pio Ardizio</dc:creator>
      <pubDate>Sat, 04 Jan 2020 19:01:07 +0000</pubDate>
      <link>https://dev.to/pioardi/open-source-project-feedbacks-3ajc</link>
      <guid>https://dev.to/pioardi/open-source-project-feedbacks-3ajc</guid>
      <description>&lt;p&gt;Could you please give me some feedback on this project &lt;a href="https://github.com/pioardi/ring-election"&gt;https://github.com/pioardi/ring-election&lt;/a&gt;  ? &lt;/p&gt;

&lt;p&gt;I would like people to build something great on top of this !&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>github</category>
      <category>githunt</category>
      <category>node</category>
    </item>
    <item>
      <title>How to build high available/fault-tolerant services in node.js</title>
      <dc:creator>Alessandro Pio Ardizio</dc:creator>
      <pubDate>Fri, 03 Jan 2020 10:41:30 +0000</pubDate>
      <link>https://dev.to/pioardi/how-to-build-high-available-fault-tolerant-services-in-node-js-5adb</link>
      <guid>https://dev.to/pioardi/how-to-build-high-available-fault-tolerant-services-in-node-js-5adb</guid>
      <description>&lt;h1&gt;
  
  
  How to build high available/fault-tolerant services in node.js
&lt;/h1&gt;

&lt;p&gt;During my job for an important client , I was thinking about high availability and recovery NFRs , our tech stack included cassandra and kafka , two distributed systems of which I studied internal behavior.&lt;br&gt;
&lt;strong&gt;Kafka&lt;/strong&gt; used &lt;strong&gt;Zookeeper&lt;/strong&gt; to keep track of assigned partitions to each consumer , &lt;strong&gt;Cassandra&lt;/strong&gt; had a &lt;strong&gt;gossip &lt;/strong&gt; algorithm between nodes and divides data in partition ranges .&lt;br&gt;
So I was starting to think if there was any library ( not an external service like zookeeper ) that had an algorithm with gossip implemented so that people could build some new distributed systems more easily.&lt;br&gt;
&lt;strong&gt;That library does not exist , and then I created &lt;a href="https://github.com/pioardi/ring-election"&gt;ring-election&lt;/a&gt; .&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
You can integrate ring-election into your node process and you will have some important NFRs already constructed !!!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the ring-election driver offers you ?&lt;/strong&gt;&lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A default partitioner that for an object returns the partition to which it is assigned.
&lt;/li&gt;
&lt;li&gt;Mechanism of leader election
&lt;/li&gt;
&lt;li&gt;Failure detection between nodes.
&lt;/li&gt;
&lt;li&gt;Assignment and rebalancing of partitions between nodes
&lt;/li&gt;
&lt;li&gt;Automatic re-election of the leader
&lt;/li&gt;
&lt;li&gt;Listen for new assigned/revoked partitions 
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What problems can you solve with this driver ?&lt;/strong&gt;&lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scalability
&lt;/li&gt;
&lt;li&gt;High availability
&lt;/li&gt;
&lt;li&gt;Concurrency between nodes in a cluster
&lt;/li&gt;
&lt;li&gt;Automatic failover
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How it works under the hood&lt;/strong&gt;&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Leader , the node that will handle the cluster and will not have assigned partitions&lt;/li&gt;
&lt;li&gt;Follower , a node that will have assigned partitions and will work on them&lt;/li&gt;
&lt;li&gt;Heartbeat , a message sent periodically from the followers to leader node to keep track that is alive.&lt;/li&gt;
&lt;li&gt;Heartcheck , a process that run on the leader and go to check the last heartbeat received by each follower&lt;/li&gt;
&lt;li&gt;Priority , is assigned to each follower based on the time that they joined the cluster , when a node die the priority is decreased by one . If the leader die the node with lower priority will become the leader&lt;/li&gt;
&lt;li&gt;Node id , each follower node has an assigned id that is unique into the cluster&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Start up phase described
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v9g2mVTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3dmi5areu9qx9elg8jgf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v9g2mVTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/3dmi5areu9qx9elg8jgf.png" alt="StartUp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Detect follower failures ( Heartbeat/Heartcheck )
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s-EiGn93--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/nifc6m07009tyw2wmh6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s-EiGn93--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/nifc6m07009tyw2wmh6a.png" alt="Detect Failures"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Leader Failure
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GVIwqM3I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fdgwlxhq9v724olowbp9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GVIwqM3I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fdgwlxhq9v724olowbp9.png" alt="Leader Failure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to integrate it ?
&lt;/h2&gt;

&lt;p&gt;Join &lt;a href="https://github.com/pioardi/ring-election"&gt;https://github.com/pioardi/ring-election&lt;/a&gt; to have more info .&lt;br&gt;
If you want to suggest new features or you want help to integrate ring-election open an issue on github and I will be happy to help you.&lt;/p&gt;

</description>
      <category>distributedsystems</category>
      <category>node</category>
      <category>javascript</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
