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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: Why hasn't the JavaScript event loop model scaled horizontally?

3 点作者 wkyleg6 个月前
Right now, JavaScript scales well with a single-threaded event loop. Certainly not as fast as something like Go for async tasks, but enough to power much of the web and be easy to write.<p>Why hasn&#x27;t anyone abstracted the event loop model to scale across multiple machines or utilize modern processors? Perhaps with something more like an Actor model or Erlang&#x27;s BEAM?<p>It seems like just getting the JavaScript concurrency model as an abstraction over multicore or multi-machine concurrency would be one of the easiest ways to achieve this. I realize that this is still technically difficult, but programming tends towards &quot;just porting things to JavaScript.&quot; I would love to have something like Phoenix framework, just built with JavaScript&#x2F;TypeScript, and I can scale a back end by bumping size of a machine or scaling horizontally.

7 条评论

austin-cheney6 个月前
First, let&#x27;s understand what the event model is. The event model allows for a single process to use multiple call stacks. This is an example of concurrency not parallelism.<p>Second, when people talk about multiple threads they are typically talking about SMP, or simultaneous multi-processing. JavaScript already does this. It uses WebWorkers in the browser and clusters in Node. Each of those technologies can then coordinate task execution through messaging, such as IPC. Detached-state execution allows for child processes to execute with process independence from the calling process which means killing the calling process will not terminal the child process.<p>Third, when people talk about multiple machine execution they are typically talking about task distribution, which is not the same as decentralization. Distribution is similar to detached-state SMP but reliant upon network access for task distribution and status.<p>You can achieve all this with JavaScript right now. I have done it in a personal application built around decentralization and remote file system management.
idontwantthis6 个月前
I think if you want that, JavaScript isn’t the right tool. The single threaded simplicity is a big part of why it is a useful tool. You can always spin up external processes from within your app, or use a load balancer or queue to share work with multiple identical processes.<p>The idea of just horizontally scaling up a node process wouldn’t make a lot of sense. How would you share scope between the different processes for example? You would need a whole new construct, at which point you’re really throwing away the advantages you had and you should probably be using a different language.
评论 #42177210 未加载
hehehheh6 个月前
Its a good question. There are worker threads in Node but they seem clunky to use:<p><a href="https:&#x2F;&#x2F;bitsfactory.lilanga.me&#x2F;posts&#x2F;nodejs-utilize-multi-core-processors&#x2F;" rel="nofollow">https:&#x2F;&#x2F;bitsfactory.lilanga.me&#x2F;posts&#x2F;nodejs-utilize-multi-co...</a><p>Stateless webservers are easier, since this is merely loaf balancing. Just run more processes:<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;2387724&#x2F;node-js-on-multi-core-machines" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;2387724&#x2F;node-js-on-multi...</a>
ActorNightly6 个月前
If you are talking about nodejs, there is <a href="https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;child_process.html" rel="nofollow">https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;child_process.html</a><p>Same way that python does parallelism, by relying on the underlying OS to schedule threads and use multiple cores.<p>For JS running in browser, you probably don&#x27;t want any allowance for such scheduling in the scripts, and let the JS engine in the browser automatically establish parallelism if needed.
toast06 个月前
I&#x27;m not in the node ecosystem, but can&#x27;t you <i>&quot;just&quot;</i> use node worker-threads for multicore, and run node on multiple machines for multi-machine?<p>If you want the features of BEAM&#x2F;dist plus running some javascript, I&#x27;d suggest you build your coordination layer in a BEAM language and have some glue to run javascript as a spawned port, or possibly connect node as a c_node to dist.
评论 #42177229 未加载
pier256 个月前
Libuv which powers Node can execute multiple event loops (one per thread).<p><a href="https:&#x2F;&#x2F;docs.libuv.org&#x2F;en&#x2F;v1.x&#x2F;design.html" rel="nofollow">https:&#x2F;&#x2F;docs.libuv.org&#x2F;en&#x2F;v1.x&#x2F;design.html</a><p>You&#x27;d need to write your app code in C++ which isn&#x27;t very popular in web dev.
lunarcave6 个月前
People used to fork the JavaScript process according to the number of cores present, but it’s less popular now because most infrastructure is provisioned by vCPUs.<p>So people just provisioned for vCPU=1.<p>Node.js (v8) already offloads io tasks to their own threads so it’s already horizontal to some extent.