I have designed and developed game servers successfully with thrift (http://thrift.apache.org/). I am writing here some tips to share my experience. I hope that this will help someone who is just trying to solve the same problems that I have met.
Thrift is mainly for scalable cross-language services development ( what it's website has written).Someone may mention Google ProtocolBuff. I have used ProtocolBuff some projects. However, I like thrift more than Google protocolbuff. There are two reasons:
When developing MMO Server, I use messages to communicate with client which is may implemented by different language e.g., as3. So thrift is very suitable for interchange messages. But there is another circumstance to use thrift.As you know the part of the logic of game server, is modified frequently. Along with project progressing, More property will be added to player object or sub structure. So we will add more fields or rows to db for storing extra data. With version issues being considered, that's much more annoying. I create a blob field to db table that stores a thrift object. With advantages of version supporting, It's easy to add more property to player.
Thrift is originally designed for RPC. How it works for RPC is easy to find if you Google it. I will not write more for this part. But there is less articles to introduce how thrift can be used to communicate message in real time system. Thrift support as3 but just for RPC. So I add some files for supporting message communicating. That another reason why I like thrift that the codes are so readable that it's so easy to extend thrift. Though I am not a professional as3 engineer (I am professional in C++), I implement that easily. I implement two functions to wrap serialization and deserialization.
EncodeMsg(msg:TBase, ba:ByteArray): tran:FFMemoryTransport = proto:TBinaryProtocol = DecodeMsg(msg:TBase, ba:ByteArray): tran:FFMemoryTransport = proto:TBinaryProtocol =
I have uploaded flash_example.zip file which includes my extending as3 lib files and a exampl.as file. Actually it's a chat tutorial application using thrift.
There are some dissatisfied aspects in thrift C++ implement codes that they depend boost library. Generally it's not a big problem as most of C++ projects have been using boost. But someone who just want to integrate thrift easily finds it annoying. In some mobile app project with C++, they will not want to depend boost too. Actually I don't find good enough reason to must implement thrift of C++ version with boost. Most of use of boost in thrift are for assert test and smart pointer. Thanks to readable codes, I find it easy to wipe dependency of boost. Actually I still recommend you to use official version. But if you just want try thrift as soon as possible you can try this version of no boost. By the way, this C++ version of no boost supports binary encoding only.
main( argc, **=
I have uploaded ffthrif_cpp_example.zip file which includes my extending C++ files and a example file.
I use MySQL. There I show the model of game structure as an example. For storing players' data I design a table named player_info for players' base property such as level, gold, exp...
The field of Extra_Data is special and important. It is a blob type for storing thrift. For example, I design a such thrif file:
: list<i32>: : map<i32, >
thrift-0.9.0.exe -gen cpp msg_def.thrift
I will store extra_data_t
to field of Extra_Data. There are such features:
extra_data_t
but not to modify MySQL table structure. We have hundreds of game server so that we always update some of server first, if anything is ok, we make all servers updated to newest version. Thrift and blob make us agile enough to handle these situations. We don't need to modify db frequently and the part of db operations is stable.extra_data_t
as base structure of player_t
class.But we must use thrift properly. If you chose to store thrift object to db blob, you will give up query this field by SQL. So my tips are: