Node.js 或 Erlang
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3011317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js or Erlang
提问by user80805
I really like these tools when it comes to the concurrency level it can handle.
当涉及到它可以处理的并发级别时,我真的很喜欢这些工具。
Erlang looks like much more stable solution but requires much more learning and a lot of diving into functional language paradigm. And it looks like Erlang makes it much better when it comes to multi cores CPUs(fix me if I'm wrong).
Erlang 看起来是更稳定的解决方案,但需要更多的学习和深入研究函数式语言范式。看起来 Erlang 在多核 CPU 方面做得更好(如果我错了,请纠正我)。
But which should I choose? Which one is better in the short/long term perspective?
但是我应该选择哪个?从短期/长期的角度来看,哪一个更好?
My goal is to learn a tool which makes scaling my web projects under high load easier than traditional languages.
我的目标是学习一种工具,它比传统语言更容易在高负载下扩展我的 Web 项目。
采纳答案by Justin Ethier
I would give Erlang a try. Even though it will be a steeper learning curve, you will get more out of it since you will be learning a functional programming language. Also, since Erlang is specifically designed to create reliable, highly concurrent systems, you will learn plenty about creating highly scalable services at the same time.
我想试试 Erlang。尽管这将是一个更陡峭的学习曲线,但由于您将学习函数式编程语言,因此您会从中获得更多收益。此外,由于 Erlang 专门设计用于创建可靠的、高度并发的系统,因此您将同时学到很多有关创建高度可扩展服务的知识。
回答by Jarsen
I can't speak for Erlang, but a few things that haven't been mentioned about node:
我不能代表 Erlang,但有一些关于 node 的事情没有提到:
- Node uses Google's V8 engine to actually compile javascript into machine code. So node is actually pretty fast. So that's on top of the speed benefits offered by event-driven programming and non-blocking io.
- Node has a pretty active community. Hop onto their IRC group on freenode and you'll see what I mean
- I've noticed the above comments push Erlang on the basis that it will be useful to learn a functional programming language. While I agree it's important to expand your skillset and get one of those under your belt, you shouldn't base a project on the fact that you want to learn a new programming style
- On the other hand, Javascript is already in a paradigm you feel comfortable writing in! Plus it's javascript, so when you write client side code it will look and feel consistent.
- node's community has already pumped out tons of modules! There are modules for redis, mongodb, couch, and what have you. Another good module to look into is Express(think Sinatra for node)
- Node 使用 Google 的 V8 引擎将 javascript 实际编译成机器码。所以节点实际上非常快。所以这是在事件驱动编程和非阻塞 io 提供的速度优势之上。
- Node 有一个非常活跃的社区。跳到他们在 freenode 上的 IRC 组,你就会明白我的意思
- 我注意到上面的评论推动 Erlang 的基础是学习函数式编程语言会很有用。虽然我同意扩展您的技能并掌握其中一项很重要,但您不应该将项目建立在您想学习一种新的编程风格的事实之上
- 另一方面,Javascript 已经处于一种您可以轻松编写的范式中!加上它是 javascript,所以当你编写客户端代码时,它的外观和感觉是一致的。
- node 的社区已经推出了大量的模块!有用于 redis、mongodb、couch 的模块,你有什么。另一个值得研究的好模块是Express(想想 Sinatra 的节点)
Check out the videoon yahoo's blog by Ryan Dahl, the guy who actually wrote node. I think that will help give you a better idea where node is at, and where it's going.
查看yahoo 博客上由 Ryan Dahl 撰写的视频,他是实际编写 node 的人。我认为这将有助于让您更好地了解 node 所在的位置以及它的去向。
Keep in mind that node still is in late development stages, and so has been undergoing quite a few changes—changes that have broke earlier code. However, supposedly it's at a point where you can expect the API not to change too much more. So if you're looking for something fun, I'd say node is a great choice.
请记住,node 仍处于开发后期阶段,因此一直在进行相当多的更改——这些更改已经破坏了早期的代码。但是,据推测,您可以期望 API 不会发生太大变化。因此,如果您正在寻找有趣的东西,我会说 node 是一个不错的选择。
回答by dsmith
I'm a long-time Erlang programmer, and this question prompted me to take a look at node.js. It looks pretty damn good.
我是一个长期的 Erlang 程序员,这个问题促使我看看 node.js。它看起来非常好。
It does appear that you need to spawn multiple processes to take advantage of multiple cores. I can't see anything about setting processor affinity though. You could use taskset on linux, but it probably should be parametrized and set in the program.
看来您确实需要生成多个进程才能利用多个内核。不过,我看不到有关设置处理器关联的任何信息。您可以在 linux 上使用 taskset,但它可能应该在程序中进行参数化和设置。
I also noticed that the platform support might be a little weaker. Specifically, it looks like you would need to run under Cygwin for Windows support.
我还注意到平台支持可能有点弱。具体来说,您似乎需要在 Cygwin 下运行才能获得 Windows 支持。
Looks good though.
不过看起来不错。
Edit
编辑
Node.js now has native support for Windows.
Node.js 现在对 Windows 有本机支持。
回答by p_l
While I'd personally go for Erlang, I'll admit that I'm a little biased against JavaScript. My advice is that you evaluate few points:
虽然我个人会选择 Erlang,但我承认我对 JavaScript 有点偏见。我的建议是你评估几点:
- Are you reusing existing code in either of those languages (both in terms of source code, and programmer experience!)
- Do you need/want on-the-fly updates without stopping the application (This is where Erlang wins by default - its runtime was designed for that case, and OTP contains all the tools necessary)
- How big is the expected traffic, in terms of separate, concurrent operations, not bandwidth?
- How "parallel" are the operations you do for each request?
- 您是否重用了这两种语言中的任何一种的现有代码(在源代码和程序员经验方面!)
- 您是否需要/想要在不停止应用程序的情况下即时更新(这是 Erlang 默认获胜的地方 - 它的运行时是为这种情况设计的,并且 OTP 包含所有必要的工具)
- 就单独的并发操作而不是带宽而言,预期流量有多大?
- 您为每个请求执行的操作有多“并行”?
Erlang has really fine-tuned concurrency & network-transparent parallel distributed system. Depending on what exactly is the project, the availability of a mature implementation of such system might outweigh any issues regarding learning a new language. There are also two other languages that work on Erlang VM which you can use, the Ruby/Python-like Reiaand Lisp-Flavored Erlang.
Erlang 确实对并发性和网络透明的并行分布式系统进行了微调。根据项目的具体内容,此类系统的成熟实现的可用性可能会超过有关学习新语言的任何问题。还有两种其他语言可以在 Erlang VM 上使用,您可以使用 Ruby/Python-like Reia和Lisp-Flavored Erlang。
Yet another option is to use both, especially with Erlang being used as kind of "hub". I'm unsure if Node.js has Foreign Function Interface system, but if it has, Erlang has C library for external processes to interface with the system just like any other Erlang process.
另一种选择是同时使用两者,尤其是当 Erlang 被用作一种“中心”时。我不确定 Node.js 是否有外部函数接口系统,但如果有,Erlang 有 C 库供外部进程与系统交互,就像任何其他 Erlang 进程一样。
回答by Warren Young
I'm looking at the same two alternatives you are, gotts, for multiple projects.
对于多个项目,我正在寻找与您相同的两种选择。
So far, the best razor I've come up with to decide between them for a given project is whether I need to use Javascript. One existing system I'm looking to migrate is already written in Javascript, so its next version is likely to be done in node.js. Other projects will be done in some Erlang web framework because there is no existing code base to migrate.
到目前为止,对于给定的项目,我想出的在它们之间做出决定的最佳剃刀是我是否需要使用 Javascript。我希望迁移的一个现有系统已经用 Javascript 编写,因此它的下一个版本可能会在 node.js 中完成。其他项目将在一些 Erlang web 框架中完成,因为没有现有的代码库可以迁移。
Another consideration is that Erlang scales well beyond just multiple cores, it can scale to a whole datacenter. I don't see a built-in mechanism in node.js that lets me send another JS process a message without caring which machine it is on, but that's built right into Erlang at the lowest levels. If your problem isn't big enough to need multiple machines or if it doesn't require multiple cooperating processes, this advantage isn't likely to matter, so you should ignore it.
另一个考虑因素是 Erlang 的扩展性远远超出了多核,它可以扩展到整个数据中心。我在 node.js 中没有看到内置机制,可以让我发送另一个 JS 处理消息而无需关心它在哪台机器上,但它已在最低级别内置到 Erlang 中。如果您的问题不够大,需要多台机器,或者如果它不需要多个协作进程,则此优势可能无关紧要,因此您应该忽略它。
Erlang is indeed a deep pool to dive into. I would suggest writing a standalone functional program first before you start building web apps. An even easier first step, since you seem comfortable with Javascript, is to try programming JS in a more functional style. If you use jQuery or Prototype, you've already started down this path. Try bouncing between pure functional programming in Erlang or one of its kin (Haskell, F#, Scala...) and functional JS.
Erlang 确实是一个可以潜入的深潭。我建议在开始构建 Web 应用程序之前先编写一个独立的功能程序。更简单的第一步,因为您似乎对 Javascript 感到满意,所以尝试以更函数式的风格编写 JS。如果您使用 jQuery 或 Prototype,那么您已经开始走这条路了。尝试在 Erlang 或其同类(Haskell、F#、Scala...)中的纯函数式编程和函数式 JS 之间跳来跳去。
Once you're comfortable with functional programming, seek out one of the many Erlang web frameworks; you probably shouldn't be writing your app directly to something low-level like inetsat this late stage. Look at something like Nitrogen, for instance.
一旦您熟悉了函数式编程,就可以从众多 Erlang Web 框架中寻找一种;inets在这个后期阶段,您可能不应该将您的应用程序直接编写为低级别的内容。例如,看看像Nitrogen这样的东西。
回答by adib
It looks like Erlang performs better for deployment in a relatively low-end server (512MB 4-core 2.4GHz AMD VM). This is from SyncPad's experienceof comparing Erlang vs Node.js implementations of their virtual whiteboard server application.
看起来 Erlang 在部署在相对低端的服务器(512MB 4 核 2.4GHz AMD VM)上表现更好。这是来自SyncPad比较 Erlang 与 Node.js 虚拟白板服务器应用程序实现的经验。
回答by NoDisplayName
There is one more language on the same VM that erlang is -> Elixir
在 erlang 所在的同一 VM 上还有另一种语言 -> Elixir
It's a very interesting alternative to Erlang, check this one out.
这是 Erlang 的一个非常有趣的替代品,请查看这个。
Also it has a fast-growing web framework based on it-> Phoenix Framework
还有一个基于它的快速增长的 web 框架-> Phoenix Framework
回答by Henry H.
whatsapp could never achieve the level of scalability and reliability without erlang https://www.youtube.com/watch?v=c12cYAUTXXs
如果没有 erlang,whatsapp 永远无法达到可扩展性和可靠性的水平https://www.youtube.com/watch?v=c12cYAUTXXs
回答by Sumit Pugalia
I will Prefer Erlang over Node. If you want concurrency, Node can be substituted by Erlang or Golang because of their light weight processes.
我更喜欢 Erlang 而不是 Node。如果你想要并发,Node 可以用 Erlang 或 Golang 代替,因为它们的轻量级进程。
Erlang is not easy to learn so requires a lot of effort but its community is active so can get help from that, this is only the reason why people prefer Node .
Erlang 不容易学,所以需要付出很多努力,但它的社区很活跃,所以可以从中得到帮助,这就是人们喜欢 Node 的原因。

