Sign in to follow this  
graveyard filla

is C# a good choice for scripting on an MMO server?

Recommended Posts

Just like the title says - is C# a good scripting choice for an MMO server? I am strictly asking performance wise here. I am working on a 2D MMO in C#/XNA and was thinking about how scripting would work - it seems C# is the most logical choice to use - I already am very familiar with the syntax, and creating a 'scripting engine' is about as easy as 2 function calls. And then, I have access to *all* the game data and functions I could ever need... Seems too good to be true... so my question is, how efficient is reflection & dynamic compiling in .NET really? Is it realistic to use in a distributed virtual world server? We're talking about scripts firing off every single step most likely. I wonder if there's a really slick way to get the best of both worlds. I'm thinking it's possible to write a code generator that would allow me to 'compile' all my scripts, so that when I deploy, I take all my scripts, and generate some ScriptingEngine class that takes all those script files and puts them in functions in a real .cs file and builds them as part of my project. Yes, obviously I lose all the advantages of having a scripting engine at that point - but hey, at that point I'm deploying and I'm done with all my tweaks... at least for production uses. I'd still use the 'dynamic build' for all development / staging purposes. I doubt that any of the commercial virtual worlds are actually tweaking scripts in production without a whole ton of red tape going through first anyway, so a last compile step couldn't hurt much. (right?) I guess I would lose the ease of deployment, which means any script changes would require a server restart.. I'm probably just prematurely optimizing at this point. anyway, sorry, I'm rambling now. Thanks for any advice.

Share this post


Link to post
Share on other sites
dv    124
There was an article about building a MMO server using Erlang around I think.
Erlang seems to be perfect for this kind of task, since it is designed for massively parallel tasks (we are talking about >10000 threadlets), is very robust, allows hotswapping of code, can isolate crashes so that other parts still run etc.

On the downside, the Erlang syntax isn't exactly pretty, and being a purely functional language, it takes a good while to learn.

Share this post


Link to post
Share on other sites
My design is really meant to be distributed across multiple machines, not cpu's. at work we are looking to build a box for an app that is CPU bound and cannot be distributed.. I forget the exact stats, but it's a ton of RAM like dozens of gigs and something like 16 CPU's on a sun box.. it was priced at over 1 mill. The cost of 16 physical computers is less then 10% of that. That sounds like a pretty expensive design for an MMO. btw, that reply was pretty random [lol]

Share this post


Link to post
Share on other sites
hplus0603    11347
The tool support for C# on Windows is really nice. If you think that you will stay on Windows for your servers, I would seriously consider going that route, because with the right magic incantations in your dynamic compilation, you can attach a debugger and debug your script pretty easily.

The other options are Python and Lua, both of which have remote debugger libraries and implementations, but they're not as slick as Visual Studio. They do, however, port to other platforms.

When doing "live" scripting, you have to solve a few problems, though:

1) What happens if you want to change the data structure of something, say to add a field? In Python or Lua, you can just add fields to existing maps/dicts. In C#, not so much.

2) What do you do with the code that has been edited? How does it get QA-ed? How does it get source controlled? What if two people try to attach and edit at the same time? None of the languages have an edge here.

3) Make sure you have really good exception insulation, because some of the scripted code will be broken. In fact, some of the code may accidentally hose your entire world state, so you might even want to checkpoint world state before re-compiling some new scripts, and have the ability to wind back to that state. That, of course, makes re-compiling (or at least injecting) a new script a lot heavier weight.

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
The tool support for C# on Windows is really nice. If you think that you will stay on Windows for your servers, I would seriously consider going that route, because with the right magic incantations in your dynamic compilation, you can attach a debugger and debug your script pretty easily.

The other options are Python and Lua, both of which have remote debugger libraries and implementations, but they're not as slick as Visual Studio. They do, however, port to other platforms.

When doing "live" scripting, you have to solve a few problems, though:

1) What happens if you want to change the data structure of something, say to add a field? In Python or Lua, you can just add fields to existing maps/dicts. In C#, not so much.

2) What do you do with the code that has been edited? How does it get QA-ed? How does it get source controlled? What if two people try to attach and edit at the same time? None of the languages have an edge here.

3) Make sure you have really good exception insulation, because some of the scripted code will be broken. In fact, some of the code may accidentally hose your entire world state, so you might even want to checkpoint world state before re-compiling some new scripts, and have the ability to wind back to that state. That, of course, makes re-compiling (or at least injecting) a new script a lot heavier weight.


Thanks for the advice. That's what I was hoping to hear... I don't plan on switching platforms... for me, Windows works just great and I really see no need to ever move to a nix based system. Are commercial MMO servers typically nix based? It makes me wonder how they share all their code between client and server, you must be restricted to cross platform languages like Java or C++ I'm guessing... which probably is no problem for you guys anyway since i'd bet it's all written in C++ anyway.

Anyway... about planning this into further design details, I'm several months away from that (if I'm lucky [lol])... but thanks a lot, this gives me the thumbs up to move forward with it..

For source control, that's a great point. Luckily I'm a one man team, so it's not a serious issue yet... hell, we can't even get SQL Server scripts in a proper source control environment here at work... or even our propriety-unix-based-query-language-reports here at work... and we are a decent sized dev shop.. so at this point I'm not that afraid, since we haven't had any major disasters yet. I bet I could use Team Systems though and have all my scripts live in SQL (where they would live anyway), and use SQL Server as my source control mechanism... err, but then we are talking about data, not structure... so that probably wouldn't work...

For exception handling, that's another good point. Not related to screwing the game state, but I'm wondering if a script can easily toast my whole server and bring it down. In this case, maybe I can 'sand box' my scripts by using .NET Remoting to have them run in a seperate process? And yeah, that won't stop it from hosing my whole game state, but at least it won't bring down the server... although I don't see why I can't just wrap the script call in a try/catch and call it a day... anyway, just brainstorming and rambling out loud again..

thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this