Skip to content

Linux inotify poller wastes an OS thread #240

@WGH-

Description

@WGH-

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions