Search code examples
c++boostboost-asioprotocol-buffersboost-serialization

Boost.Asio with google protocol buffers


I've currently investigating ways of improving our current c++ network hand-made serialization mechanism maintaining our existing binary protocol. The first approach taken was to code it using Boost.Asio with Boost.Serialisation using binary serialization. Anyway it turned up that it's somewhat slower (10%) that our current hand-made implementation. Anyone has actual _real_work_ experience about using google protobuf together with Boost.Asio ?

I searched google for samples but was only able to come-up with this example:

Boost Asio with google protocol buffers sample

Does anybody did this in any actual project ? I've very interested performance figures since this has to be quite fast...


Solution

  • We use boost::asio and Protobuf for complex, low message rate protocols. For simple, high message rate protocols we do boost::asio and custom serialization.

    The C++ Protobuf library uses std::string to represent the string fields for messages that it deserializes, which means a free store allocation is performed by Protobuf for every string field in every message you receive. That makes Protobuf not very performant for really high frequency messaging.

    I would use Protobuf everywhere if I could, though. It's a marvelous tool for making rich, complex, platform independent, forward-and-backward-compatible protocols.

    ADDENDUM

    Since it seems like people are reading this answer, I should share that I've learned that in C++ Protobuf you can re-use deserialization message objects to reduce the malloc frequency when reading.

    See Optimization Tips:

    https://developers.google.com/protocol-buffers/docs/cpptutorial