Run sync job only when files are created or changed

Nextcloud app has a feature, which allows it to run file sync when files are created/changed in a directory and otherwise be inactive - thus consume almost zero battery.

Could the same interfaces be used to implement a feature like that in syncthing? Meaning it runs when and only if a new file appears (or changes) in the specified directories on the phone.

This way, photos/screenshots would be immediately uploaded, but the app remains otherwise inactive. Same as the Nextcloud app does it. IIUC not even active connection to the server needs to be kept for this to work.

Is there any roadmap for the Android app or is it abandoned wrt new features?

Compatibility and security updates still happen, but when it comes to new features, unless someones steps in and volunteers to implement them themselves, I wouldn’t count on any sudden changes.

The features you want to have would need to be implemented on the app level. One problem though is that stopping and restarting Syncthing too often may consume more battery than just leaving it running all the time. This is especially true if you sync a lot of data, e.g. 100+ GB in my case, where restarting the app and rescanning all the folders alone takes 10+ minutes, so it’s much more feasible to just keep Syncthing running 24/7 with file watching enabled (and rescan intervals set to once per day or even something less frequent).

Thanks for the reply.

I understand the concern about rescans, that’s why it would be an extra option to have for lighter users like myself xD (still usually ~30 GB of photo/video data in my case though)

Furthermore, that could be solved by sending it SIGTSTP/SIGSTOP and SIGCONT at system level or by utilizing some cache if syncthing has any (probably not).

Check out the the battery usage metrics that Android tracks for every app to see how much Syncthing on your phone has been using.

As @tomasz86 already pointed out, setting the rescan interval to a high number (e.g. 86400 or 31536000) and letting Syncthing’s file watcher do its thing effectively does what you’re asking for.

Details and tuning options for filesystem watcher: https://docs.syncthing.net/search.html?q=watcher

Combined with Android’s battery optimization system which groups network connection requests, suspends apps, etc., there might not be significant battery life to eek out for Syncthing.

On my phone, this is the battery usage report for Syncthing after almost 9 hours:

The battery consumption can be reduced to almost zero. This is the battery consumption for the same task done by the two different auto-upload apps:

Besides that, Nextcloud actually uploads the files immediately while Syncthing takes up to a minute.

To be honest, the OS will show Syncthing being active all the time simply because of its ongoing notification. In other words, it will show being always active for many hours, however this doesn’t mean that the app has necessarily used any meaningful amount of battery during that time.

What does it say for you here?

image

As you can see, the background time is 4 days, however the actual battery usage is less than 1%, i.e. basically nothing to worry about, and I have Syncthing on the phone enabled 24/7 with run conditions turned off.

It boggles my mind how Android computes the battery stats, but Syncthing consumes way more than Nextcloud (it’s at the bottom of the list).

Still if this run-only-on-new-file kind of thing was implemented it would make Syncthing outright the best file sync app for Android out there. A lot of apps have this functionality (Immich, Nextcloud, EasySync)

I think you’ve been looking at battery usage/consumption a bit too out of context…

On a modern smartphone, the most power-intensive component is often the CPU, followed by the display, then the various radio transceivers, RAM, etc. The exact order can vary a bit from phone to phone, but the CPU, display and cell modem (especially 5G radios) are usually the top three.

Let’s say that the command sleep 86400 is executed in Linux, macOS, and/or Android. The sleep program is in memory and not in a paused (SIGSTOP) state, so therefore it’s going to be “running” for a full 24 hours, yet the CPU load will be 0% for at least 99.9% of the run time.

Technically speaking, sleep 86400 is going to spend 24 hours on battery power, but it’s really only going to be active for a fraction of a second the whole time. So a proper analysis requires a full system accounting of the CPU cycles, disk I/O, etc.

If Syncthing is running in the background and spending most of its time waiting for inotify watch notifications – consuming minimal CPU cycles while waiting – is it really using that much battery power?

Note that there’s also a huge difference in efficiency between NextCloud and Syncthing when it comes to syncing files. Nextcloud’s underlying network protocol is WebDAV which is much heavier weight compared to Syncthing’s custom protocol.

(NextCloud isn’t deficient and/or WebDAV is bad. It’s simply that it overall requires more system resources compared to Syncthing, especially as the number of files and/or sizes grows.)

That’s just Syncthing’s default settings which are user-configurable. From Syncthing’s “Understanding Synchronization” documentation page:

The watcher does not immediately schedule a scan when a change is detected. It accumulates changes for 10s (adjustable by fsWatcherDelayS) and deleted files are further delayed for 1min. Therefore it is expected that you experience a slight delay between making the change and it appearing on another device.

Keep in mind that lowering the threshold so that changes are immediately synced will do the complete opposite of your goal to minimize battery consumption.

1 Like

That’s been one of Syncthing’s features for several years. :wink:

Thanks for the detailed explanation. I understand. But then there’s the CPU time metric where Syncthing still has significant consumption, possibly duplicating work of existing Android’s internal processes.

Also, in my field of work (or related), when optimizing stuff for use with certain cloud providers, for money saving, sleep (in python/bash) often isn’t good enough.

I think my desire for this feature comes down to my specific (though I think most people have this) use case. There would be days when Syncthing isn’t triggered at all. When the phone’s screen is off, Syncthing wouldn’t be running at all either, as most likely nothing new is recorded/shot with the phone.

Thing is, it’s a phone, so hyperoptimizing for battery should never be considered too much as the mobile OSes are already doing absurd things like not even allowing background apps unless one goes out of their way to enable it (dontkillmyapp stuff).

When stating it like this, aren’t you seeing it a bit too much as an “upload”-tool instead of a bi-directional synchronisation tool?

That the screen is off does not mean that there’s nothing to sync. Other nodes may have picked up changes which they need to sync to this mobile device. Local automatic processes may happen which change files which are to be kept in sync. …

Yeah I would like to use it as one.

How is it possible to get the same effect for the desktop version to save my laptop battery a little bit?..

It would probably be very difficult to know how exactly to have a positive impact of any significance on the laptop battery in my opinion.

What I do is this. I don’t edit all day long. I only turn on syncthing when I have edited data otherwise it remains off.

If I know that I have done some work on my cell phone that needs to be synced I turn it on Let it sync and turn it off and same thing goes for my laptop.

I’ve never left it running 24/7.

As an alternative there are apps in the Google Play app store that let you sync files to an SFTP server and other Cloud servers at a set time of the day. I do this with my text messaging files. I have a program called foldersync that only activates every day at 2:00 a.m. does it sync and shuts off until the next day.

1 Like

As @wank said, most of the time there’s likely minimal effect on the laptop battery life. Otherwise it really depends on the laptop’s hardware specs. If it has a decent CPU and the files are on a SSD, then the battery drain will be tiny compared to the CPU and display.

There are various tools for analyzing power consumption, and Syncthing has a bunch of tuning options, but without knowing anything about your laptop (i.e. operating system, CPU, etc.) the only suggestion I have at the moment is to check out the https://docs.syncthing.net/users/tuning.html page.

Thank you very much for the link!

Tuning for Low Resources is the most interesting section for me!

1 Like