Node.js - 针对 cpu 核心 [英] Node.js - targeting a cpu core

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

问题描述

如何启动一个节点进程,以特定的 CPU 内核为目标?

我见过节点集群,但我有兴趣在不同的内核上启动两个不同的进程.

I've seen node cluster, but I'm interested in starting two different processes, on different cores.

我假设从命令行启动节点时有一种方法可以做到这一点,即:

I was assuming there was a way of doing this when starting node from the command line, i.e:

节点 myapp.js

node myapp.js

如果有区别,我很想知道如何在 windows 和 linux 中执行此操作.

I'd be interested to know how to do this in both windows and linux, if there is a difference.

推荐答案

一般来说,调度器会在没有任何帮助的情况下很好地完成这项工作.在野外,我只见过一种情况,这很重要......

In general, the scheduler will do a pretty good job of this without any help. In the wild, I've only seen one situation where this mattered....

我们在 8 核机器上部署了一个节点服务,在负载测试期间,我们进行了最奇怪的观察……该服务实际上在 7 个 worker 时比 8 个 worker 表现得更好.稍后进行了一些调试,我们发现所有网络中断由核心 0 处理.我尝试使用 15 个工作线程,这样与其他核心相比,核心 0 将拥有 1/2 的负载份额.最终,我认为我们最终使用了 7 个工人,因为它更简单、更可预测,而且复杂性不值得为了获得约 7% 的理论吞吐量.

We were deploying a node service on an 8-core box and during load testing we made the strangest observation... the service actually performed better with 7 workers than with 8. A bit of debugging later and we figured out that all network interrupts were being handled by core 0. I played with using 15 workers so that core0 would have a 1/2 share of the load compared to the other cores. Ultimately, I think we ended up going with 7 workers because it was simpler and more predictable and the complexity just wasn't worth it to get ~7% more theoretic throughput.

话虽如此,要在 linux 上设置 CPU 亲和性:

That being said, to set CPU affinity on linux:

$ taskset -pc 3089
pid 3089's current affinity list: 0,1

$ taskset -p 3089
pid 3089's current affinity mask: 3 # core 0 = 0x1, core 1 = 0x2


$ taskset -pc 1,2,3 3089 
pid 3089's current affinity list: 0,1
pid 3089's new affinity list: 1

这篇关于Node.js - 针对 cpu 核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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