views:

2119

answers:

16

Hello,

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).

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?

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?

+14  A: 

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.

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.

sli
A: 

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?

ryeguy
This site has a question/answer format, it is not a threaded discussion. Your "answer" above is not an answer to your question, so it should either be a comment or an update to the question.
ΤΖΩΤΖΙΟΥ
or maybe a new question
nosklo
+1  A: 

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++.

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.

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.

paranoidgeek
+7  A: 
Dustin
+6  A: 

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.

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

  • EVE Online uses 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 Terracotta is 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.
Esko
Although I haven't tried it out, EVE has recently done a major rewrite which they say has improved performance significantly. This suggests to me that the lag issues were with their architecture rather than due to their choice of language. And every language is slow with bad architecture.
Dave Sherohman
They have removed some of their networking bottlenecks with a new network layer ("Stackless I/O"), but their scalability problems still persist because they don't have any dynamic load balancing (they cannot move a busy solar system to another server without "rebooting" it).
mjy
The biggest contributor to lag in EVE afaik comes from their poor choice of database architecture (one SQL server and multiple SOLs, extremely bandwidth heavy) and some from their interesting use of Python in wrong places so yes, you're right that it's mostly an architectural problem.
Esko
@Esko AFAIK the DB server isn't used much in fleet battles. They have > 5000 solar systems assigned to 250-300 CPUs/"nodes" though and any number of battles might erupt in different solar systems on the same node at any time, which may be handling a busy mission hub as well. No load balancing = bad.
mjy
S.Lott: I'd rather not get points for mentioning EVE but the actual content of my post instead.mjy: Did you know that each system node is actually a single EVE client running in server mode? That's why they can't really load balance them properly. Poor design choice.
Esko
A: 

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.

PEZ
+2  A: 

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

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.

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.

Nils Pipenbrinck
+11  A: 

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:

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

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

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

finpingvin
+1  A: 

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?

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.

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.

antik
+1  A: 

The obvious candidates are Java and Erlang:

Pro 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

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)

Contra Erlang:

  • unfamiliar syntax and programming paradigm
  • not so well known; hard to get experienced programmers for
  • VM is not nearly as fast as 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.

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.

mfx
A: 

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.

Dave Sherohman
A: 

You could take a look at Stackless Python. It's an alternative Python interpreter that provides greater support for concurrency. Both EVE Online's server and client software use Stackless Python.

Disclaimer: I haven't used Stackless Python extensively myself, so I can't provide any first-hand accounts of its effectiveness.

mipadi
+3  A: 

I might be going slightly off-topic here, but the topic interests me as I have (hobby-wise) worked on quite a few game servers (MMORPG servers) - on others' code as well as mine. There is literature out there that will be of interest to you, drop me a note if you want some references.

One thing that strikes me in your question is the want to serve a thousand users off a multithreaded application. From my humble experience, that does not work too well. :-)

When you serve thousands of users you want a design that is as modular as possible, because one of your primary goals will be to keep the service as a whole up and running. Game servers tend to be rather complex, so there will be quite a few show-stopping bugs. Don't make your life miserable with a single point of failure (one application!).

Instead, try to build multiple processes that can run on a multitude of hosts. My humble suggestion is the following:

  • Make them independent, so a failing process will be irrelevant to the service.
  • Make them small, so that the different parts of the service and how they interact are easy to grasp.
  • Don't let users communicate with the gamelogic OR DB directly. Write a proxy - network stacks can and will show odd behaviour on different architectures when you have a multitude of users. Also make sure that you can later "clean"/filter what the proxies forward.
  • Have a process that will only monitor other processes to see if they are still working properly, with the ability to restart parts.
  • Make them distributable. Coordinate processes via TCP from the start or you will run into scalability problems.
  • If you have large landscapes, consider means to dynamically divide load by dividing servers by geography. Don't have every backend process hold all the data in memory.

I have ported a few such engines written in C++ and C# for hosts operating on Linux, FreeBSD and also Solaris (on an old UltraSparc IIi - yes, mono still runs there :). From my experience, C# is well fast enough, considering on what ancient hardware it operates on that sparc machine.

The industry (as far as I know) tends to use a lot of C++ for the serving work and embeds scripting languages for the actual game logic. Ah, written too much already - way cool topic.

mstrobl
A: 

C++ and Java are quite slow compared to C. The language should be a tool but not a crutch.

dwelch
A: 

There is a pretty cool framework in development that addresses all your needs:

Project Darkstar from Sun. So I'd say Java seems to be a good language for game server development :-)

A: 

I know facebook uses a combination of Erlang and C++ for their chat engine.

Whatever you decide, if you choose a combination of languages, check out facebook's thrift framework for cross language services deployment. They open sourced it about a year+ back:

http://incubator.apache.org/thrift/

ajhit406