|
Boost Users : |
Subject: Re: [Boost-users] Performance of boost::serialization
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-09-17 15:34:05
Daniel Herb wrote:
> Hi!
> I'm having performance issues with boost::serilaization.
> First a short description what my data looks like:
> I serialize a container of boost::shared_ptr<Base> where i put
> polymorph objects in (no very deep hierarchy ~2 layers). The objects
> are ~40 byte each. The container has 100 elements in my test case.
>
> In the test application i can only serialize that container ~40 times
> per second. That's to slow for me because the data is used for the
> network communication.
> What i've found is this thread:
> http://old.nabble.com/-Serialization--Speedding-up-client-server-communication-td27462494.html
> But it seems that i have to recreate the archive in my case because
> the data can get send, changed and send again. The documentation says
> that this behaviour can be disabled through disabling tracking. But
> that doesn't work for me because I use pointers.
>
> Robert Ramey also mentioned that implementing a lightweight version of
> stringstream could improve the performance. I liked to look at that
> but it seems that i'm missing something completely.
>
> class mystreambuf : public std::streambuf {
> public:
> virtual std::streamsize xsputn(const char*_Ptr, std::streamsize
> _Count) {
> }
> };
>
>
> So this stream buffer does nothing right? But somehow serialization
> throughput is even worse with that implementation (compared to
> stringstream). I've never implemented a stream buffer so help would
> be nice. What are the requirements of boost::serialization for the
> stream buffer?
>
> Also generally it would be nice if you could share your oppinion if
> you think if the performance of boost::serialization can be tuned to
> serialize data for network communication. Is it only possible without
> polymorphism/shared_ptr?
a) polymorphic archives are measurable slower than the non-polymorphic on
b) Which archive class are you using? For maximum speed use binary_archive.
c) It is a current feature of the library that you would have to reconstruct
the archive class for each usage. This costs a lot of time. In the future
this
may be addressed.
For now I would suggest
a) don't use a polymorphic archive
b) make a special class just for data transmission
i) don't use pointers,
ii) mark the class NOT_TRACKED
iii) make sure all it's non-primitive members are not tracked
c) Open the archive just one and invoke ar << multiple times
d) Make your own stream buffer implementation which sends the raw
data down the pipe.
e) Performance test your implementation with gcc profile or similar msvc
tool
Robert Ramey
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net