Skip to content
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

[Filebeat] possible filestream performance regression on Windows #36694

Closed
andrewkroh opened this issue Sep 27, 2023 · 2 comments · Fixed by #37301
Closed

[Filebeat] possible filestream performance regression on Windows #36694

andrewkroh opened this issue Sep 27, 2023 · 2 comments · Fixed by #37301
Assignees
Labels
Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@andrewkroh
Copy link
Member

It looks like on Windows the filestream input calls OpenFile, GetFileInformationByHandle, and CloseFile twice for each log line read (six syscalls per line read). It would be good to get a second opinion on this. The code path is through:

err = setFileSystemMetadata(r.fi, message.Fields)

func GetOSState(info os.FileInfo) StateOS {
// os.SameFile must be called to populate the id fields. Otherwise in case for example
// os.Stat(file) is used to get the fileInfo, the ids are empty.
// https://github.com/elastic/beats/filebeat/pull/53
os.SameFile(info, info)

https://pkg.go.dev/os#SameFile

https://cs.opensource.google/go/go/+/master:src/os/types_windows.go;l=243-249?q=loadFileId&ss=go%2Fgo

Relates: #36065

@andrewkroh andrewkroh added Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team labels Sep 27, 2023
@rdner
Copy link
Member

rdner commented Nov 13, 2023

@andrewkroh thanks for discovering this, it comes to me as a surprise that os.SameFile opens and closes files on Windows, furthermore, it actually acquires a file system lock doing so.

The problem is this loadFileId function here:

https://cs.opensource.google/go/go/+/refs/tags/go1.21.4:src/os/types_windows.go;l=165-214

used by os.SameFile:

https://cs.opensource.google/go/go/+/refs/tags/go1.21.4:src/os/types_windows.go;l=231-241

As the comment states, this call is required on Windows to fill the IDs in:

fs.vol = i.VolumeSerialNumber
fs.idxhi = i.FileIndexHigh
fs.idxlo = i.FileIndexLow

I believe our code populates the IDs elsewhere, so we should be able to get rid of this os.SameFile call in setFileSystemMetadata by storing the values once they are set for the first time.

I'll have a deeper look as soon as I can.

@pierrehilbert we should prioritise this.

@pierrehilbert
Copy link
Collaborator

This is currently in our next sprint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants