Repository navigation
log-parser: Periodically flush contexts based on log timestamps - #327
Conversation
ContextTracker::flush took an Option<SystemTime>, where None meant flushing everything. This splits it into flush(before) and flush_all() to make the intent explicit at call sites. This also adds ContextTracker::latest, which returns the end time of the most recent event group handled, resolved to the system time. That allows crau-query to drive the periodic flush by the log timestamps without converting them on its own, so resolve_system_time is made private again. Signed-off-by: Daiki Ueno <dueno@redhat.com>
crau-query filtered the root contexts returned from ContextTracker::flush by the --since and --until options on its own. This moves the filtering into the tracker with ContextTracker::set_range, taking any RangeBounds<SystemTime>, so that a root context is returned only if both its start and end are within the range. The contexts outside the range are still tracked until flushed, so that their descendants are not mistaken for root contexts. This also adds ContextTracker::is_range_exhausted, which tells whether any subsequent flush could return a root context within the range. Signed-off-by: Daiki Ueno <dueno@redhat.com>
Previously crau-query kept all the contexts in the log in the ContextTracker until the end, which made processing large log files slow, as the tracker's lookups scale with the number of tracked contexts. This flushes the contexts started more than the event window ago, similarly to crau-monitor, but using the timestamps recorded in the log instead of the system time. The event window is configurable with the --event-window option or event_window in the config file, in milliseconds, defaulting to 10 seconds. Signed-off-by: Daiki Ueno <dueno@redhat.com>
Once the contexts started up to the event window before the end of the --until range have been flushed, no further contexts can match, as long as the log is ordered by timestamps. This makes crau-query stop reading the log at that point, instead of processing the rest of the log only to discard the contexts. Signed-off-by: Daiki Ueno <dueno@redhat.com>
serde_cbor's Deserializer::from_reader doesn't buffer the input by itself, so reading directly from File issued many small read(2) calls, which dominated the processing time of large log files. Signed-off-by: Daiki Ueno <dueno@redhat.com>
ContextTracker::flush checked every tracked context against every removed context tree, and every entry of the parent tables against all tracked contexts, which made flushing quadratic in the number of contexts. This collects the removed contexts (by pointer) and the IDs of the remaining contexts into hash sets first. As both checks only test membership, reused context IDs are handled as before. Signed-off-by: Daiki Ueno <dueno@redhat.com>
Previously crau-monitor flushed the root contexts started before the previous flush time plus the event window. If more than the event window had passed since the previous flush, a newly created root context was not flushed at its own timeout, but only at the timeout of the next root context, if any. This makes each timeout carry the end time of the event group that created the root context, as seen by the tracker, and flush the contexts started up to that time. Using the tracker's notion of time avoids comparing it with the system time, as the boot time it is based on is only accurate to a second. This also flushes all the remaining contexts on shutdown, instead of dropping them. Signed-off-by: Daiki Ueno <dueno@redhat.com>
The-Mule
left a comment
There was a problem hiding this comment.
This is pretty neat, I did some very basic performance test on a sample log generated thanks to encode/trace modules added by one of the previous PRs :) and results are impressive:
- ~10 MB log (2000 handshakes): before ~40s, after ~2s
- ~100MB log (20000 handshakes): before - cancelled after 15mins, after ~22s
It's still eating a lot memory (in peak it's ~4x log size from what I see) , I am not sure why and if it can be addressed so it's more like FYI.
All in all I think this is good. I did mostly perf testing rather than careful code review but I don't see any obvious blunder in the code.
|
I think @neverpanic has some performance testing from the last time and it might be interesting to see his results too. |
|
I had attached the trace of my example to https://redhat.atlassian.net/browse/CRYPTO-25033, which @ueno has already tested and seem a lot of improvement. |
Previously crau-query kept all the contexts in the log in the
ContextTracker until the end, which made processing large log files
slow, as the tracker's lookups scale with the number of tracked
contexts. This flushes the contexts started more than the event
window ago, similarly to crau-monitor, but using the timestamps
recorded in the log instead of the system time.
The event window is configurable with the --event-window option or
event_window in the config file, in milliseconds, defaulting to 10
seconds.