Node.js 或 Erlang
当谈到它们可以处理的并发级别时,我真的很喜欢这些工具。
Erlang/OTP 看起来是更稳定的解决方案,但需要更多的学习和深入研究函数式语言范例。看起来 Erlang/OTP 在多核 CPU 方面做得更好(如果我错了,请纠正我)。
但我应该选择哪一个呢?从短期和长期角度来看,哪一个更好?
我的目标是学习一种工具,使我在高负载下扩展 Web 项目比传统语言更容易。
I really like these tools when it comes to the concurrency level it can handle.
Erlang/OTP 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/OTP makes it much better when it comes to multi-core CPUs (correct me if I am wrong).
But which should I choose? Which one is better in the short and long term perspective?
My goal is to learn a tool which makes scaling my Web projects under high load easier than traditional languages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我想尝试一下 Erlang。尽管这将是一个更陡峭的学习曲线,但您会从中获得更多,因为您将学习函数式编程语言。此外,由于 Erlang 是专门为创建可靠、高度并发的系统而设计的,因此您将同时了解如何创建高度可扩展的服务。
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,但有一些关于 Node 没有提到的事情:
查看 雅虎博客上的视频,由 Ryan Dahl 制作,他是 Node 的真正编写者。我认为这将帮助您更好地了解节点所在的位置以及它的去向。
请记住,节点仍处于后期开发阶段,因此已经经历了相当多的更改 - 这些更改破坏了早期的代码。然而,据推测,现在您可以期望 API 不会发生太多变化。因此,如果您正在寻找一些有趣的东西,我认为 Node 是一个不错的选择。
I can't speak for Erlang, but a few things that haven't been mentioned about node:
Check out the video on 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.
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.
我是一名长期的 Erlang 程序员,这个问题促使我看一下 Node.js。看起来非常不错。
看来您确实需要生成多个进程才能利用多个核心。不过,我看不到任何有关设置处理器关联性的信息。您可以在 Linux 上使用任务集,但它可能应该在程序中进行参数化和设置。
我还注意到平台支持可能有点弱。具体来说,您似乎需要在 Cygwin 下运行才能获得 Windows 支持。
不过看起来不错。
Edit
Node.js 现在具有对 Windows 的本机支持。
I'm a long-time Erlang programmer, and this question prompted me to take a look at node.js. It looks pretty damn good.
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.
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.
Looks good though.
Edit
Node.js now has native support for Windows.
对于多个项目,我正在寻找与您相同的两种替代方案。
到目前为止,我想出的针对给定项目在它们之间做出决定的最佳剃刀是我是否需要使用 Javascript。我想要迁移的一个现有系统已经是用 Javascript 编写的,因此它的下一版本很可能是在 Node.js 中完成的。其他项目将在一些 Erlang Web 框架中完成,因为没有现有的代码库可以迁移。
另一个考虑因素是,Erlang 的扩展能力远远超出了多个核心,它可以扩展到整个数据中心。我在 Node.js 中没有看到一个内置机制可以让我向另一个 JS 进程发送消息而不用关心它在哪台机器上,但它是在 Erlang 的最低级别内置的。如果你的问题不够大,不需要多台机器,或者不需要多个协作进程,那么这个优势可能并不重要,所以你应该忽略它。
Erlang确实是一个需要潜入的深潭。我建议在开始构建网络应用程序之前先编写一个独立的功能程序。更简单的第一步是尝试以更函数式的风格编写 JS,因为您似乎对 Javascript 很熟悉。如果您使用 jQuery 或 Prototype,那么您已经开始走这条路了。尝试在 Erlang 或其同类之一(Haskell、F#、Scala...)和函数式 JS 中的纯函数式编程之间切换。
一旦您熟悉了函数式编程,就可以寻找众多 Erlang Web 框架之一;在这个后期阶段,您可能不应该直接将应用程序编写到诸如
inets
之类的低级内容。例如,看看氮之类的东西。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.
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 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.
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
inets
at this late stage. Look at something like Nitrogen, for instance.虽然我个人会选择 Erlang,但我承认我对 JavaScript 有一点偏见。我的建议是,您评估以下几点:
Erlang 确实对并发性和并发性进行了微调。网络透明的并行分布式系统。根据项目的具体内容,此类系统的成熟实现的可用性可能比学习新语言的任何问题更重要。还有另外两种可以在 Erlang VM 上运行的语言,即类似于 Ruby/Python 的 Reia 和 Lisp 风格的 Erlang。
另一种选择是同时使用两者,特别是在 Erlang 被用作“集线器”的情况下。我不确定 Node.js 是否有外部函数接口系统,但如果有的话,Erlang 有 C 库供外部进程与系统交互,就像任何其他 Erlang 进程一样。
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 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 Reia and 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 在相对低端的服务器(512MB 4 核 2.4GHz AMD VM)中部署表现更好。这是来自 SyncPad 对比 Erlang 和 SyncPad 的经验虚拟白板服务器应用程序的 Node.js 实现。
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 experience of comparing Erlang vs Node.js implementations of their virtual whiteboard server application.
在同一个虚拟机上还有一种语言就是 erlang -> Elixir
这是 Erlang 的一个非常有趣的替代品,看看这个。
另外它还有一个基于它的快速增长的Web框架-> Phoenix 框架
There is one more language on the same VM that erlang is -> Elixir
It's a very interesting alternative to Erlang, check this one out.
Also it has a fast-growing web framework based on it-> Phoenix Framework
如果没有 erlang,whatsapp 永远无法达到可扩展性和可靠性的水平 https://www.youtube.com/watch ?v=c12cYAUTXXs
whatsapp could never achieve the level of scalability and reliability without erlang https://www.youtube.com/watch?v=c12cYAUTXXs
相比 Node,我更喜欢 Erlang。
如果你想要并发,Node 可以用 Erlang 或 Golang 代替,因为它们的轻量级进程。
Erlang 不容易学习,需要付出很大的努力,但它的社区很活跃,可以从中获得帮助,这就是人们更喜欢 Node 的原因。
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 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 .