<?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"><channel><title><![CDATA[Fail-over and load balancing colyseus Testing]]></title><description><![CDATA[<p>We have successfully configured Colyseus with two nodes in fork mode using PM2, installed latest REDIS (4.0.9), and also added RedisPresence code. It seems to be working.</p>
<p><img src="/assets/uploads/files/1556547263942-485a5ccc-cb66-47f0-9f99-031e1ad03393-image-resized.png" alt="0_1556547267268_485a5ccc-cb66-47f0-9f99-031e1ad03393-image.png" class="img-responsive img-markdown" /></p>
<p><strong>Snippet to configure Redis</strong></p>
<pre><code>const gameServer = new Server({
    server: createServer(app),
    presence: new RedisPresence(),
});
</code></pre>
<p><strong>pm2 configuration</strong></p>
<pre><code>const os = require('os');
module.exports = {
    apps: [{
        port: 2567,
        name: &quot;suicidePoker&quot;,
        script: &quot;./index.ts&quot;, // your entrypoint file
        watch: true,           // optional
        instances: 2,
        exec_mode: 'fork',         // IMPORTANT: do not use cluster mode.
        exec_interpreter : &quot;ts-node&quot;,
        env: {
            DEBUG: &quot;colyseus:errors&quot;,
            NODE_ENV: &quot;production&quot;,
        }
    }]
}
</code></pre>
<p>We now need to test the failover and load balancing.</p>
<p>Will are assuming that all room states will be saved in Redis transparently, without us having to anything.</p>
<p>We then connected to one node (2567 port) and then added two players using different browsers. We saw them appear in the same in the room, using the monitor. We saved some room state e.g. this.player.coins=5 etc etc. Please check screenshot. You can see that on both nodes, we can see the same states. So far, so good. We can see state replication.</p>
<p>We had also created an API that crashes the server.</p>
<p>Something like this:</p>
<pre><code>app.get('/api/ping', function (req, res) {
     setTimeout(function () {
      throw new Error(&quot;Let's crash the server for Testing&quot;);
         }, 10000);
    res.status(200).json({'status':''})

}); 
</code></pre>
<p><strong>Colyseus Monitor</strong></p>
<p><img src="/assets/uploads/files/1556547376974-bb34f240-c8c6-4524-b506-4d56bf6b326e-image-resized.png" alt="0_1556547379420_bb34f240-c8c6-4524-b506-4d56bf6b326e-image.png" class="img-responsive img-markdown" /></p>
<p>After room state data was saved, we crashed the 2567 node. After a few seconds we checked the Colyseus monitor on both ports i.e. 2567 and 2568 there is no room, and all state is gone.<br />
What is happening here?<br />
<a href="https://drive.google.com/file/d/1yTATAhwMeYRA8kH9jy13QXYSTZJvmZvp/view?usp=sharing" rel="nofollow">Video demo</a></p>
]]></description><link>http://discuss.colyseus.io/topic/241/fail-over-and-load-balancing-colyseus-testing</link><generator>RSS for Node</generator><lastBuildDate>Fri, 06 Mar 2026 15:23:29 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/241.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Apr 2019 14:36:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fail-over and load balancing colyseus Testing on Tue, 30 Apr 2019 09:47:05 GMT]]></title><description><![CDATA[<p>We have successfully configured Colyseus with two nodes in fork mode using PM2, installed latest REDIS (4.0.9), and also added RedisPresence code. It seems to be working.</p>
<p><img src="/assets/uploads/files/1556547263942-485a5ccc-cb66-47f0-9f99-031e1ad03393-image-resized.png" alt="0_1556547267268_485a5ccc-cb66-47f0-9f99-031e1ad03393-image.png" class="img-responsive img-markdown" /></p>
<p><strong>Snippet to configure Redis</strong></p>
<pre><code>const gameServer = new Server({
    server: createServer(app),
    presence: new RedisPresence(),
});
</code></pre>
<p><strong>pm2 configuration</strong></p>
<pre><code>const os = require('os');
module.exports = {
    apps: [{
        port: 2567,
        name: &quot;suicidePoker&quot;,
        script: &quot;./index.ts&quot;, // your entrypoint file
        watch: true,           // optional
        instances: 2,
        exec_mode: 'fork',         // IMPORTANT: do not use cluster mode.
        exec_interpreter : &quot;ts-node&quot;,
        env: {
            DEBUG: &quot;colyseus:errors&quot;,
            NODE_ENV: &quot;production&quot;,
        }
    }]
}
</code></pre>
<p>We now need to test the failover and load balancing.</p>
<p>Will are assuming that all room states will be saved in Redis transparently, without us having to anything.</p>
<p>We then connected to one node (2567 port) and then added two players using different browsers. We saw them appear in the same in the room, using the monitor. We saved some room state e.g. this.player.coins=5 etc etc. Please check screenshot. You can see that on both nodes, we can see the same states. So far, so good. We can see state replication.</p>
<p>We had also created an API that crashes the server.</p>
<p>Something like this:</p>
<pre><code>app.get('/api/ping', function (req, res) {
     setTimeout(function () {
      throw new Error(&quot;Let's crash the server for Testing&quot;);
         }, 10000);
    res.status(200).json({'status':''})

}); 
</code></pre>
<p><strong>Colyseus Monitor</strong></p>
<p><img src="/assets/uploads/files/1556547376974-bb34f240-c8c6-4524-b506-4d56bf6b326e-image-resized.png" alt="0_1556547379420_bb34f240-c8c6-4524-b506-4d56bf6b326e-image.png" class="img-responsive img-markdown" /></p>
<p>After room state data was saved, we crashed the 2567 node. After a few seconds we checked the Colyseus monitor on both ports i.e. 2567 and 2568 there is no room, and all state is gone.<br />
What is happening here?<br />
<a href="https://drive.google.com/file/d/1yTATAhwMeYRA8kH9jy13QXYSTZJvmZvp/view?usp=sharing" rel="nofollow">Video demo</a></p>
]]></description><link>http://discuss.colyseus.io/post/835</link><guid isPermaLink="true">http://discuss.colyseus.io/post/835</guid><dc:creator><![CDATA[ahtashamabbasse]]></dc:creator><pubDate>Tue, 30 Apr 2019 09:47:05 GMT</pubDate></item></channel></rss>