<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dmitrii G on Medium]]></title>
        <description><![CDATA[Stories by Dmitrii G on Medium]]></description>
        <link>https://medium.com/@goriunovd?source=rss-1b9fcdd8a7ac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*io-wj1xDHHeKSDcAp4kdNQ.jpeg</url>
            <title>Stories by Dmitrii G on Medium</title>
            <link>https://medium.com/@goriunovd?source=rss-1b9fcdd8a7ac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 10:27:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@goriunovd/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How does ClusterWS scale Websocket? (Part 1 CPU scale)]]></title>
            <link>https://medium.com/@goriunovd/how-does-clusterws-scale-websocket-part-1-cpu-scale-d7a64a33a19?source=rss-1b9fcdd8a7ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7a64a33a19</guid>
            <category><![CDATA[scale]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[website]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[framework]]></category>
            <dc:creator><![CDATA[Dmitrii G]]></dc:creator>
            <pubDate>Fri, 22 Dec 2017 17:11:23 GMT</pubDate>
            <atom:updated>2019-04-03T10:08:16.771Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This article is outdated as many things have changed in ClusterWS. Unfortunately i don’t have enough time (at this point) to support medium articles.</strong></p><p>Good time of the day everyone, hope you are having a great day. If you have not heard about ClusterWS you probably should check it out (and it is not just that i am a developer and trying to make my library more popular, but also it solves a big problem with scaling WebSocket applications in Node.js)</p><p><a href="https://github.com/ClusterWS/ClusterWS">ClusterWS/ClusterWS</a></p><p>ClusterWS reminds SocketCluster, but it works a bit differently i will write separate article about differences between this two frameworks.</p><p>Probably many people will right away ask what are the benefits of using ClusterWS in your next Real Time application. The answer is pretty simple this Framework will reduce the pain of scaling Websocket (what is probably the biggest problem which exist with Websocket applications).</p><p>So how does ClusterWS scale Websocket across machines and cpu cores ?</p><p>Hope you have heard about <a href="https://nodejs.org/api/cluster.html">Node.js Cluster</a> if not please check it out before you continues because that is really tedious to explain it here.</p><p>Basically to scale Websocket across CPUs of your server we use Node.js Cluster. Which unfortunately does not have share state, therefore we developed a Broker server which is running at the background as separate worker and passes messages from one Worker to others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FXBsWSrjVqXaFg77EZyr6w.png" /></figure><p>I know terrible picture (painter is the reason, and may be i am a bit 😄). This schema displays basic client server connection. So for example if i want to send message from Bob to Anna we need to go from one Child to another and for that we have to use Broker. It will work like:</p><p>Bob =&gt; Child 2 =&gt; Child 1 Broker =&gt; [Child 3, Child 4] =&gt; Anna</p><p>Yes message will be send to all childs and every server child will decide if message should go farther or should be deleted.</p><p>This kind of execution chain allows to reduce Broker load as broker will be responsible only for retrieving and emitting message to every one without even thinking if there are receivers. And then every Child instance will decide about message (send it farther or delete).</p><p>This kinda thing calls Pub/Sub that is exactly what you have to use when you build communication between clients in ClusterWS. Also in ClusterWS you can use client =&gt; server communication but this thing does not really scale well 😃 (but any way there are many use cases for client =&gt; server), therefore u will have to use Pub/Sub System (which is provided in ClusterWS) to send message from server to clients or from client to client.</p><p>This is Part 1 and in next article i will explain how we scale across Machines. Hope you will like it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7a64a33a19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real Time Chat with Node.js Cluster & Websocket (ClusterWS)]]></title>
            <link>https://medium.com/@goriunovd/clusterws-chat-with-node-js-clusters-and-websockets-cb6c1224bd79?source=rss-1b9fcdd8a7ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb6c1224bd79</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[Dmitrii G]]></dc:creator>
            <pubDate>Wed, 27 Sep 2017 03:03:51 GMT</pubDate>
            <atom:updated>2018-01-19T04:47:58.860Z</atom:updated>
            <content:encoded><![CDATA[<p>Ohh no building real time chat again…. There are lots of articles about doing it, so what it is the point in this one.The thing is that this article is mainly to show how you can build Chat with ClusterWS (the framework which i mention in the <a href="https://medium.com/clusterws/clusterws-node-js-clusters-with-websockets-easy-829c2e885075">last article</a>). I am pretty sure that this is the first article about building chat with ClusterWS 😈.</p><h3><strong>This article is outdated!!!</strong></h3><p>The great thing about ClusterWS is that all the dirty logic with Worker division and Pub/Sub system done on the background so you don’t have to worry about it.</p><p>So the chat which we gonna build is going to be exactly like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*mSKiYFXHJf1ZTXrM6upQPA.png" /></figure><p>Actually it is the chat which we gonna build 😄</p><p>Ok, i think it is time to start.</p><h3><strong>1. Creating the project</strong></h3><p>The first thing which we need to do is to create Node.js project, go to the folder where you want to do it and just run:</p><pre>npm init</pre><p>and follow the instructions to create <strong><em>package.json</em></strong> file.</p><h3>2.<strong> Installing dependencies</strong></h3><p>Now we have <strong><em>package.json </em></strong>and we can install all needed dependencies.</p><p>First, we need to install ClusterWS from this repository:</p><p><a href="https://github.com/ClusterWS/ClusterWS">ClusterWS/ClusterWS</a></p><p>Just run:</p><pre>npm install --save clusterws</pre><p>To handle http / static files and so on we need to use some other framework like Express/ Koa etc. So i am going to use Koa and Koa Static (for static files).</p><p>To install run:</p><pre>npm install --save koa koa-static</pre><p>The last thing we need to have ClusterWS Client JS library from:</p><p><a href="https://github.com/ClusterWS/ClusterWS-Client-JS">ClusterWS/ClusterWS-Client-JS</a></p><p>Now create folder <strong><em>public </em></strong>and inside that create another folder <strong><em>assets.</em></strong></p><p>With client library everything is a bit different we actual have 2 ways to install it. First one is to go the the repository and copy <strong><em>ClusterWS.min.js</em></strong> from <strong><em>dist/browser </em></strong>to your <strong><em>public/assets</em></strong> folder.</p><p>I will do it another way, will start with installing client library with:</p><pre>npm install --save clusterws-client-js</pre><p>And after that navigate to <strong><em>node_modules/clusterws-client-js/browser</em></strong> and copy <strong><em>ClusterWS.min.js </em></strong>to the <strong><em>public/assets</em></strong> folder.</p><p>Great we have installed everything and now can start codding. 😃</p><h3>3.<em> </em><strong><em>Writing the code 😎</em></strong></h3><p>Now start the most interesting part of this whole article.</p><p>Will start with creating <strong><em>server.js</em></strong> file in the root of our project with the following code (all description done in comments):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f8174a888774d6d91a6a32b6d449352/href">https://medium.com/media/3f8174a888774d6d91a6a32b6d449352/href</a></iframe><p>That was pretty simple for the chat server. And yes it is all what we need on the server, all other logic is going to be in the client side.</p><p>Now we can build client side, first create <strong><em>index.html</em></strong> file in<strong><em> public</em></strong> folder with the follow code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52d2b0a407a66537b3e01c36abeb540c/href">https://medium.com/media/52d2b0a407a66537b3e01c36abeb540c/href</a></iframe><p>Now we need to write main logic for client, to do that create <strong><em>main.js</em></strong> in <strong><em>public/assets</em></strong> folder with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d21d39b305b2311bb6022d9a046f87c/href">https://medium.com/media/1d21d39b305b2311bb6022d9a046f87c/href</a></iframe><p>I hope that code and comments are explaining everything well. 😄</p><p>Ok we left only with some styles to make our chat more or less beautiful (unfortunately i was a bit lazy to work with styles so they are not really good), to connect styles just create <strong><em>styles.css</em></strong> in <strong><em>public/assets</em></strong> with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3509e0c3686db0ec0ccf17b5709bf2aa/href">https://medium.com/media/3509e0c3686db0ec0ccf17b5709bf2aa/href</a></iframe><p>Now <strong><em>chat </em></strong>should be working fine, you can try by navigating to the root of the project in your terminal and running:</p><pre>node server.js</pre><p>You should be able to see blue color text if it is the case, then open it in the browser <strong><em>localhost:yourport</em></strong> (in my case it is<strong><em> localhost:80</em></strong>).</p><p>To test it just open <strong><em>localhost</em></strong> in 2 browser windows and try to send message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zc3pqa6pePyksDhZLY4pnQ.gif" /></figure><p>I hope you like it. You can find all code in this repository:</p><p><a href="https://github.com/goriunov/ClusterWS-Chat-Example">goriunov/ClusterWS-Chat-Example</a></p><p>Thank you for your time, if liked the article please share it and clap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb6c1224bd79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js Cluster & WebSocket (ClusterWS?)]]></title>
            <link>https://medium.com/@goriunovd/clusterws-node-js-clusters-with-websockets-easy-829c2e885075?source=rss-1b9fcdd8a7ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/829c2e885075</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dmitrii G]]></dc:creator>
            <pubDate>Mon, 25 Sep 2017 06:27:54 GMT</pubDate>
            <atom:updated>2019-04-03T10:06:46.690Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>THIS ARTICLE IS OUTDATED !!!</strong></p><p>Node.js is getting more and more popular in development world as well as WebSocket (real time connection), but it is still hard to make WebSocket and Node.js Cluster work well together. In this article I am going to introduce simple, minimalist framework (yes, yes i am a developer) which will make building Node.js Cluster and WebSocket apps easy.</p><p>Before we start with framework I would like that you understand what is Node.js Cluster. Of cause the best place to get started is official <a href="https://nodejs.org/api/cluster.html">Node.js documentation</a>. But I know that almost no one is gonna read it properly, so this is main part:</p><blockquote>A single instance of Node.js runs in a single thread. To take advantage of multi-core systems the user will sometimes want to launch a cluster of Node.js processes to handle the load. The cluster module allows easy creation of child processes that all share server ports. <a href="https://nodejs.org/api/cluster.html">FROM</a>. Also Node.js processes you can call Workers.</blockquote><p>In couple of words it is just<em> : “boost your Node.js app by utilizing all cores of your server computer”</em>.</p><p>I hope you understand why Node.js Cluster is awesome :) Next is going WebSocket.</p><p>Amm. What to say…. Oh Yes, real time connection you probably have met it a lot before but did not know that it is WebSocket. The basic example is chat, where you send message to the user and user gets it straight away without reloading page.</p><p>You can read more about WebSocket <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API">HERE</a> (but it is a bit complicated).</p><p>Ok, why can’t we make Node.js Cluster and WebSocket work together easily.</p><p>If you have two users connected to different Workers in Node.js Cluster, you wont be able to send message from one user to another. Because Workers do not have share state between them. To solve this problem you may need to develop your own share state between Workers by using Redis or some other libraries to handle your messages between Workers. After all of that your code may get bulky, confusing and during development you may meet a lot of complications with WebSocket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RpRMZI3UfwEEqgw0XwT1gw.gif" /></figure><p>Eventually time of <strong>ClusterWS </strong>(yes it is the name of the framework, you probably have noticed that already, in the top left corner). So what does it do? If you want to build salable Node.js and WebSocket app this framework makes your life much easier. ClusterWS allows in couple of lines create Workers (as many as you want) in Node.js Cluster , and in each worker set up WebSocket connections. Also with ClusterWS you can use any other libraries for REST like Express, Koa, etc. To learn more about ClusterWS i would strongly recommend to read README on GitHub.</p><p><a href="https://github.com/ClusterWS/ClusterWS">ClusterWS/ClusterWS</a></p><p>Example Chat built with ClusterWS:</p><p><a href="https://medium.com/clusterws/clusterws-chat-with-node-js-clusters-and-websockets-cb6c1224bd79">ClusterWS: Building chat with Node.js Clusters and WebSockets</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=829c2e885075" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>