Node.js在Kubernetes上扩展 [英] Node.js scaling out on Kubernetes

查看:80
本文介绍了Node.js在Kubernetes上扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Docker在node.js上构建了一个应用程序,但不确定如何在Kubernetes集群上进行扩展,以便最大程度地利用集群硬件.

从性能角度来看,以下哪个更好:

集群我的节点应用程序,并根据需要运行尽可能多的容器

是否可以根据需要运行任意数量的容器而不进行集群?

当我说集群时,是指 https://nodejs.org/api/cluster.html

我的应用程序是由mongoDB支持的简单CRUD Api.我们估计它将有1000个并发用户.我们的集群有3个节点.

解决方案

NodeJS集群该机制有助于使NodeJS更有效地使用大于单个内核的功能,因此,取决于您的代码,它可能会使您受益,但它高度依赖于您的代码和各种依赖关系,以及它们在集群中的工作(或不工作)情况. /p>

作为一般惯例,如果您可以将容器分解为可以在kubernetes中作为Pod运行的很好的并行化工作,那么我建议您采用以下过程来查看对您有用的过程:

  1. 设置一个包含您的代码的pod,然后对其进行负载测试.使用Kubernetes从cAdvisor获得的数据来表征您的pod希望拥有多少资源(cpu和内存).
  2. 根据上面的内容设置CPU和内存的资源限制.
  3. 运行负载测试以验证您的单个Pod可以处理的规模

然后从那里有了一个基准,可以在其中使用Kubernetes对其进行水平扩展,以验证要实现的1000个用户并发基准. 2017年Kubecon对此过程进行了很好的演讲,称为负载测试Kubernetes:如何优化集群资源生产中的分配

一旦有了基准,就可以利用代码中的集群来运行原型,然后与非集群版本进行比较.如果这样做,我将仔细检查您设置的任何限制是否> 1个CPU内核,否则您将在NodeJS运行时之外进行自我限制以访问多个内核,这将破坏使用的目的.集群.

根据您在代码中所做的工作,可能需要进行大量的重新工作才能启用群集,因为它想利用自己的工作人员概念,并且不清楚您正在使用什么框架以及是否使用它们.会合理地适合该结构.

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 https://nodejs.org/api/cluster.html

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

解决方案

The NodeJS cluster 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:

  1. 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.
  2. set a resource limit for cpu and memory based on what you see above.
  3. run a load test to validate what your single pod handles in terms of scale

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 Load Testing Kubernetes: How to optimize your cluster resource allocation in production

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.

这篇关于Node.js在Kubernetes上扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆