本文介绍了Docker容器和Node.js集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个api服务器运行Node.js正在使用它的集群模块和测试看起来相当不错。现在我们的IT部门想转移到使用我很高兴的Docker容器,但我从来没有使用过它,而不仅仅是在玩。但是我有一个想法,Node.js应用程序在单个Docker进程中运行,所以集群模块不会真的是最好的,因为单个Docker进程可能是缓慢的安装点,直到请求在该进程中分裂为止通过集群模块。



所以真正能够启动和停止它们的Docker集群运行的集群比使用Node.js的集群模块更正确?



如果我有一个容器集群,将使用Node.js的集群模块给我什么? api终端需要少于0.5秒的时间才能返回(通常会少一些)。



我正在使用MySQL(相信它是一个单一的服务器,目前还没有更多)那么应该没有任何理由使用数据完整性解决方案。

解决方案

您必须测量确定,但我的预感将运行节点的集群模块是值得的。这将使您获得更多的CPU利用率,额外的额外开销。没有额外的容器来管理(启动,停止,监视)。加上集群工作人员有一个有效的沟通机制。在我看来,最合理的演变(不要跳过步骤):


  1. 1个容器,1个节点进程

  2. 1容器,几个群集节点工作器

  3. 几个容器,每个容器有几个节点工作器


I have an api server running Node.js that was using it's cluster module and testing looked to be pretty good. Now our IT department wants to move to using Docker containers which I am happy about but I've never actually used it other than just playing around. But I had a thought, the Node.js app runs within a single Docker process so the cluster module wouldn't really be the best as the single Docker process can be a slow point of the setup until the request is split up within that process by the cluster module.

So really a cluster of Docker containers running being able to start and stop them on the fly is more important than using Node.js' cluster module correct?

If I have a cluster of containers, would using Node.js' cluster module get me anything? The api endpoints take less than .5sec to return (usually quite a bit less).

I'm using MySQL (believe it's a single server, nothing more currently) so there shouldn't be any reason to use a data integrity solution then.

解决方案

You'll have to measure to be sure, but my hunch would be running with node's cluster module would be worthwhile. It would get you more CPU utilization with the least amount of extra overhead. No extra containers to manage (start, stop, monitor). Plus the cluster workers have an efficient communication mechanism. The most reasonable evolution (don't skip steps) would seem to me:

  1. 1 container, 1 node process
  2. 1 container, several clustered node workers
  3. several containers, each with several node workers

这篇关于Docker容器和Node.js集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:04