Skip to content

Allow sub-second watcher delay (use case: remote development) #7859

Closed

Description

@bard

I'm doing "remote development", where I edit sources locally, and they're compiled/executed on a remote, faster machine.

I'm currently using lsyncd. Syncthing can almost cover this use case; unfortunately, it introduces unnecessary latency due to fsWatcherDelayS, which can't be set lower than one second. Depending on circumstances, this reduces or even cancels out the advantage of compiling/executing on the faster machine.

Ideally, it would be possible to specify a fractional fsWatcherDelayS, or an integer fsWatcherDelayMs.

Activity

  1. added
    enhancement
    needs-triage
    on Jul 31, 2021
  2. AudriusButkevicius commented on Jul 31, 2021

    @AudriusButkevicius
    Member

    I don't see syncthing as a zero latency mirroring application.

    There is a cost associated with starting a scan, so I am not sure that doing on every file change is feasible, so I think you are simply using the wrong tool.

  3. calmh commented on Jul 31, 2021

    @calmh
    Member

    Well, I mean, that’s a trade off that might be legitimate, so I don’t think we need to enforce it. There will presumably be some natural batching anyway for changes happening while we’re scanning the previous changes.

  4. AudriusButkevicius commented on Jul 31, 2021

    @AudriusButkevicius
    Member

    I fear that the behaviour will not be what the user expects, given scanning and syncing is exclusive.

  5. bard commented on Jul 31, 2021

    @bard
    Author

    I think I'm missing some important pieces of the puzzle. I thought that the mode of operation is:

    1. receive change notification
    2. receive change notification
    3. receive change notification
      [...]
    4. when no change received for fsWatcherDelayS seconds:
      a. scan files for which a notification was received
      b. synchronize

    If that's correct (which might totally not be, I haven't dug deep into the sources), then the cost of 4a is proportional to the number of files, and unless one types real fast, I don't foresee many saves in less than one second. :) Also, fsWatcherDelayS is per-folder, so it would seem safe to give the option.

    Again, writing all this without deep knowledge of the internals.

    FYI, there's at least one project that is relying on Syncthing for remote development: https://github.com/okteto/okteto. (I did try it but ran into the latency issue.)

  6. AudriusButkevicius commented on Jul 31, 2021

    @AudriusButkevicius
    Member

    There is a some cost for setting up step 4, getting database snapshots, locks etc. With "no delay", that cost would have to be paid on every file change., potentially introducing enough latency that dropping the delay below 1 second wouldn't make much difference.

  7. bard commented on Jul 31, 2021

    @bard
    Author

    I did a quick test by applying a one-line hack in aggregator.go to switch from seconds to milliseconds, and left fsWatcherDelayS at the default value of 10. I must say it works even better than I hoped. This is the effect when sharing the syncthing source repo with a remote machine (on the left) which is ~30ms ping time away:

    screencast

    As I said, just a hack, no pretense of contributable code:

     }
     
     func (a *aggregator) updateConfig(folderCfg config.FolderConfiguration) {
    -	a.notifyDelay = time.Duration(folderCfg.FSWatcherDelayS) * time.Second
    +	a.notifyDelay = time.Duration(folderCfg.FSWatcherDelayS) * time.Millisecond
     	a.notifyTimeout = notifyTimeout(folderCfg.FSWatcherDelayS)
     	a.folderCfg = folderCfg
     }
  8. AudriusButkevicius commented on Jul 31, 2021

    @AudriusButkevicius
    Member

    Changing that variable to be milliseconds is not "free", as it requires a config migration, and the old field will have to be present in the config structure potentially forever.

    Allowing value of zero is not sensible, as if you did something like a git checkout k8s project, it would end up consuming unreasonable amount of resources.

    Personally, I'd say that perhaps maintaining a fork for your use case is the right way forward here, but that is my opinion, and other maintainers might have a different view.

  9. calmh commented on Jul 31, 2021

    @calmh
    Member

    It might be mostly free to change the type to float and keep the seconds unit.

  10. tomasz1986 commented on Aug 2, 2021

    @tomasz1986
    Member

    Allowing value of zero is not sensible, as if you did something like a git checkout k8s project, it would end up consuming unreasonable amount of resources.

    I changed

    if f.FSWatcherDelayS <= 0 {
    f.FSWatcherEnabled = false
    f.FSWatcherDelayS = 10
    }

    to

     if f.FSWatcherDelayS < 0 { 
     	f.FSWatcherEnabled = false 
     	f.FSWatcherDelayS = 10 
     } 

    and then compiled a custom build. I created a new folder, set the watcher delay to 0, and then ran a piece of software inside it that creates and modifies thousands of files very quickly. As expected, Syncthing was picking up the changes almost immediately as they were taking place. I didn't experience any extraordinary resource usage though (on Ryzen 4350G with a mid-range SSD). The Web GUI was indeed going a little crazy, changing the folder status back and forth almost constantly.

    Nevertheless, would it bring any harm if a value of 0 was simply allowed for special cases like the one described here? Syncthing already allows much more dangerous custom configuration (e.g. disable fsync, etc.). There is no danger in this one except for potentially higher resource usage, right?

    Edit:

    There is also this part of the code:

    // Events that involve removals or continuously receive new modifications are
    // delayed but must time out at some point. The following numbers come out of thin
    // air, they were just considered as a sensible compromise between fast updates and
    // saving resources. For short delays the timeout is 6 times the delay, capped at 1
    // minute. For delays longer than 1 minute, the delay and timeout are equal.
    func notifyTimeout(eventDelayS int) time.Duration {
    shortDelayS := 10
    shortDelayMultiplicator := 6
    longDelayS := 60
    longDelayTimeout := time.Duration(1) * time.Minute
    if eventDelayS < shortDelayS {
    return time.Duration(eventDelayS*shortDelayMultiplicator) * time.Second
    }
    if eventDelayS < longDelayS {
    return longDelayTimeout
    }
    return time.Duration(eventDelayS) * time.Second
    }

    Currently, with the shortest possible watch delay of 1, the deletion delay is 6, right? Will deletion delay also become 0 when watch delay is set to 0?

  11. calmh commented on Aug 2, 2021

    @calmh
    Member

    Logically it should. I think this is fine. You'll miss out on rename optimizations and whatnot, but if you're tuning this for Ultimate Speed(tm) then that's what you're tuning for.

  12. added a commit that references this issue on Sep 15, 2021
    1339e4e
  13. removed
    needs-triage
    on Jan 29, 2022
  14. Hubro commented on Nov 20, 2022

    @Hubro

    Crap. I'm using syncthing for the same reason as the issue author. I've spent several hours setting up syncthing on my local PC and on my remote server through Docker, and only now do I find out it's too slow for my use case, it takes 8-9 seconds from I hit save until the remote file is updated.

    Was this issue ever resolved? Can I tune syncthing to be faster? (Preferably sub-second?)


    EDIT: Ah, I'm a sloppy reader, I just now noticed the fsWatcherDelayS setting. I reduced it to 1 and it drastically improved things. There's still a 1-2 second delay, though. Is there currently anything that can be done to reduce it?

  15. tomasz1986 commented on Nov 20, 2022

    @tomasz1986
    Member

    Unfortunately, no. In the linked PR, I got stuck on code related to usage reporting and wasn't able to finish it. Someone with better Go skills should probably be able to accomplish this quite easily.

    At the moment, the value of 1 will allow Syncthing to sync new files and modifications in 1 second, and deletions in 6 seconds.

  16. bard commented on Mar 17, 2023

    @bard
    Author

    @Hubro sorry I didn't see this sooner. I've been using a minimally patched version without problems for more than a year at this point: https://github.com/bard/syncthing/tree/instant-sync (it's not in sync with upstream though).

    It works just fine with sub-second delays, file synchronization is near immediate and I haven't seen side effects (e.g. when synchronizing large amount of files).

    The only thing preventing official Syncthing from doing the same is that the configuration delay parameter is implemented as an integer. In the fork, I hacked around thtat by leaving the parameter as integer but making Syncthing interpret it as milliseconds. I've tried to make a case in this issue for a proper fix, changing the parameter type to a float (see discussion above) but without luck.

  17. calmh commented on Mar 18, 2023

    @calmh
    Member

    There. You'll have to configure it manually in the config file though, because the advanced config editor doesn't accept floats and I couldn't figure out why in a reasonable amount of time (it's an <input type=number> 🤷 )

  18. tomasz1986 commented on Mar 18, 2023

    @tomasz1986
    Member

    There. You'll have to configure it manually in the config file though, because the advanced config editor doesn't accept floats and I couldn't figure out why in a reasonable amount of time (it's an <input type=number> 🤷 )

    I think this may be browser-dependent? I've just tried in Chromium, and I can input numbers like 0.1 or 0.01 with no problems (and they do save properly into config).

    By the way, thank you very much for completing the PR 🙂.

  19. bard commented on Mar 18, 2023

    @bard
    Author

    Woah, this was quite the surprise. Thank you both. :)

    About the <input>: I couldn't immediately find it (happy to have a look — can you point me to it?) but usually fiddling with the min and step parameters tames float-related matters.

  20. calmh commented on Mar 18, 2023

    @calmh
    Member

    It's in the auto generated advanced editor:

    <input ng-if="inputTypeFor(key, value) != 'list'" id="folder{{folderIndex}}Input{{$index}}" class="form-control" type="{{inputTypeFor(key, value)}}" ng-model="folder[key]" />

    The inputTypeFor(...) method returns number for all numeric inputs. I suspect the rest of the problem is somewhere in angular, which I'm not interested in trying to debug. Also, making an exception for this field specifically is tricky given how all this is auto generated from the actual config json.

  21. added this to the v1.23.3 milestone on Mar 29, 2023
  22. added a commit that references this issue on Apr 14, 2023
    b69598f
  23. Devocub commented on Jun 13, 2023

    @Devocub

    Please reveal shortDelayMultiplicator in Advanced settings.
    Also +1 to subsecond delays.

    Having forceful scans (not fsWatcher) writes 57 bytes each scan (every second) into "indexed*/*.log", While fsWatcher writes 109 bytes every 36 seconds. Would also be nice to disable these pointless? writes at all.

    Not related to issue but having some buffering (1-10s) is hugely beneficial when many small files sent to another device and another device immediately deletes them because each file issues ~4-5 kb writes to "indexed*/*.log".

  24. added a commit that references this issue on Jan 28, 2024
    358cf25
  25. added
    frozen-due-to-age
    on Mar 17, 2024
  26. locked and limited conversation to collaborators on Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrozen-due-to-age

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions