在node.js中,如何请求或访问群集中的特定工作程序(具有进程ID或工作程序号)? [英] In node.js how to request or access specific worker in cluster (with either process ID or worker number)?

查看:73
本文介绍了在node.js中,如何请求或访问群集中的特定工作程序(具有进程ID或工作程序号)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求: 假设是否有4个核心的PID(进程ID)为0000,1111,2222,3333.有什么办法可以设置总是由特定内核处理的某些请求.

My requirement: Suppose if there are 4 cores with PIDs (process IDs) 0000,1111,2222,3333. Is there any way to set certain request always handled by particular core.

有什么方法可以设置特定内核的ID,并且可以在请求中访问该ID?

Is there any way to set ID for specific core and can access that ID in requests?

示例:对"localhost:8000/info"的所有请求应始终由0000或我们可以设置的任何上述条件处理.如果有办法,该怎么办?

Example: all requests to 'localhost:8000/info' should always handled by 0000 or any of the above that we can set. If there is a way, how to do that?

推荐答案

第一步:停止使用集群 第二步:在四个端口上启动四个节点进程 第三步:在端口8000上放置一个反向代理,其中包含规则以分配给四个节点进程

Step one: stop using cluster Step two: fire up four node processes on four ports Step three: put a reverse proxy on port 8000 with rules to distribute to the four node processes

对于第三步,您可以使用node,nginx,haproxy等. .

For step three you can use node, nginx, haproxy etc . . .

这篇关于在node.js中,如何请求或访问群集中的特定工作程序(具有进程ID或工作程序号)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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