用Erlang和其他人制作的套接字服务器

时间:2021-01-18 23:56:08

I am learning Erlang and trying to understand how its sockets work as it is meant to be one of the strongest parts of the language and OTP.

我正在学习Erlang并试图理解它的套接字是如何工作的,因为它是语言和OTP最强大的部分之一。

I have experience with NodeJS, and wonder, how the applications made with NodeJS and Erlang differ in regards on how multiple sockets connections are managed.

我有NodeJS的经验,并且想知道NodeJS和Erlang的应用程序在如何管理多个套接字连接方面有所不同。

As I understand, while JavaScript is single-threaded, V8 manages all the multiple simultaneous connections for it, though Erlang can manage multiple connections itself.

据我所知,虽然JavaScript是单线程的,但V8管理它的所有多个同时连接,尽管Erlang本身可以管理多个连接。

So, I wonder, if Erlang has excellent support for managing multiple connections at a time, how is it different from other technologies for a programmer? I mean, when I write an app for NodeJS, it can have as many connections open and well-managed as if I wrote code in Erlang, isn't it?

所以,我想知道,如果Erlang一次性支持多个连接的管理,它与程序员的其他技术有何不同?我的意思是,当我为NodeJS编写一个应用程序时,它可以打开多个连接并且管理良好就好像我在Erlang中编写代码一样,不是吗?

Please share your thoughts, links to some articles about the specialties of Erlang in this context are welcome too.

请分享您的想法,也欢迎链接到一些关于Erlang特色的文章。

1 个解决方案

#1


1  

I am by no means an expert in Erlang, but I think I know Erlang and NodeJs on the same level.

我绝不是Erlang的专家,但我想我知道Erlang和NodeJ在同一级别。

The things you say, are all correct. Bot can handle multiple connections very efficiently, well well-managed you say.

你说的话都是正确的。 Bot可以非常高效地处理多个连接,您可以很好地管理。

But the thing is, the problems are not only handling multiple concurrent connections. The problems Erlang tries to solve very good, are fail safety, and distribution. I don't think NodeJs will be as good at it, as it is now.

但问题是,问题不仅仅是处理多个并发连接。 Erlang试图解决的问题非常好,是失败的安全性和分配。我不认为NodeJ会像现在这样擅长它。

Don't take it wrong, I'm not saying no one can code a distributed app in NodeJs, but considering the tools Erlang gives you, it maybe is a better choice.

不要误解,我不是说没有人可以在NodeJ中编写分布式应用程序,但考虑到Erlang提供的工具,它可能是更好的选择。

For fail safety, as an example, Erlang let's you link your processes, so when one fails, other also fails or gets notified. That is not very practical by itself, but when you look at it alongside supervisors and shared-nothing processes, it is a great tool.

对于失败安全性,例如,Erlang让你链接你的进程,所以当一个失败时,其他也失败或得到通知。这本身并不是很实用,但是当你将它与主管和无共享流程一起看时,它是一个很好的工具。

For distribution, Erlang let's you link nodes together. Linked nodes can talk together as if they were on the same machine, and they can spawn processes on other side too. Consider this, with the ability to start a failed app from a failed node on another node that is healthy. Gives you a great uptime.

为了分发,Erlang让你将节点链接在一起。链接的节点可以像在同一台机器上一样通话,并且它们也可以在另一侧生成进程。考虑这一点,能够从另一个健康的节点上的故障节点启动失败的应用程序。给你一个很好的正常运行时间。

And not to mention that these tools have years of experience behind them.

更不用说这些工具背后有多年的经验。

Just try to solve these issues on another ecosystem. I say ecosystem, because Erlang as a language is not complete, but the tools and frameworks (mostly OTP) have to be considered too. Then you can also say that Erlang really shines in this areas.

试着在另一个生态系统上解决这些问题。我说生态系统,因为Erlang作为一种语言并不完整,但是必须考虑工具和框架(主要是OTP)。然后你也可以说Erlang在这方面真的很棒。

But Erlang also is not very good when it comes to linear processing, number crunching, image/sound processing, etc. That would be better implemented in another system.

但是Erlang在线性处理,数字处理,图像/声音处理等方面也不是很好。在另一个系统中可以更好地实现。

I think, in this areas, the big difference between NodeJs and Erlang is their runtime model. NodeJs has one process, one thread that is working async on io-related tasks. Of course, you can run multiple processes, but that is the basic thing. On the other hand, Erlang has a VM called BEAM. Erlang uses special processes inside this VM, very light processes. BEAM schedules them itself, because they are not OS processes. This gives BEAM the advantage to have hundreds of thousands processes at the same time, each doing a task, be it io or anything else.

我认为,在这方面,NodeJs和Erlang之间的最大区别在于它们的运行时模型。 NodeJ有一个进程,一个在io相关任务上工作异步的线程。当然,您可以运行多个进程,但这是基本的事情。另一方面,Erlang有一个名为BEAM的VM。 Erlang在这个VM中使用了特殊的进程,非常轻的进程。 BEAM自己安排它们,因为它们不是OS进程。这为BEAM提供了优势,可以同时拥有数十万个进程,每个进程都可以执行任务,无论是io还是其他任何事情。

You see the difference now, I think. Erlang is more battle-tested, more better when fail safety or distribution is a must. NodeJs maybe better when you need faster development, and deployment.

我想你现在看到了不同之处。当失败的安全或分配是必须的时候,Erlang更受战斗考验,更好。当您需要更快的开发和部署时,NodeJ可能会更好。

#1


1  

I am by no means an expert in Erlang, but I think I know Erlang and NodeJs on the same level.

我绝不是Erlang的专家,但我想我知道Erlang和NodeJ在同一级别。

The things you say, are all correct. Bot can handle multiple connections very efficiently, well well-managed you say.

你说的话都是正确的。 Bot可以非常高效地处理多个连接,您可以很好地管理。

But the thing is, the problems are not only handling multiple concurrent connections. The problems Erlang tries to solve very good, are fail safety, and distribution. I don't think NodeJs will be as good at it, as it is now.

但问题是,问题不仅仅是处理多个并发连接。 Erlang试图解决的问题非常好,是失败的安全性和分配。我不认为NodeJ会像现在这样擅长它。

Don't take it wrong, I'm not saying no one can code a distributed app in NodeJs, but considering the tools Erlang gives you, it maybe is a better choice.

不要误解,我不是说没有人可以在NodeJ中编写分布式应用程序,但考虑到Erlang提供的工具,它可能是更好的选择。

For fail safety, as an example, Erlang let's you link your processes, so when one fails, other also fails or gets notified. That is not very practical by itself, but when you look at it alongside supervisors and shared-nothing processes, it is a great tool.

对于失败安全性,例如,Erlang让你链接你的进程,所以当一个失败时,其他也失败或得到通知。这本身并不是很实用,但是当你将它与主管和无共享流程一起看时,它是一个很好的工具。

For distribution, Erlang let's you link nodes together. Linked nodes can talk together as if they were on the same machine, and they can spawn processes on other side too. Consider this, with the ability to start a failed app from a failed node on another node that is healthy. Gives you a great uptime.

为了分发,Erlang让你将节点链接在一起。链接的节点可以像在同一台机器上一样通话,并且它们也可以在另一侧生成进程。考虑这一点,能够从另一个健康的节点上的故障节点启动失败的应用程序。给你一个很好的正常运行时间。

And not to mention that these tools have years of experience behind them.

更不用说这些工具背后有多年的经验。

Just try to solve these issues on another ecosystem. I say ecosystem, because Erlang as a language is not complete, but the tools and frameworks (mostly OTP) have to be considered too. Then you can also say that Erlang really shines in this areas.

试着在另一个生态系统上解决这些问题。我说生态系统,因为Erlang作为一种语言并不完整,但是必须考虑工具和框架(主要是OTP)。然后你也可以说Erlang在这方面真的很棒。

But Erlang also is not very good when it comes to linear processing, number crunching, image/sound processing, etc. That would be better implemented in another system.

但是Erlang在线性处理,数字处理,图像/声音处理等方面也不是很好。在另一个系统中可以更好地实现。

I think, in this areas, the big difference between NodeJs and Erlang is their runtime model. NodeJs has one process, one thread that is working async on io-related tasks. Of course, you can run multiple processes, but that is the basic thing. On the other hand, Erlang has a VM called BEAM. Erlang uses special processes inside this VM, very light processes. BEAM schedules them itself, because they are not OS processes. This gives BEAM the advantage to have hundreds of thousands processes at the same time, each doing a task, be it io or anything else.

我认为,在这方面,NodeJs和Erlang之间的最大区别在于它们的运行时模型。 NodeJ有一个进程,一个在io相关任务上工作异步的线程。当然,您可以运行多个进程,但这是基本的事情。另一方面,Erlang有一个名为BEAM的VM。 Erlang在这个VM中使用了特殊的进程,非常轻的进程。 BEAM自己安排它们,因为它们不是OS进程。这为BEAM提供了优势,可以同时拥有数十万个进程,每个进程都可以执行任务,无论是io还是其他任何事情。

You see the difference now, I think. Erlang is more battle-tested, more better when fail safety or distribution is a must. NodeJs maybe better when you need faster development, and deployment.

我想你现在看到了不同之处。当失败的安全或分配是必须的时候,Erlang更受战斗考验,更好。当您需要更快的开发和部署时,NodeJ可能会更好。