-
Notifications
You must be signed in to change notification settings - Fork 0
ring buffer: store logs as proto instead of fb #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
cefd6fe to
11be406
Compare
For logs with many fields, the fact that fb is padded and doesn't use varint encoding leads to substantial overhead. This removes that overhead. As part of this change I went a bit over the top and also implemented a custom encoder for the Log proto which allows for zero copy into the ring buffer. This is better than the previous fb implementation which encoded and then did a memcpy into the buffer. Signed-off-by: Matt Klein <[email protected]>
| // Helpers for doing raw casts where we are sure the value fits and don't want to pay for | ||
| // checks and avoid clippy lints. | ||
| pub trait LossyIntToU32 { | ||
| fn to_u32(self) -> u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be called to_u32_lossy just to make it obvious?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
| ) -> u64 { | ||
| let mut my_size = 0; | ||
|
|
||
| my_size += ::protobuf::rt::uint64_size(1, occurred_at.unix_timestamp_nanos().to_u64() / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does nanos / 1000 come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's microseconds since epoch. I will add more comments everywhere.
| ) | ||
| } | ||
|
|
||
| pub fn serialize_proto_to_stream_inner( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously this means that we need to maintain this as more fields are added - any way to have a test fail in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah can do.
| os.write_uint32(2, log_level)?; | ||
| } | ||
|
|
||
| Self::serialize_proto_data(3, message, os)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed you checked but there's no constants available in the generated proto with the field IDs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so but will double check.
For logs with many fields, the fact that fb is padded and doesn't use varint encoding leads to substantial overhead. This removes that overhead. As part of this change I went a bit over the top and also implemented a custom encoder for the Log proto which allows for zero copy into the ring buffer. This is better than the previous fb implementation which encoded and then did a memcpy into the buffer.