Skip to content

bisync: performance #7332

Closed
Closed

Description

setup

11,265 files - 290.743MiB (90MB in ~5 files the rest are smaller and more equal in size)

Results the same regardless of Wasabi or iDrive (iDrive typically performs a little faster in every test but only ~5-10% on average)

Remote is using crypt and base32768 encoding.

BW: ~1.5MiB UP ~5MiB DOWN

default/common flags

After testing best performing filters are: --transfers 64 --checkers 128 --fast-list

Along with this (--filter-from) or (--filters-file) is also used

e.g. --transfers 64 --checkers 128 --fast-list --filter-from/--filters-file ..

check

~8s on average and between 6.8s to 9.6s

ls

(using time as no info given with -v)

ls: 0m4.088s
lsl: 7m36.975s

sync

upload:
initial: 3m57.0s
subsequent: 18.6s

download:
initial: 2m9.0s
subsequent: 17.8s

copy

upload:
initial: 4m0.0s
subsequent 18.6s

download:
initial: 2m6.5s
subsequent: 16.8s

bisync

These are some of the best and would say are usually a little longer by upto 5 mins this is likely when resync is run when data is already present vs copying the data itself.. There are no changes made to files when moving between a --resync and normal run.

defaults:
resync: 10m47.0s
normal: 6m44.7s

defaults with ignore checksum: (--ignore-listing-checksum --ignore-checksum)
resync: 10m36.5s
normal: 6m31.9s

overview

So as you can see bisync is orders of magnitude slower than copy or sync . ls is incredibly fast as is sync and copy in both directions (e.g. uses up almost 100% of bandwidth)

I only ran the test of lsl and ls at the very end and now thinking that bisync relies on lsl as this so incredibly slow (as I believe bisync does not use checksum so would need lsl info to compare?).

I can do a local to crypt (local) bisync in 15s (--resync) and 8.7s for subsequent.

Is there something I am doing wrong? If not, are there plans/options available to rclone to improve the speed of bisync so that it is more in line with 2 x sync/copy commands (e.g. one upload, one download) or is this a limitation that is unlikely to be overcome? Also, if this is due to lsl taking so long is there a way to speed up lsl?

Thanks to you all for your hard work and a special thank you @nielash for all you've been doing on bisync and continue to do. I as many others massively appreciate it and when this tool is out of experimental stages it will be a game changer for so many. If I had any free time or money right now I would help out but unfortunately the best I can do is give you some benchmarks and user feedback.

Thanks

Activity

  1. nielash commented on Sep 23, 2023

    @nielash
    Contributor

    Thank you for the benchmarks and feedback! You are right -- bisync is currently much slower than copy or sync. This is for a few reasons, most of which I think are solvable. My multi-step plan to address this includes:

    • Apply filters correctly during deletes (fixed in v1.64.0 26ff813 )
    • Build and compare initial listings concurrently using March
      This should help a lot. Currently, bisync builds a full listing for Path1, then a full listing for Path2, then compares them -- and each of those tasks must finish before the next one can start. That's silly, as we could easily be doing most of these tasks concurrently, using the same March infrastructure that check and sync use. This would also solve another important issue I talked about here.
    • Merge copies and deletes
      Currently bisync makes its changes in a 4-step process:
    1. copy 2 to 1
    2. copy 1 to 2
    3. delete 2 to 1
    4. delete 1 to 2

    I believe we can condense this to just 2 steps:

    1. sync 2 to 1
    2. sync 1 to 2

    Both syncs would be filtered for only the individual files that need to be copied or deleted in that direction. I already have a local proof-of-concept for this that works beautifully, so I think it should be coming relatively soon. Incidentally, this change also paves the way for allowing bisync to support --track-renames (which is supported only for sync, not copy.)

    • Eliminate the second listing
      This is probably the one that will make the most difference in terms of speed. Currently, if there are changes to sync, bisync lists each directory twice: once before the sync and once after. The second one causes quite a lot of problems, in addition to making each run much slower. I am currently working on a way to eliminate it by getting the underlying sync operation to report back a list of what it changed. This project is pretty far along, and the results are very encouraging so far!

    When all of the above are done, bisync will probably still be slightly slower than sync (because bisync has to do an extra listing, and 2 syncs instead of 1), but the difference should be much less dramatic than it is today.

    For bisync to ever truly be as fast as sync, it would have to (at minimum) merge the two sync operations together (or at least do them concurrently), and also merge the initial listing into the sync operation (similar to how checkers and transfers currently work during a sync -- note how the transfers are able to start working before all the checkers have completed!) These particular optimizations are not currently planned, but I do think they might be possible someday.

    In the meantime, one thing you might consider to speed up your runs slightly is --check-sync=false. --check-sync has some issues anyway at the moment, so in my opinion, you might be better off disabling it and replacing it with an occasional check, until this is more properly fixed in a future release. Disabling it will make the run slightly faster, because it will skip the step of re-loading both listings into memory at the end and comparing them.

    Thank you also for the kind words of encouragement! 😃

  2. self-assigned this
    on Sep 23, 2023
  3. added this to the Soon milestone on Sep 23, 2023
  4. nielash commented on Sep 25, 2023

    @nielash
    Contributor

    I have a systemd service that runs bisync on a timer/repeat. If I shutdown my computer and bisync is running it would require a full resync as pressing Ctrl+C would do when running in terminal

    An interrupted run is tough for bisync to recover from cleanly, because of its bi-directional nature. When sync is interrupted, it can be safely retried because the source is still intact, even if the dest was left in a messy state. But with bisync, both sides could be left in a messy state, if interrupted. Before v1.63.0, I would have said clean recovery is impossible, due to the possibility (on certain backends) of leaving a partially-written file on one path, which would then get erroneously copied to the other path on the next run. But now that we have "atomic downloads", I think this is worth another look.

    One challenge would be bisync's logic surrounding lock files and the saving of the "new" state for use by the next run. Currently bisync finalizes these only after a successful sync operation. Doing this after every individual transfer probably wouldn't be practical -- it would add too much overhead and too many writes to disk. The cleaner solution is probably the "retry from last successful snapshot on error" idea that I mentioned here. Essentially what this would mean is: if the most recent listing is untrusted (because, in this case, it was interrupted), and --resilient is specified, we would look instead to the one before that, and diff the current state against the last "trusted" state. This would effectively make it possible to recover from these kinds of errors by "retrying" on the next run.

    We would also need some way of distinguishing between lock files left by aborted runs vs. ones that are still running. Perhaps lock files should be considered "expired" after X number of minutes (configurable with a setting)? (And, thinking ahead: perhaps they should also get "renewed" every X-1 minutes by runs that are still running.)

    In the meantime, my recommendation is: try to wait to shut down your computer until you know the bisync run has completed. (FWIW: I have mine scripted to send me a push notification when it starts, and another with the exit code when it finishes.)

  5. nielash commented on Sep 26, 2023

    @nielash
    Contributor

    in my opinion the best option would be to check the PID alongside a regex similar to *.rclone.*.PATH1.*.PATH2 in the case the PID is reused for another application (rclone included). This would save any 'hackery' solution and get straight to the source.

    This would work well if you're running bisync on only one machine. However, one of our long-term goals is to make bisync more portable by allowing any remote path to be used as the --workdir (currently it is limited to local paths). One of the benefits of storing lock files on a non-local remote is that you could then easily use bisync to keep several devices in sync with a cloud storage provider, without the risk of syncing the same path simultaneously from different locations. The PID is less useful in this scenario, because each machine would not know the PIDs from the other machines. (They also would not be unique, but that could possibly be solved by adding some kind of machine/location identifier.)

    I do not see a reason you couldn't have a partial session where every 30s-1m the session data is updated so in a recovery situation rather than going back to the last complete session you can continue from the last complete session + partial session. However, this might be overkill.

    This is an interesting idea -- sort of analogous to an "autosave" feature. 30s-1m could be reasonable with a local --workdir, but may not be for other backends -- particularly ones that charge per API call. It would also slow down the run. But perhaps the option should exist as a setting, and then each user can decide what's right for them. I'm not sure that this method would have much advantage over the "retry from last successful" method... the one scenario I can think of where it would make a difference is:

    1. File changes on one side
    2. File is synced successfully during a run that later aborts
    3. Same file changes AGAIN before the next run
    4. File is synced again on next run

    Absent step 3, the results should be identical with either method. (With the "retry..." method, bisync should say "I see that the file has changed on both sides since the last successful run, but since the file currently matches on both sides, I can skip this and move on.")

    I have many bisync's running so it would be too hard to handle manually or with push notification as an aid.. So my current approach is going to have to be to catch any shutdown requests...

    I wonder if what you ultimately want here is something more like #966 (a way to tell all your running bisync processes to gracefully wrap-up early, when you want to shut down.) (See also: #1522)

  6. nielash commented on Sep 30, 2023

    @nielash
    Contributor

    Thank you so much for this detailed feedback! It is really helping me gain insight into bisync use cases that are different from my own, which is quite valuable 🙂 (As an aside, I wonder if it might be helpful to start a "bisync user feedback" group in the forum or something -- it would be really helpful to be able to easily survey a group from time to time on these kinds of design questions.)

    A few responses to your comments:

    What are the benifits of a remote --workdir? The only example I can think of is to make syncing the same two remotes in stateless application easier? If the only requirement is to lock a sync it seems like a lot of work with greater potential for error if multiple PCs with different listings use the same remote workdir.

    In a word: portability. This question sort of implies that at least one of the bisync paths is a local remote, and while I agree that's probably the most common use case for bisync, it's not technically a requirement. For example, bisync could just as easily be used to sync a drive remote with a dropbox remote. In this kind of scenario, it makes a little less sense to require that bisync must always be run from the same machine. Perhaps I'm traveling with my laptop and away from my main desktop machine -- if the listing files are in the cloud, I can seamlessly pick up on one machine where I left off on another. It also just strikes me as more "rclonic" -- in general, rclone is designed to be as stateless as possible, and avoid relying on sidecars, resource forks, or local databases. Bisync is currently one of the only rclone commands that does so (out of necessity, as bidirectional sync can never be completely stateless). So, in my (subjective) opinion, allowing a non-local --workdir brings us a little bit closer to rclone's platform-agnostic core principles, and the (unreachable) goal of having full feature parity between backends.

    It should also be noted that adding support for non-local --workdir does not mean removing any existing support for local -- so really nothing would change for users that wish to continue using a local --workdir. They can ignore this new feature and carry on like they did before.

    After, looking into how rclone handles conflict resolution, I would say a small change is needed in that the newest file should not be renamed rather kept as the master

    One of the most common complaints about bisync is that it currently refuses to operate on backends that lack modification time support. This is going to be solved soon by adding support for --checksum and --size-only. Once this is the case, there will no longer really be a concept of "newest" in a file-conflict situation -- all we can say is whether a file changed on both paths (since the last run), and whether or not the current version on one path is equal to the version on the opposite path. So, this would present a challenge to what you are proposing -- sometimes there is no "newest", only "different". I could imagine possibly implementing what you are suggesting as an optional flag for the rest of the time (when we do have modtime available on both sides), although personally I'm not sure I would use it. To me, the ..path1 / ..path2 rename is a helpful alert that something went wrong and needs my attention to resolve, so silently skipping this for one of the paths would give me a false sense of security. That said, I have no objection to implementing features I don't personally plan to use (I much prefer giving users the choice whenever possible), so if a sizable number of users want this, I'm happy to add the option. (This is a good example of something I'd love to poll the group about!)

    Also worth noting: even when both paths do support modtime, "deletes" still never have a modtime, just by their nature. (All we can say is that a file used to be there and now is not -- we can't say what time it was deleted, or whether it was deleted before or after the other path's version was last modified.)

    any conflicts are made using .conflict1, .conflict2 and so on over _PATH1, _PATH2 so it is more inline with the typical two-way sync. Naming the files ..path1 & ..path2 limits the number of conflict and can lead to further issues when multiple PCs are used at the same time. Should I open another issue for this?

    I'm not sure if I understand what you mean about this one. How does ..path1 / ..path2 limit the number of conflicts, and how would .conflict1 / .conflict2 solve that? Does this question rely on the the prior suggestion (of renaming only one side) being implemented? To make sure we're on the same page about the current behavior: the first conflict for file x results in x..path1 (for the Path1 side) and x..path2 (for the Path2 side). If the Path1 conflict were to have yet another conflict after that (and I'm not sure why that would happen, as it would mean opening x..path1 and editing it on both sides without renaming it first -- but let's just assume it did), you would then get x..path1..path1 and x..path1..path2, in addition to the pre-existing x..path2 which would remain unchanged. You could repeat this any number of times (limited only by filename length limitations from your backend...eventually.) I'm guessing that maybe what you would prefer is for subsequent conflicts to be named x..conflict3, x..conflict4, x..conflict5, etc. but my question then would be: how would you tell whether x..conflict5 came from Path1 or Path2? And how do you determine the winner when neither side can be considered "newest"?

    As bisync is stateful rather than stateless the only race condition I could think of is the same path being written at the same time?

    By "path" do you mean one individual file? That is certainly a concern, but I think it's also important to consider the risk at the directory level. When rclone walks directories recursively, the order can be unpredictable due to concurrency, among other things -- there's no guarantee that bisync A B and bisync A C will both list the directories of A in the same order. (The tradeoff is that concurrency is what makes rclone so fast.) So given that, now imagine a use case where the sync needs to be atomic at not just the file level, but also the directory level. For example, something like a source code repository, where all files in the tree must be from version 1 or else all files in the tree must be from version 2. You can't end up with one subdirectory from version 1 and another from version 2 in the same repo -- the application won't work. This is the kind of problem we could miss if we only worry about conflicts between individual files and consider each file an island. So, while you're right that the chance of writing any individual file at the exact same time from two locations is fairly small, the chance of doing the same thing to a directory is much larger -- the race condition window could be even hours or days-long, if the files are particularly large. A directory-level conflict could occur without any of its containing files having a file-level conflict. Most concurrent applications solve this problem with a mutex or other kind of locking mechanism, and that is why bisync uses "lock files", although the implementation is imperfect at the moment because the mutual exclusion enforcement doesn't extend to other machines (nor does it detect tree overlaps even within the same machine.) To give credit where credit's due, though, the original designer of bisync (not me, to be clear) realized this problem and made sure to include this warning in the docs:

    "Note that while concurrent bisync runs are allowed, be very cautious that there is no overlap in the trees being synched between concurrent runs, lest there be replicated files, deleted files and general mayhem."

    Another common scenario where mutual exclusion matters at the directory-level is a "project folder" like the kind often created by media editing applications (Pro Tools, Adobe Premiere / Illustrator, Apple Logic Pro, etc.) These apps expect all the source media files to be from the same project version (for example, video editors often throw errors if the video file they find at a particular path doesn't match the length of the clip in the timeline.) This kind of data corruption is not something we can catch by looking solely for conflicts between individual files.

    With regards to session, my view is if the workdir is local then this should happen regularly at reasonable and predefined interval and perhaps disabled by default when remote

    I think we may be using the word "sessions" to mean different things (I'm using it as defined here), but setting that aside, I think we generally agree on the substance -- it would be ideal for bisync to be more prepared for the possibility of an unexpected interruption, and it should require --resync as little as possible. I think where we might differ slightly is our preference when faced with the inevitable tradeoff between convenience and safety. While I'm no fan of being asked to --resync, I still would rather be asked than have bisync take a "best guess" on my behalf and guess wrong. One of the main reasons I chose bisync (and rclone as a whole) in the first place is because of how it prioritizes safety where other sync tools prioritize convenience or resilience. I feel comfortable entrusting important files to bisync precisely because it will err on the side of stopping and asking me for help when its only alternative is to guess. I fully acknowledge that some users will prefer a different tradeoff and may be fine settling for a standard where data corruption is just "unlikely" -- but I can't assume that every user will be ok with that. So, I plan to maintain bisync's original philosophy of being "(too) safe by default", but changeable with flags for advanced users. (My recent addition of --resilient mode is an example.)

    To sum up where I think I am regarding crash recovery: I think there are definitely some meaningful improvements we can and should make, and in particular I like your idea of an "autosave"-like feature that is disabled by default when --workdir is remote (and I'd say possibly when local too -- unless careful testing finds the performance overhead to be basically negligible.) To be totally transparent, I think it will likely take me awhile to get to it, as I think bisync has several other more pressing issues, and I also don't find "don't pull the plug while it's running" to be an unreasonable or excessively burdensome expectation in the meantime (but again, that's not to say we shouldn't try to improve it -- we should.) You are also of course welcome to submit a Pull Request at any time, if you would like to. You might also consider checking out some bisync alternatives (such as syncrclone) that make some different choices with regard to some of these tradeoffs.

    I've implemented the method described in my previous comment which seemingly works well for my use case.

    Glad to hear that! I'd also be interested to know a little more about your use case (only if you're inclined to share) and why it requires so many different bisync processes to be running simultaneously. For example -- could it not be solved by combining the various paths into one tree and then bisyncing them all in one bisync run? Also, how frequently do you schedule the runs, and what's the longest they normally take? (I think this info may help me conceptualize why curing the interruptions would be more practical than preventing them.)

    Thank you again for the thoughtful feedback! You've challenged my thinking in a good way 🙂

  7. nielash commented on Oct 1, 2023

    @nielash
    Contributor

    having a remote --workdir would require a complete change to --workdir to handle unique ids

    You are right -- it would. This is work that would have to be done when implementing the feature.

    The rest of your comments in this section describe why you personally do not wish to use a remote --workdir, which is fine -- you don't have to. There are others who do want such a feature. I think the only way it affects you is that it means we can't rely on PIDs as our locking mechanism -- but as I've explained, there would already be problems with doing so. At most, checking PIDs could offer some protection within the same machine, but it could not protect against the risk of race conditions caused by bisync runs on other machines.

    Also, a lock file is to do with the remote and not workdir.

    I agree this is a valid point, and I think it may be worth considering a separation -- such that you can have a remote lock file and a local --workdir. I think that might be my ideal combination.

    By very nature and for bisync to be fully functional requires a backend to support mod time. That's not to say that workarounds can't be put in place but simply when using bisync one should always be advised to use it with a backend that supports modtime.

    I disagree -- please read the following:

    I think where we do agree is that I personally would probably not ever use a backend that didn't support modtimes (and there are many.) But that is just my personal preference. There are many other users who feel differently and do want to use such backends. There are even many users who go out of their way to avoid using modtimes, even when the backend supports it. This is popular with S3-compatible backends, for example, for performance and money reasons. Bisync should be available to them too.

    Modtime is also imperfect -- it relies on the assumption that the underlying Fs is always updating it correctly, and that's not always true. It can be fooled (for example by using touch). It is not sensitive to bit rot. And even if it were perfect, "newer" does not always equal "better". There are times when a user does intentionally revert to an older version.

    I think the best compromise here is a --prefer newer flag that renames conflicts in the way you describe if modtime is available for both paths.

    Also PATH1 and PATH2 is ultimately meaningless as by very nature if wanting to bisync a remote that means you are expecting more than one person/pc to update the remote and would also assume the use of the same tool e.g. rclone (in general). So really it would only have meaning if you also include a PC/PERSON unqiue ID too as PATH1 and PATH2 could be different in each case e.g. ..PATH1..COMPUTER1

    This is a good point, and perhaps we should consider adding such a unique ID.

    • Directory 'dir' is deleted on machine A
    • On machine B somebody adds a file to 'dir' called 'file'
      I'm not sure how rclone handles this?

    This is explained in the docs. In short: the non-deleted path always wins (when one path is deleted and the other is new/changed). (But note that anything else in the dir, such as dir/file2, would still be deleted.)

    I guess I also struggle to see how concurrency changes the outcome of the sync if rclone is file based but perhaps I'm wrong about this.

    When there's only one run at a time, it does not change the outcome of the sync. The problem is when there's more than one run at a time. The outcome then depends on which machine gets to that directory first, and that is what cannot be predicted, because of concurrency (and potentially because of other things too, like differences in network speed, CPU/RAM, size of other jobs in the queue, etc).

    Like the above is kinda of obvious no? Like yes, if you try and edit stuff you've deleted on another machine then get ready for some issues when it tries to sync up.

    It's obvious to me, but I can't assume it will be obvious to everyone 😄

    But if it's obvious, then surely it is also obvious why a lock file must ideally exclude additional runs on any machine, not just the same machine.

    My setup is as such to create separation of different crypt keys, storage remotes, usage and local file path/location. Also to avoid too many files in one place as bisync in its current state simply can't handle the load.

    So, it sounds to me like the reason you have so many simultaneous bisync runs is:

    1. You have many different remotes
    2. Bisync currently is slow

    For 1, have you looked into the Combine backend? This is exactly what it's for.
    For 2, I agree -- bisync is currently slow. I'm working on improving that.

    Am I understanding correctly that if the speed issues were solved, and you combined your remotes with the Combine backend, you would no longer need multiple simultaneous bisync runs? Or is there an additional problem that I'm overlooking?

  8. 12 remaining items

  9. added a commit that references this issue on Jan 26, 2024
    fd95511
  10. moved this to Done in bisyncon Aug 20, 2024
  11. added a commit that references this issue on Jul 20, 2026
    83caec4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    Done

Relationships

None yet

Development

No branches or pull requests

Issue actions