Lua in a server (performance)

Started by
5 comments, last by ddn3 15 years, 4 months ago
I have this MUD server, and I'm planing it to be scripted so I will be able to use it with different games, stories and all, just by scripting it different. In a MUD, I think it's ok, but in some point in future, I'm planing to do a MMORPG, like many people do. A mmorpg is a little bit more demanding then a mud server. How much performance I will be losing by using lua? Oh, my server is coded in c++ using completion ports. I've think in two different ways to script. 1) Expose everything to lua: There is a class to encapsulate an IOCP server,CIocpServer. But, this class needs a pointer to a function, this function is the one that actually does the logic work, what to do with messages and all that stuff. I was planning to Expose this class CIocpServer to lua (luaBind) and left the rest to a lua script. This way gives me maximum freedom. 1) Expose Key functions to lua: Do all the logic in functions(a function to accept connections), a function to send data to a specific client, a function to save data in a database, and expose those functions to lua. This way, Lua will just coordinate when to call those functions, instead of implement then directly as lua functions. This way there is less lua involved. What do you think? Should I implement lua scripts and it's freedom? In which manner should I implement it? thanks
Advertisement
From my tests and stats from the Language shootout, Lua is about 20-30x slower than native C code and 5x slower if your using LuaJit ( which you should if your on an intel platform, as there isn't any cost not too ).

If your worried about performance you might want to consider using C# and its just in time compiler, which runs about 80% the speed of C in general.

Lua strength, speed being just one, is more so its dynamic nature. It allows you to program in a much more free form fashion, with support for closures, dynamic associative arrays, coroutines and its support for different programming methodologies and styles (ie functional, procedural, object oriented, etc.. ) In that sense it's much closer to Ruby than C#. Another strength is it's implementation, which are only a few source files and easily customized for embedding (ie sandboxing, custom io, etc..), this is of course impossible with other much heavier languages like C# or Java, you would more so extend them much like how you use Python, than embed.

Lua biggest drawback IMO, is lack of 3d party support in IDEs like visual studio, for debugging and developmenet within the same IDE. There are programs which alllow you to debug Lua but they're not intergrated into the visual studio IDE which is a big negative.

Good Luck!

-ddn
How can I use C# to script my c++ program??

I am intending to use lua to add functionalities and extend my base server. This way, I will be able to use the same base server in different games.

.

With an MMORPG, my understanding is that scalability is far more important than the speed of an individual server. So really your architecture is something you need to get right. I don't imagine using Lua will limit you in any way.

My instinct would be to use as much Lua as possible. If your program is sane, you should be able to replace any Lua parts that you identify as being too slow with a C++ replacement later on, if necessary.
I think that you draw the line between what is coded in C and what is coded in Lua between what will change the most. Logic and data will change the most, so that should probably be in Lua.

If you go with option 1, instead of exposing the server to Lua, write your logic function as a Lua script and call that script from a C function that you register with your server. You'll need to expose the messages to Lua so that your script can receive them and make decisions on them.

This approach will probably mix in some of the second approach and bind a few of the key function with Lua.

If a function's logic doesn't change much, or is processor intensive it should be in C, but if it's something you're going to tweak a lot (like AI, or game logic) you will save yourself a lot of time by implementing it in Lua and tweaking it there.

Lua + Visual Studio=http://www.itrango.com/vslua/

cheers,

Bob

[size="3"]Halfway down the trail to Hell...
I tweaked the Lua compiler a smidge to, if a compile-time symbol is defined, have Lua do call-counting profiling for all functions without any function-call overhead; it just adds a fetch,add,store to the start of every function. With this profiling data, I could build as much of my codebase in Lua as I wanted, and every once in a while take the top ten most-called Lua functions and replace them with C.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
That would be a great patch submission Wyrframe, hint hint :D

MMOs are very complex, with their logic, networking, stability, scalability, security and robustness requirements. You can definitely use Lua for a small scale MMO, its robust and flexible enough to do things which you can't even attempt in other languages realistically (performance or programming wise).

Good Luck!

-ddn

This topic is closed to new replies.

Advertisement