55420

Node.js scaling out on Kubernetes

Question:

I built an app on node.js using Docker and I'm not sure how to scale it on a Kubernetes cluster so that I take the most out of my cluster hardware.

From a performance perspective which of the following is better:

clusterize my node app and run as many containers as needed

or

just run as many containers as needed without clustering ?

When I say clustering I mean this <a href="https://nodejs.org/api/cluster.html" rel="nofollow">https://nodejs.org/api/cluster.html</a>

My app is a simple CRUD Api backed by mongoDB. We estimate that it will have 1000 concurrent users. Our cluster has 3 nodes.

Answer1:

The <a href="https://nodejs.org/api/cluster.html" rel="nofollow">NodeJS cluster</a> mechanism is useful to allow NodeJS to more effectively use greater than a single core, so depending on your code it may benefit you, but it's highly dependent on your code and the various dependencies and how well they work (or not) with clustering.

As a general practice, if you can break your containers down into nicely parallelized efforts that can be run as pods within kubernetes, then I'd recommend the following as a process to see what works for you:

<ol><li>set up a single pod with your code in it, and run a load test against it. Use the data that Kubernetes has from cAdvisor to characterize how much resources (cpu & memory) your pod likes to have.</li> <li>set a resource limit for cpu and memory based on what you see above.</li> <li>run a load test to validate what your single pod handles in terms of scale</li> </ol>

And from there, you have a baseline where you can use Kubernetes to scale this horizontally to validate the 1000 user concurrent baseline you want to achieve. There's a good talk on this process from the 2017 Kubecon called <a href="https://www.youtube.com/watch?v=_l8yIqMpWT0" rel="nofollow">Load Testing Kubernetes: How to optimize your cluster resource allocation in production</a>

Once you have a baseline, you can run a prototype out leveraging the clustering in your code, and then compare against the non-clustered version. If you do this, I'd double-check that any limits you set are > 1 core for CPU, or you'll be self-limiting outside of the NodeJS runtime to get access to multiple cores, which would defeat the purpose of using clustering.

Depending on what you're doing in your code, there may be significant re-work needed to enable clustering, as it wants to leverage its own worker concept, and it's not clear what frameworks you're using and if they'll fit reasonably into that structure.

Recommend

  • Javascript variables for Get http
  • miss prototype functions when “new” a instance
  • How to create list with carousel effect in android
  • Emulate User Activity
  • Git subtree post hook
  • How many percent of the tweets does twitter sample API give?
  • How to create a data template dependent on an XML Attribute?
  • Is an if-let or a normal if condition better?
  • MySql - get days remaining
  • How do I recognize a line break with a switch case that evaluates a char in Java?
  • Binary Tree Traversal Sum Of Each Depth
  • Converting simple MySQL database to a NoSQL solution
  • How to load Q library with Require.js?
  • Neo4j: Legacy Indexes and auto index vs new label bases schema indexes
  • How to add learning rate to summaries?
  • d3.js selection conditional rendering
  • Unzip archive in .Net CORE 1.0
  • Lock Horizontal View
  • Jquery Knockout: ko.computed() vs classic function?
  • Angular2 component view does not update on value change via method
  • CakePHP ACL tutorial initDB function warnings
  • Unable to install Git-core+svn by MacPorts
  • jQuery ready not fired after rails link_to is clicked
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • How to attach a node.js readable stream to a Sendgrid email?
  • Yii2: Config params vs. const/define
  • Avoid links criss cross / overlap in d3.js using force layout
  • Algorithm for a smudge tool?
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Cassandra Data Model
  • Updated Ionic CLI but shows previous version (Windows)
  • SetUp method failed while running tests from teamcity
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Acquiring multiple attributes from .xml file in c#
  • Understanding cpu registers
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • java string with new operator and a literal