-
Notifications
You must be signed in to change notification settings - Fork 484
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
Documenting memory usage/management by BatchLogProcessor #2469
base: main
Are you sure you want to change the base?
Documenting memory usage/management by BatchLogProcessor #2469
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2469 +/- ##
=======================================
+ Coverage 77.8% 79.5% +1.6%
=======================================
Files 122 118 -4
Lines 23061 22526 -535
=======================================
- Hits 17956 17909 -47
+ Misses 5105 4617 -488 ☔ View full report in Codecov by Sentry. |
@@ -167,6 +167,72 @@ enum BatchMessage { | |||
|
|||
/// A [`LogProcessor`] that buffers log records and reports | |||
/// them at a pre-configured interval from a dedicated background thread. | |||
// **Memory Management in BatchLogProcessor** |
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.
a lot of these can be moved off to docs.rs itself, as they are good for users to be aware of.
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.
The contents are very good. Lets plan to move them to user-facing docs before stable release.
// 1. **Record Ingestion**: | ||
// - Each `LogRecord` is **cloned** upon entering the processor. | ||
// - `LogRecordAttributes` utilize a hybrid memory model: | ||
// - Attributes up to `PREALLOCATED_ATTRIBUTE_CAPACITY` are **stack-allocated**. |
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.
Since PREALLOCATED_ATTRIBUTE_CAPACITY
is not a public const
, lets write the exact number of attributes here. I would suggest something like this:
- The first 5 attributes are allocated on the stack.
- Any additional attributes are allocated on the heap in a dynamically growing vector.
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.
Done
// | ||
/// 5. **Memory Limits**: | ||
/// - **Worst-Case Memory Usage**: | ||
/// - **Queue Memory** = `max_queue_size * size of boxed (LogRecord + InstrumentationScope)`. |
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'd be nice to mention the actual size of LogRecord
and InstrumentationScope
in bytes to get a better idea of the memory consumption.
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.
Good point, have added some numbers of memory usage in worst case scenario, with average size of LogRecord and InstrumentationScope.
// are moved into this temporary vector using `logs.split_off(0)`. | ||
// - Ownership of the boxed records is transferred to the new vector, ensuring efficient | ||
// memory usage without additional cloning. | ||
// - The temporary vector is then used to construct references passed to the exporter via `LogBatch`. |
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'd be good to mention that there two temporary vectors created during each export:
- One vector is created by
split_off(0)
(we could avoid this if we pursue Avoid vec allocation during each export for BatchLogProcessor #2483) - The second vector is created by collecting references from the first vector mentioned above.
I think we should be able to avoid the second vector creation as well by updating LogBatch
constructors.
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 created #2488 to showcase one approach to avoid the vec allocation mentioned in the second point.
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.
Have updated the document as per the latest optimizations, where both these vectors usage is removed.
Have moved them as doc comment. |
/// | ||
/// 1. **Record Ingestion**: | ||
/// - Each `LogRecord` is **cloned** upon entering the processor. | ||
/// - `LogRecordAttributes` utilize a hybrid memory model: |
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.
How attributes are stored inside LogRecord is not a concern of BatchLogProcessor. It can be documented (and should be!), but not in processor doc.
/// to allocate them on the heap before entering the queue. This means: | ||
/// - The `LogRecord`'s inline attributes (if any) are moved to the heap as part of the boxed structure. | ||
/// - Any dynamically allocated data already on the heap (e.g., strings, overflow attributes) remains unaffected. | ||
/// - Ownership of the boxed data is transferred to the queue, ensuring it can be processed independently of the original objects. |
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.
Not sure I follow this.. The data inside box is already a clone, so it is already independent of originals right?
/// - **Control Message Queue**: | ||
/// - Stores control messages (`BatchMessage`) to manage operations like exporting, force flushing, setting resources, and shutting down. | ||
/// - The control message queue has a fixed size (e.g., 64 messages). | ||
/// - Control messages are processed with higher priority, ensuring operational commands are handled promptly. |
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.
is there anything we do to process them with higher priority? This does not match the implementation.
/// - Messages supported include: | ||
/// - `ExportLog`: Triggers an immediate export of log records. | ||
/// - `ForceFlush`: Flushes all buffered log records to the exporter. | ||
/// - `SetResource`: Updates the exporter with a new resource. |
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.
this is misleading. There is no ability to update a resource. This could be misinterpreted as Resource can be changed and processor will be informed of the same, which is not true.
/// - The vector’s capacity is fixed at `max_export_batch_size`. | ||
/// - Records are **moved** (not cloned) from the log record queue to the vector for processing. | ||
/// | ||
/// 4. **Export Process**: |
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.
this looks too much details for end users to care about!
/// | ||
/// 7. **Control Queue Prioritization**: | ||
/// - Control messages take precedence over log record processing to ensure timely execution of critical operations. |
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.
This does not look like how BatchProcessor works.
Changes
Felt it would be good to document it for better understanding of the memory management by BatchLogProcessor. This is not the doc-comment so won't go the docs.rs. If there is better place to add this, please suggest.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes