TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why does it seem like threading and fibers in Node have been abandoned?

42 点作者 adamcanady超过 11 年前

15 条评论

hacknat超过 11 年前
I work with the node source and I have made C&#x2F;C++ based node modules.<p>Threading at the JS level in node is really ineffective. V8 has a global lock on all JS objects that prevent them from being passed between threads. The only way to allow threading is to serialize and deserialize the objects into new &quot;isolates&quot; (V8 language). V8 does this for some pretty obvious reasons, you wouldn&#x27;t really want to allow threading at the JS level in a browser, now would you.<p>You can use threads if you dive down into C++ land, but event then, you should have a really good reason for doing so, because if you&#x27;re only manipulating objects for processing you&#x27;re going to have to serialize into a C++ data-structure, process, and then serialize into a JS object. Threads in node are good for doing process intensive work that doesn&#x27;t require any two way input from the main event loop, otherwise it&#x27;s very unlikely to be worth your time or effort.<p>This is why fibers are kind of silly for node and is also why process intensive programs should most likely be avoided in node (with rare exception). Please use node for what it is good at; it&#x27;s a short lived connection proxy maven, and good at ancillary front-end work that requires complex state transitions (i.e. mobile). Working it into a monolithic stack is just asking for trouble and pain. No serious architect should consider it for a large monolithic rendering stack.
评论 #6836088 未加载
评论 #6836440 未加载
评论 #6836450 未加载
评论 #6836370 未加载
CGamesPlay超过 11 年前
Because technologies like Q [1] and streams [2] provide a very abstractions around doing long-running tasks asynchronously, which jives better with node&#x27;s entire philosophy. Combine that with the fact that running multiple processes is a perfectly viable way to do actual long-running tasks and node provides abstractions around that out of the box, and it really starts to look like fibers and webworkers in node are patchy hold-overs for technologists who haven&#x27;t fully changed into thinking about things in &quot;the node way.&quot;<p>[1] <a href="https://github.com/kriskowal/q" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kriskowal&#x2F;q</a> [2] <a href="https://github.com/substack/stream-handbook" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;substack&#x2F;stream-handbook</a>
评论 #6834869 未加载
评论 #6834846 未加载
audreyt超过 11 年前
Hi, maintainer of <a href="https://github.com/audreyt/node-webworker-threads/" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;audreyt&#x2F;node-webworker-threads&#x2F;</a> here.<p>We&#x27;re using it happily in production, and it&#x27;s proved to be quite stable, and there&#x27;s quite a few users — certainly more than the average amount of emails I get from other projects. :-)<p>It&#x27;s true that I haven&#x27;t heard from the earliest adopters (like Uber.com), but it might be a sign of its maturity rather than abandonment.<p>The last commit was 2 month ago, and only to repair compatibility with the then-just-released V8 version. It will likely require another commit for Node 0.12.0 — pull requests welcome!<p>Edit: Just released v0.4.8 to npm with references to the <a href="http://aosabook.org/en/posa/from-socialcalc-to-ethercalc.html#multi-core-scaling" rel="nofollow">http:&#x2F;&#x2F;aosabook.org&#x2F;en&#x2F;posa&#x2F;from-socialcalc-to-ethercalc.htm...</a> writeup.
_greim_超过 11 年前
I suspect people who dislike the idea of multithreaded programming are over-represented in the Node community. I&#x27;d even speculate that Node owes some of its popularity to being a release valve for a general thread-grumpiness that has been simmering in developer circles for years, fueled by the common belief that multithreaded programming is error-prone and difficult to reason about. So there&#x27;s probably a bit of an ideological hurdle to overcome, but I also think that it&#x27;s not an insurmountable problem, as the community matures and if a really useful solution presents itself.
scriby超过 11 年前
It would be tough for Fibers to be totally abandoned, as <a href="http://www.meteor.com/" rel="nofollow">http:&#x2F;&#x2F;www.meteor.com&#x2F;</a> relies on it.<p>I don&#x27;t think it&#x27;s really needed any code updates recently, as it works on Linux &#x2F; OS X &#x2F; Windows and all recent versions of node.<p>I think it&#x27;s somewhat hard to tell what the adoption of fibers looks like, as it typically wouldn&#x27;t be used by other modules in npm. You don&#x27;t want to force people using your module to use fibers. So, it would mostly see its usage in applications.<p>It will be interesting to see what happens to fibers once generators ship with core node (available now under the --harmony-generators v8 flag). The most compelling reasons for using fibers can also be met by using generators.<p>(I maintain a library built on top of fibers: <a href="https://github.com/scriby/asyncblock" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;scriby&#x2F;asyncblock</a>)
CmonDev超过 11 年前
But surely Node.js is not meant for that? It&#x27;s meant for high-load scenarios where you want to do simple processing for a lot of connections - not treated like a silver bullet. It&#x27;s just an extra layer for GUI purposes. If you want something advanced you will be better off with a programming language instead of script anyway (type checking etc.). For example: do a long-running process using a proper technology and feed the status of the process to display on GUI via lean Node.js services.
评论 #6835506 未加载
PaulHoule超过 11 年前
There&#x27;s a big difference between a thread implementation that works (Java) and a thread implementation that only works (Python). Even languages close to the metal enough that you&#x27;d think they could support threads (C++) have enough problems with libraries and dependencies that you can&#x27;t entirely depend on threads working right.
goldenkey超过 11 年前
The current way if your workload is cpu-bound is to use cluster or child_process with a priority queue.<p><a href="http://nodejs.org/api/cluster.html" rel="nofollow">http:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;cluster.html</a> <a href="http://nodejs.org/api/child_process.html" rel="nofollow">http:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;child_process.html</a>
Touche超过 11 年前
I disagree with the premise that a project is &quot;abandoned&quot; unless it has very recent commits to master. We are living in a weird world if that&#x27;s the case.
jjm超过 11 年前
My CPU intensive work is wrapped around services. This can be direct native calls to libs (c or openmp), actors via akka, finagle, storm, Hadoop, spark or mesos for that matter. The beauty of node is it&#x27;s single threaded-ness. Doesn&#x27;t mean I cannot orchestrate these single threaded apps as services, asynchronously. Freeing me up from thinking too much about locks and low level context switching.<p>Now not to say you can&#x27;t have it &quot;just because&quot;, a worthy exercise I&#x27;m sure. But in the coming years we will all be asked to use multicores, multiple machines, and multiple data centers. For these scenarios, it may make more sense to think high order.<p>Hopefully I made some sense, I happen to be on my mobile device.
xdissent超过 11 年前
From what I understand, v8 does allow multithreading, but each thread still needs its own isolate scope. That&#x27;s roughly the equivalent of forking off another node process per thread, which is what cluster does.
shtylman超过 11 年前
Because writing plain javascript is simpler for the majority of people to understand and will run in more places without the need for custom setups. Module authors will not write to these custom implementations since it would greatly limit the audience for their module.
评论 #6834696 未加载
评论 #6834798 未加载
rpedela超过 11 年前
Hmm, the last commit for webworker-threads seems to be two months ago instead of six?
评论 #6835552 未加载
cedias超过 11 年前
I&#x27;m puzzled, what&#x27;s the use case for threads in the node asynchronous model ? Isn&#x27;t the major use of threads is to prevent long running task from blocking the app in synchronous programming ?
评论 #6834826 未加载
评论 #6834817 未加载
评论 #6834800 未加载
arxpoetica超过 11 年前
There&#x27;s a model in all this that many developers lose sight of. More and more intensive work is being lifted on the <i>front end</i>. Obviously not a universal phenomenon, but important to any discussion about performance, threading, and IO blocking.