Efficient logging of selective data changes with FlatBuffers and multiple channels #1368
Replies: 1 comment
-
Which overhead are you concerned about? There is some setup code required, yes, but it does not add per-message overhead, since each message is logged with a channel id (an integer) and that would be true even if they shared the same channel.
The requirements are documented here: https://mcap.dev/spec/registry#flatbuffer-1 By the way, it's invalid to have two
I believe Foxglove will currently fill in the default values for missing fields in flatbuffer messages, so this might not work the way you want. Although it may work with protobuf -- haven't tried recently. Generally though, this might give you problems if you are trying to visualize certain data, e.g. if you try to plot |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am developing a logging system for my project using MCAP for data persistence. My goal is to optimize the logging by writing to the file only when a specific value changes.
My current approach involves using FlatBuffers to define the message schemas. Since I need to write different types of data (e.g., speed, position) independently based on their change, I have split my data into separate FlatBuffer tables:
namespace VehicleSim;
table VehicleStateSpeed{
speed: float;
}
table VehicleStatePos{
x: float;
y: float;
}
root_type VehicleStateSpeed;
root_type VehicleStatePos;
n my MCAP writer implementation, I have registered a single FlatBuffer schema with the name "vehicle_sim". To handle the separate writing of speed and position, I am currently using multiple channels associated with this single schema:
mcap::Schema MySchema("vehicle_sim", "flatbuffer","binary");
writer.addSchema(MySchema);
mcap::Channel SpeedChannel("speed", "flatbuffer", MySchema.id);
writer.addChannel(SpeedChannel);
mcap::Channel PosChannel("pos", "flatbuffer", MySchema.id);
writer.addChannel(PosChannel);
My questions are:
Is this the most efficient or recommended way to handle selective logging of different data types that share a common serialization format (FlatBuffers) but are written independently based on value changes? Using multiple channels seems to introduce some overhead and might complicate later If i want to add more data's.
In the mcap::Schema constructor, how do I correctly provide the binary representation of my FlatBuffer schema (binary in my current code)? Since I have two root types in separate .fbs files, what binary data should I be providing here to represent a schema that can encompass both VehicleStateSpeed and VehicleStatePos (even though I'm writing them separately)?
Is there a more streamlined approach using a single channel and a single FlatBuffer schema to achieve the goal of writing only changed values for different data fields? For example, could I have a single schema with optional fields for speed and position, and then only populate and write the fields that have changed in a given message? If so, how would the FlatBuffer schema and the MCAP writing process look in this scenario?
I am looking for guidance on best practices for this kind of selective logging with MCAP and FlatBuffers to ensure efficiency and maintainability.
Beta Was this translation helpful? Give feedback.
All reactions