mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
journald: seek to time when --since is used
Instead of reading the full journal which can be expensive we can seek based on the time. If you have a journald with many podman events just compare the time `time podman events --since 1s --stream=false` with and without this patch. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -80,8 +80,15 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
|
||||
return fmt.Errorf("adding filter to journald logger: %v: %w", match, err)
|
||||
}
|
||||
|
||||
if err := journal.SeekHead(); err != nil {
|
||||
return err
|
||||
if options.Since.IsZero() {
|
||||
if err := journal.SeekHead(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// seek based on time which helps to reduce unnecessary event reads
|
||||
if err := journal.SeekRealtimeUsec(uint64(options.Since.UnixMicro())); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// API requires Next() immediately after SeekHead().
|
||||
if _, err := journal.Next(); err != nil {
|
||||
|
@ -121,6 +121,15 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error {
|
||||
if _, err := j.Previous(); err != nil {
|
||||
return fmt.Errorf("failed to move journal cursor to previous entry: %w", err)
|
||||
}
|
||||
} else if len(options.Since) > 0 {
|
||||
since, err := util.ParseInputTime(options.Since, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// seek based on time which helps to reduce unnecessary event reads
|
||||
if err := j.SeekRealtimeUsec(uint64(since.UnixMicro())); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
|
Reference in New Issue
Block a user