-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
Reduce excessive CPU usage when serializing breadcrumbs to disk #4181
base: main
Are you sure you want to change the base?
Conversation
Performance metrics 🚀
|
@Override | ||
public void setBreadcrumbs(@NotNull Collection<Breadcrumb> breadcrumbs) { | ||
serializeToDisk(() -> store(breadcrumbs, BREADCRUMBS_FILENAME)); | ||
if (breadcrumbs.isEmpty()) { |
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 it wanted?
i get clearing the queue if the breadcrumb list is empty, but we are not doing anything if the list is full
|
||
final Converter<T> converter; | ||
|
||
FileObjectQueue(QueueFile queueFile, Converter<T> converter) { |
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.
l
: missing final
and @NotNull
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.
Just a question regarding setBreadcrumbs()
, but it's good
📜 Description
QueueFile
(vendored from https://github.com/square/tape) which allows us to write breadcrumbs atomically one-by-one using RandomAccessFile under the hoodmaxElements
and works as a ring buffer based on the number of elements in the queueresetCache
method that cleans up the disk cache on every init (but after the ANR processing is done) to ensure clean state and that we don't enrich with outdated scope valuesBefore
After
💡 Motivation and Context
Closes #3168
💚 How did you test it?
manually + automated
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps
Another potential improvement could be to batch breadcrumbs in-memory first, before writing to disk, and then flush every 1-2 seconds as batches to reduce I/O even further. The trade-off would be that we can lose some important breadcrumbs if an error occurs right within that timeframe. For now I would still like to keep it as-is, but if we receive further reports about excessive I/O we can implement that improvement too. I'm leaving the code snippet here so we can come back to it later and just copy-paste it:
Code snippet for batched writes
as a result we just had 2 I/O writes:
