Overhaul the way we build up buffers of data to send
Created by: robertmaynard
Currently we have a pretty inefficient way of serializing data to and from proto::Messages. What we need to do is introduce an entirely different way of building up messages, to reduce the number of temporary allocations that are currently being done.
For example right now to send a JobRequirements we do the following:
bool Client::canMesh(const remus::proto::JobRequirements& reqs)
{
std::ostringstream buffer;
buffer << reqs;
remus::proto::Message j(reqs.meshTypes(),
remus::CAN_MESH_REQUIREMENTS,
buffer.str());
j.send(&this->Zmq->Server);
}
This is really inefficient because not only do we create a ostringstream buffer, it has to do a copy into a temporary string for remus::proto::Message, and than the remus::proto::Message does an internal copy to a zmq::msg buffer.
What we need to do is either create a new smart buffer class that has a simple interface to allow conversion from known types to an uncompressed binary stream. This class than can be passed to remus::proto::Message
which will tack ownership of the buffer and send it to zmq with as few copies as possible ( zmq zero copy? ).
The end result would be the following syntax:
bool Client::canMesh(const remus::proto::JobRequirements& reqs)
{
remus::proto::Buffer buffer;
buffer << reqs;
remus::proto::Message j(reqs.meshTypes(),
remus::CAN_MESH_REQUIREMENTS,
buffer);
j.send(&this->Zmq->Server);
}
The upside to this class is that buffer doesn't allocate to a string to pass to Message, and Message will hold onto the internal data made by buffer so we avoid a second copy there.