为什么说 Erlang 比 Java 和 C++ 更适合网页游戏的服务器端编程?
我不太明白,Erlang 怎么会比 C++ 更高效呢?
I don't really understand, how can Erlang be more efficient than C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Erlang 的效率远低于 C++。 Erlang 的一大优势是可扩展性,而不是效率。它将跨多个 CPU 线性扩展,并且由于其编程和通信模型,将非常容易地跨机器集群扩展。
需要明确的是,Erlang 不会比 C++ 扩展更多;它只是比 C++ 更容易扩展。更容易很多。请参阅 ConcurrentProgramminginErlang 很好地解释了为什么会这样。
Erlang is far less efficient than C++. Erlang's big strength is scalability, not efficiency. It will linearly scale across multiple CPUs and, due to its programming and communications model, will very easily scale across machine clusters.
Just to be clear, Erlang won't scale more than C++; it just scales more easily than C++. A lot more easily. See chapters 5 and 6 of Concurrent Programming in Erlang for a very good explanation of why this is so.
我可以看到这样的几个原因:
然而,它不适合数字运算,但它具有良好的与交互的可用性C 和 C++ 以及其他语言。使用正确的工具完成正确的工作。
专为并发而设计
Erlang 是一种面向并发的编程语言,非常适合高度并行的应用程序,即游戏服务器。 Erlang进程更加轻量级,并且在进程通信方面具有良好的性能。这意味着用 erlang 实现的应用程序可以拥有比 C++ 中的应用程序可以拥有的线程多得多的进程。另请参阅我的问题从技术上讲,为什么erlang中的进程比操作系统线程更高效。
专为分布式系统设计
Erlang 还内置了一些功能,使程序员在处理分布式系统时更加高效。内置语言原语用于在进程之间发送和接收消息,如果进程位于另一个核心或计算机上,则以相同的方式使用。此外,当消息在进程之间发送时,程序员不必处理编组和序列化,这是语言内置的。
专为软实时系统而设计
Erlang 是为软实时系统而设计的,这在制作游戏服务器时非常有用。与 C++ 相比,它内置了内存管理,这对于程序员来说会更加高效。 C++ 和 malloc 在使用多线程时会遇到问题,并且可能成为瓶颈(请参阅演示文稿 Erlang SMP 支持 - 幕后 (14:00))。与 Java 相比,Erlang 的垃圾收集是按进程(小得多的单位)完成的,这在实时系统中非常有用。
专为可用性而设计
Erlang 专为可用性至关重要的电信应用程序而设计。可用性功能之一是应用程序可以在运行时通过热代码交换进行更新。如果您想在游戏服务器仍然在线时更新它,这会很有用。
我建议您观看此演示文稿: Erlang - Software for a concurrent世界
I can see a few reasons for this:
However, it's not good for number crunching, but it has good availability for interfacing with C and C++ and other languages. Use the right tool for the right job.
Desined for Concurrency
Erlang is a concurrent oriented programming language, and are well suited for applications that can be highly parallellized i.e. game servers. Erlang processes are much more light-weight and has good performence in process communication. This means that an application implemented in erlang can have many more processes than an application in C++ can have threads. Also see my question Technically why is processes in erlang more efficient than OS threads.
Designed for Distributed Systems
Erlang has also built in features that make the programmer more productive when dealing with distributed system. There is built in language primitives for sending and receiving messages between processes, and it is used the same way if the process is located on another core or computer. Also the programmer doesn't has to deal with marshalling and serialization when messages are sent between processes, that is built-in in the language.
Designed for Soft Real Time Systems
Erlang is designed for soft real time systems, and that is useful when doing game-servers. Compared to C++ it has built in memory management which will be much more productive for the programmer. C++ and malloc will suffer from problems when using many threads, and may be a bottleneck (See the presentation Erlang SMP support - behind the scenes at (14:00)). Compared to Java, Erlang's garbage collection is done per process (a much smaller unit) and that will be useful in a real time system.
Designed for Availability
Erlang is designed for Telecom applications where availability is critical. One of the availability features is that applications can be updated at runtime, with hot code swapping. This can be useful if you want to update your game server while it's still online.
I would recommend to see this presentation: Erlang - Software for a concurrent world
当 Erlang 被提升为比 C 更好时,这并不是关于效率。而是关于错误处理和并发性。使用适当的 OTP 原则用 Erlang 编写的服务器将自动具有从错误中恢复的出色方法。
您可以说,Erlang 对于程序员编写服务器应用程序来说效率更高。而且运行起来会更加稳定。
It is not about efficiency when Erlang is promoted as better than C. It's about error handling and concurrency. A server written in Erlang using proper OTP principles will automatically have excellent ways of recovering from errors.
You could say that Erlang is more efficient for the programmer to write a server application. And when it is running it will be more stable.