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

Linux inotify poller wastes an OS thread #240

Closed
WGH- opened this issue Mar 24, 2018 · 3 comments
Closed

Linux inotify poller wastes an OS thread #240

WGH- opened this issue Mar 24, 2018 · 3 comments

Comments

@WGH-
Copy link

WGH- commented Mar 24, 2018

Every Watcher instance does unix.EpollWait in a loop inside a goroutine. Since this is direct syscall, which circumvents Go runtime poller, it wastes entire OS thread. If you create N watchers, N OS threads will be doing nothing except waiting in epoll_wait syscall.

This can be theoretically fixed, because both inotify fd and even epoll fd are pollable.

There's even convenient method in internal/poll (https://golang.org/pkg/internal/poll/#FD.RawRead) which does what we want. However, internal packages are not acessible from third-party code.

I'm not sure it's even fixable in current Go. There're many related issues in the Go bug tracker which are not yet resolved (probably not a complete list): golang/go#15021 golang/go#24331 golang/go#22939

@WGH-
Copy link
Author

WGH- commented Sep 14, 2020

It's already fixable in modern Go, by the way.

@horahoradev
Copy link
Member

horahoradev commented Feb 27, 2022

I'm working on this. I currently have a basic implementation.

Essentially, I:

  • deleted all of the epoll/poller code
  • set inotify's FD to nonblocking, added it to the runtime IO poller with os.NewFile
  • swapped out the poller.Wait() call for .Read(), which will return early if the file is closed

I'll run through this again tomorrow to see if either I have any flaws in my logic or anything can be improved.

@arp242
Copy link
Member

arp242 commented Jul 24, 2022

Fixed with #434

@arp242 arp242 closed this as completed Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants