C# 开发游戏服务器的好语言?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/392624/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 01:44:40  来源:igfitidea点击:

Good language to develop a game server in?

c#javapythonnetworking

提问by ryeguy

I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out).

我只是想知道哪种语言是开发支持大量(数千)用户的游戏服务器的不错选择?我涉足了 python,但意识到它会太麻烦,因为它不会跨内核产生线程(意味着 8 核服务器 = 1 核服务器)。我也不太喜欢这种语言(“自我”的东西让我感到恶心)。

I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development?

我知道 C++ 是性能方面的工作语言,但我讨厌它。我不想处理它草率的语法,我喜欢我的手被托管语言握住。这让我接触了 C# 和 Java,但我对其他语言持开放态度。我喜欢 .NET 的简单性,但我想知道,速度方面,这是否适合这份工作。请记住,由于这将部署在 Linux 服务器上,它将在 Mono 框架上运行 - 不确定这是否重要。我知道 Java 在语法上与 .Net 非常相似,但我对它的经验有限。是否有任何框架可以缓解开发过程?

Please help me and my picky self arrive on a solution.

请帮助我和我挑剔的自己找到解决方案。

UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?

更新:我不是故意听起来这么挑剔,我真的不认为我是。我真正排除的唯一语言是 C++,由于可扩展性问题,我不喜欢 Python。我知道进程之间有通信的方式,但是如果我有一个8核服务器,为什么我需要做8个进程?有没有更优雅的解决方案?

采纳答案by finpingvin

Erlang is a language which is designed around concurrency and distribution over several servers, which is perfect for server software. Some links about Erlang and game-servers:

Erlang 是一种围绕并发和分布在多个服务器上而设计的语言,非常适合服务器软件。关于 Erlang 和游戏服务器的一些链接:

http://www.devmaster.net/articles/mmo-scalable-server/

http://www.devmaster.net/articles/mmo-scalable-server/

http://www.erlang-consulting.com/euc2005/mmog/mmog_in_erlang.htm

http://www.erlang-consulting.com/euc2005/mmog/mmog_in_erlang.htm

I'm thinking of writing a game-server in Erlang myself.

我正在考虑自己在 Erlang 中编写一个游戏服务器。

回答by ryeguy

I hate to say it, and I know I'm risking a down mod here, but it doesn't sound like there's a language out there for you. All programming languages have their quirks and programmers simply have to adapt to them. It's completely possible to write a working server in Python without classes (eliminating the "self" variable class references) and likewise just as easy to write C++ with clean syntax.

我不想这么说,我知道我在这里冒着降级的风险,但听起来好像没有适合你的语言。所有编程语言都有自己的怪癖,程序员只需要适应它们。完全有可能在没有类的情况下用 Python 编写一个工作服务器(消除“self”变量类引用),同样用干净的语法编写 C++ 也同样容易。

If you're looking to deploy cross-platform and want to develop cross-platform as well, your best bet would probably be Java. It shorter development cycles than compiled languages like C and C++, but is higher performance (arguable, but I've always been anti-Java =P) than interpreted languages like Python and Perl and you don't have to work with unofficial implementations like Mono that may from time to time not support all of a language's features.

如果您希望部署跨平台并希望开发跨平台,那么您最好的选择可能是 Java。它比 C 和 C++ 等编译语言的开发周期更短,但比 Python 和 Perl 等解释型语言的性能更高(有争议,但我一直反对 Java =P),而且您不必使用非官方的实现,例如Mono 有时可能不支持一种语言的所有功能。

回答by paranoidgeek

It may depend a lot on what language your "game logic" (you may know this term as "business logic") is best expressed in. For example, if the game logic is best expressed in Python (or any other particular language) it might be best to just write it in Python and deal with the performance issues the hard way with either multi-threading or clustering. Even though it may cost you a lot of time to get the performance you want out of Python it will be less that the time it will take you to express "player A now casts a level 70 Spell of darkness in the radius of 7 units effecting all units that have spoken with player B and .... " in C++.

这可能在很大程度上取决于您的“游戏逻辑”(您可能知道这个术语为“业务逻辑”)的最佳表达语言。例如,如果游戏逻辑最好用 Python(或任何其他特定语言)表达它最好只用 Python 编写它并通过多线程或集群以艰难的方式处理性能问题。尽管从 Python 中获得您想要的性能可能会花费您很多时间,但您表达“玩家 A 现在在 7 个单位的半径范围内施放 70 级黑暗法术”所花费的时间会更少所有与玩家 B 和...交谈过的单位在 C++ 中。

Something else to consider is what protocol you will be using to communicate with the clients. If you have a complex binary protocol C++ may be easier (esp. if you already had experience doing it before) while a JSON (or similar) may be easier to parse in Python. Yes, i know C++ and python aren't languages you are limited to (or even considering) but i'm refer to them generally here.

还需要考虑的是您将使用什么协议与客户端进行通信。如果你有一个复杂的二进制协议,C++ 可能更容易(特别是如果你之前已经有过这样做的经验),而 JSON(或类似的)可能更容易在 Python 中解析。是的,我知道 C++ 和 python 不是你被限制(甚至考虑)的语言,但我在这里一般是指它们。

Probably comes down to what language you are the best at. A poorly written program which you hated writing will be worse that one written in a language you know and enjoy, even if the poorly written program was in an arguable more powerful language.

可能归结为您最擅长哪种语言。一个你讨厌编写的写得不好的程序会比用你熟悉和喜欢的语言写的更糟糕,即使写得不好的程序是用一种有争议的更强大的语言。

回答by Dustin

What kind of performance do you need?

你需要什么样的表现?

twisted is great for servers that need lots of concurrency, as is erlang. Either supports massive concurrency easily and has facilities for distributed computing.

Twisted 非常适合需要大量并发的服务器,就像 erlang。要么轻松支持大规模并发,并具有分布式计算的设施。

If you want to span more than one core in a python app, do the same thing you'd do if you wanted to span more than one machine — run more than one process.

如果您想在一个 Python 应用程序中跨越多个核心,请执行与跨越多台机器相同的操作——运行多个进程。

回答by Esko

Speaking of pure performance, if you can run Java 6 you get about 1:1 performance when compared to optimized C++ (special cases notwithstanding, sometimes Java is faster, sometimes C++), the only problem you will have is of course stuff like database libraries, interconnectivity, scalability and such. I believe there's a variety of good to great solutions available to each of these problems but you won't find one language which would solve everything for you so I have to give you the age old advice: Choose the language you like and use that one.

说到纯粹的性能,如果你可以运行 Java 6,与优化的 C++ 相比,你可以获得大约 1:1 的性能(尽管有特殊情况,有时 Java 更快,有时 C++),你唯一会遇到的问题当然是数据库库之类的东西、互连性、可扩展性等。我相信对于这些问题中的每一个都有各种很好的解决方案,但是你找不到一种语言可以解决所有问题,所以我必须给你一个古老的建议:选择你喜欢的语言并使用那种语言.

Oh, you're still reading this? :) Well, here's some extra pointers.

哦,你还在读这个吗?:) 好吧,这里有一些额外的提示。

  • EVE Onlineuses Python for its client and server side code and it's both bug-ridden and laggy as something I don't think I should write here so that'd be an example of how Python can be extended to (poorly) serve vast amounts of users.
  • While Java has some good to great solutions to various related problems, it's really not the best language out there for vast amount of users; it doesn't scale well to extremes without tuning. However there's multi-VM solutions to this which somewhat fix the issue, for example Terracottais said to do the job well.
  • While C++ is rather cumbersome, it allows for such a low-level interaction with the system that you may actually find yourself doing things you thought you couldn't do. I'm thinking of something like dynamic per-core microclustering of runtime code blocks for "filling" every possible clock cycle of the processor as efficiently as possible for maximum performance and things like that.
  • Mono is far behind the .NET VM/equivalent on Windows platforms so you wouldn't be able to use the latest and fanciest features of C#. However Windows XP (x64) OEM licenses are so laughably cheap at the moment that with small investment you could get a bunch of those and you could then run your code on the platform it was meant to be. And don't fall into the Linux hype, Linux is your saviour only if you really know how to use it and especially XP is pretty damn fast and stable nowadays.
  • EVE Online将 Python 用于其客户端和服务器端代码,它既存在漏洞又滞后,因为我认为我不应该在这里写一些东西,因此这将是如何扩展 Python 以(较差)提供大量服务的示例的用户。
  • 虽然 Java 对各种相关问题有一些很好的解决方案,但对于大量用户来说,它确实不是最好的语言;如果不进行调整,它就不能很好地扩展到极端。然而,有一些多虚拟机解决方案可以解决这个问题,例如据说Terracotta可以很好地完成这项工作。
  • 尽管 C++ 相当麻烦,但它允许与系统进行如此低级的交互,以至于您实际上可能会发现自己在做您认为无法做的事情。我正在考虑诸如运行时代码块的动态每核微集群之类的东西,以尽可能有效地“填充”处理器的每个可能的时钟周期,以获得最大的性能等等。
  • Mono 远远落后于 Windows 平台上的 .NET VM/等效项,因此您将无法使用 C# 的最新和最先进的功能。然而,Windows XP (x64) OEM 许可证目前非常便宜,只需少量投资,您就可以获得大量这些许可证,然后您可以在它应该使用的平台上运行您的代码。不要沉迷于 Linux 炒作,只有当您真正知道如何使用 Linux 时,Linux 才是您的救星,尤其是现在 XP 非常快速和稳定。

回答by PEZ

You could also look at jRuby. It comes with lots of the benefits of Java and lots of the benefits of Ruby in one neat package. You'll have access to huge libraries from both languages.

你也可以看看jRuby。它在一个简洁的包中提供了 Java 的许多优点和 Ruby 的许多优点。您将可以访问来自两种语言的庞大库。

回答by Nils Pipenbrinck

You could as well use Java and compile the code using GCC to a native executable.

您也可以使用 Java 并使用 GCC 将代码编译为本机可执行文件。

That way you don't get the performance hit of the bytecode engine (Yes, I know - Java out of the box is as fast as C++. It must be just me who always measures a factor 5 performance difference). The drawback is that the GCC Java-frontend does not support all of the Java 1.6 language features.

这样你就不会受到字节码引擎的性能影响(是的,我知道 - 开箱即用的 Java 与 C++ 一样快。必须只有我总是测量 5 倍的性能差异)。缺点是 GCC Java 前端不支持所有 Java 1.6 语言功能。

Another choice would be to use your language of choice, get the code working first and then move the performance critical stuff into native code. Nearly all languages support binding to compiled libraries.

另一种选择是使用您选择的语言,首先让代码工作,然后将性能关键的东西移到本机代码中。几乎所有语言都支持绑定到编译库。

That does not solve your "python does not multithread well"-problem, but it gives you more choices.

这并不能解决您的“python 不能很好地多线程”问题,但它为您提供了更多选择。

回答by antik

More details about this game server might help folks better answer your question. Is this a game server in the sense of something like a Counter Strike dedicated server which sits in the background and hosts multiplayer interactions or are you writing something which will be hosted on an HTTP webserver?

有关此游戏服务器的更多详细信息可能会帮助人们更好地回答您的问题。从某种意义上说,这是一个游戏服务器,例如位于后台并托管多人交互的反恐精英专用服务器,还是您正在编写将托管在 HTTP 网络服务器上的内容?

Personally, if it were me, I'd be considering Java or C++. My personal preference and skill set would probably lead me towards C++ because I find Java clumsy to work with on both platforms (moreso on Linux) and don't have the confidence that C# is ready for prime-time in Linux yet.

就个人而言,如果是我,我会考虑 Java 或 C++。我的个人偏好和技能集可能会引导我使用 C++,因为我发现 Java 在两个平台上工作都很笨拙(在 Linux 上更是如此),并且不相信 C# 已经准备好在 Linux 中进入黄金时段。

That said, you also need to have a pretty significant community hammering on said server before performance of your language is going to be so problematic. My advise would be to write it in whatever language you can at the moment and if your game grows to be of sufficient size, invest in a rewrite at that time.

也就是说,在您的语言的性能出现问题之前,您还需要有一个非常重要的社区来打击该服务器。我的建议是用你现在可以使用的任何语言编写它,如果你的游戏增长到足够大,那么在那个时候投资重写。

回答by mfx

The obvious candidates are Java and Erlang:

显而易见的候选者是 Java 和 Erlang:

Pro Java:

亲Java:

  • ease of development
  • good development environments
  • stability, good stack traces
  • well-known (easy to find experienced programmers, lots of libraries, books, ...)
  • quite fast, mature VM
  • 易于开发
  • 良好的开发环境
  • 稳定性,良好的堆栈跟踪
  • 众所周知(很容易找到有经验的程序员、大量的图书馆、书籍……)
  • 相当快,成熟的VM

Pro Erlang:

亲二郎:

  • proven in systems that need >99.9% uptime
  • ability to have software updates without downtime
  • scalable (not only multi-core, but also multi-machine)
  • 在需要 >99.9% 正常运行时间的系统中得到验证
  • 无需停机即可进行软件更新的能力
  • 可扩展(不仅多核,而且多机)

Contra Erlang:

反对Erlang:

  • unfamiliar syntax and programming paradigm
  • not so well known; hard to get experienced programmers for
  • VM is not nearly as fast as java
  • 不熟悉的语法和编程范式
  • 不太为人所知;很难找到有经验的程序员
  • VM 没有 java 快

If your game server mainly works as a event dispatcher (with a bit of a database tucked on), Erlang's message-driven paradigm should be a good match.

如果您的游戏服务器主要用作事件调度程序(带有一些数据库),那么 Erlang 的消息驱动范式应该是一个很好的匹配。

In this day and age, I would not consider using an unmanaged language (like C or C++); the marginal performance benefits simply aren't worth the hassle.

在这个时代,我不会考虑使用非托管语言(如 C 或 C++);边际性能优势根本不值得麻烦。

回答by Dave Sherohman

What are your objectives? Not the creation of the game itself, but why are you creating it?

你的目标是什么?不是游戏本身的创造,而是你为什么要创造它?

If you're doing it to learn a new language, then pick the one that seems the most interesting to you (i.e., the one you most want to learn).

如果您这样做是为了学习一门新语言,那么请选择您认为最有趣的语言(即您最想学习的语言)。

If it is for any other reason, then the best language will be the one that you already know best and enjoy using most. This will allow you to focus on working out the game logic and getting something up and running so that you can see progress and remain motivated to continue, rather than getting bogged down in details of the language you're using and losing interest.

如果是出于任何其他原因,那么最好的语言将是您已经最了解并且最喜欢使用的语言。这将使您能够专注于制定游戏逻辑并启动并运行某些内容,以便您可以看到进展并保持继续前进的动力,而不是陷入所使用语言的细节并失去兴趣。

If your favorite language proves inadequate in some ways (too slow, not expressive enough, whatever), then you can rewrite the problem sections in a more suitable language when issues come up - and you won't know the best language to address the specific problems until you know what the problems end up being. Even if your chosen language proves entirely unsuitable for final production use and the whole thing has to be rewritten, it will give you a working prototype with tested game logic, which will make dealing with the new language far easier.

如果你最喜欢的语言在某些方面证明是不够的(太慢,不够表达,等等),那么当问题出现时,你可以用更合适的语言重写问题部分 - 而且你不会知道解决特定问题的最佳语言直到你知道问题最终是什么。即使您选择的语言被证明完全不适合最终的生产使用并且整个事情必须重写,它也会为您提供一个经过测试的游戏逻辑的工作原型,这将使​​处理新语言变得更加容易。