Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a high-performance network server in C++

I need to create a network server in C++ for a trading application. This network server needs to perform the following tasks:

  • handle authentication of clients and provide session id for each session.

  • handle orders originating from the clients and inform clients about their execution.

  • handle other data request asked for by the clients and send data back to them.

I am planning to use Boost.Asio networking library and Google protocol buffers to implement the messages being sent from the clients to the server. XML-RPC or SOAP based approaches are a strict no-no as latency is a big concern.

I have the following questions for the stackoverflow community:

  1. Is it a good idea to implement these messages using protocol buffers? I am also considering sending messages Boost serialization library to implement this. When I look at the code, I find myself more confident of implementing this with boost serialization and Google protobuf headers look too heavyweight. Which of these methods will be a) more maintainable and b) require less effort? I guess, both these approaches will work across different platforms.

  2. Is there any other networking library which I should look at apart from Boost.Asio.?I find ACE a little dated as far as C++ coding style is concerned.

  3. Eventually I would like to make this network server run on SSL, however, I do not have any experience with implementing SSL. How much effort would it require to move to SSL later on. Should I start with SSL or can it be added later on?

  4. Does anybody know of a good open source network project, which might have implemented a similar network server using Boost.Asio, to get inspired from?

like image 267
Lazylabs Avatar asked Oct 04 '11 18:10

Lazylabs


2 Answers

You should also look at Apache Thrift (originated at Facebook) or Apache Etch (initially developed by Cisco). They are RPC frameworks that make it easy to develop both servers and clients meeting your needs (more or less). For a framework developed using protobuf and boost.asio, look at the server1 project.

like image 164
npclaudiu Avatar answered Sep 20 '22 14:09

npclaudiu


BSON ( http://www.mongodb.org/display/DOCS/BSON and http://bsonspec.org ) is a very fast binary protocol. C++ implementation is readily available from mongodb. The fact that it is basically JSON makes it quite easy to implement and maintain.

SSL implementation doesn't add up much extra code to the asio-based server: SSL context initialization with certificate paths and some handshake logic.

like image 22
dimitri Avatar answered Sep 18 '22 14:09

dimitri