syncthing icon indicating copy to clipboard operation
syncthing copied to clipboard

Inotify support

Open jpjp opened this issue 12 years ago • 116 comments

To notice changes more quickly.

jpjp avatar Jan 06 '14 15:01 jpjp

The other advantage of this would probably be reduced power usage.

jpjp avatar Jan 14 '14 19:01 jpjp

Yep.

calmh avatar Jan 14 '14 20:01 calmh

Btw, this is on top of the todo list now.

calmh avatar Jan 14 '14 21:01 calmh

Great!

jpjp avatar Jan 15 '14 06:01 jpjp

This turns out to be not doable using the currently (or soon) available APIs in Go. See http://goo.gl/MrYxyA for some discussion of the problems; in short it doesn't scale on any of the BSDs, including Mac. Possibly something non portable could be implemented for Mac (fsevents), Linux and Windows separately but that's a significant amount of work. Hopefully someone else will do that and package it up. :) Until then, this will have to be put on the back burner.

calmh avatar Jan 18 '14 03:01 calmh

Okay. Back burner for Linux too?

jpjp avatar Jan 18 '14 09:01 jpjp

I wonder if it's worth using https://github.com/howeyc/fsnotify in the meanwhile?

johnsto avatar Jan 21 '14 16:01 johnsto

It suffers from the same problem - not using the recursiveness support that the OS might have. This means that for a directory structure like

dir/
dir/file
dir/dir_b/
dir/dir_b/file
dir/dir_c/
dir/dir_c/file

we need to put watches on (and consume one file descriptor per) dir, dir/dir_b and dir/dir_c to catch changes to the files. That doesn't scale.

calmh avatar Jan 22 '14 10:01 calmh

For example, on my Mac the default fd limit is 256, and the number of directories in my directory to sync is significantly higher;

jb@jborg-mbp:~ $ ulimit -n
256
jb@jborg-mbp:~ $ find -L Sync -type d | wc -l
    2424
jb@jborg-mbp:~ $ 

The limit can of course be raised, but there's a hard max somewhere and the exact limits are system specific. It sometimes working, sometimes not working and sometimes working to start with but then not working later would not be awesome behavior.

calmh avatar Jan 22 '14 10:01 calmh

How about syncthing let something else do the watching, then accept events from that? inotifywatch is a binary that will monitor a directory recursively. Perhaps the output could be parsed or it could be setup to pass the information to syncthing so that the inotify stuff stays separate?

jpjp avatar Jan 22 '14 13:01 jpjp

Inotifywatch is a Linux thing.

calmh avatar Jan 22 '14 14:01 calmh

Yes, it's just an example of an external program that feeds data to syncthing.

jpjp avatar Jan 22 '14 14:01 jpjp

Actually, no, that doesn't work either. inotify isn't recursive either, so has the same scalability problems.

jb@syncer:/data/syncer$ inotifywatch -r sync/
Establishing watches...
Failed to watch sync/; upper limit on inotify watches reached!
Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'.

calmh avatar Jan 22 '14 15:01 calmh

What we could do is use inotify/kqueue/etc for the case where there is only a handful of directories to sync, then fall back to scanning when it doesn't work any more. Personally I think that's pretty crappy and the only gain is to discover changes faster than the scanning interval -- the CPU load of doing the scanning is anyway pretty negligible since we've established there are only a handful of directories to start with...

calmh avatar Jan 22 '14 15:01 calmh

I'd say that's a reasonable compromise, and one could expose the directory limit for users who have raised their system's limits and want to push it further (and/or know what they're doing).

johnsto avatar Jan 22 '14 16:01 johnsto

Yeah, I think switching behaviour is fine as long as you tell the user when you do this, otherwise they will see a sudden degradance in the functionality of syncthing and not know what has happened.

jpjp avatar Jan 22 '14 17:01 jpjp

inotify support could be useful for rapidly changing files, it would avoid the delay.

jpjp avatar Mar 05 '14 07:03 jpjp

Hi I think that would be easier on linux systems stay with fanotify ( http://lwn.net/Articles/339253/ ), usually Anti-Virus implementations uses fanotify because you won't need a fd per directory or even create new inotify handlers for new folders on the fly. There's a good implementation of fanotify for GO ( https://godoc.org/bitbucket.org/madmo/fanotify ) I am using this one to scan uploaded files using clamav.

ncode avatar Mar 07 '14 09:03 ncode

Another tool that has already solved this problem & has implemented a protocol is Facebook's watchman so perhaps including support for that would be beneficial?

nogweii avatar Mar 18 '14 01:03 nogweii

Indeed, that could be a solution.

calmh avatar Mar 18 '14 15:03 calmh