Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextcloud sync on Linux takes long time #3004

Closed
ebayer opened this issue Apr 7, 2020 · 30 comments
Closed

Nextcloud sync on Linux takes long time #3004

ebayer opened this issue Apr 7, 2020 · 30 comments
Labels
bug It's a bug desktop All desktop platforms linux sync sync related issue

Comments

@ebayer
Copy link
Contributor

ebayer commented Apr 7, 2020

Hello

Nextcloud linux client takes too long to finish sync. I have ~1000 notes and ~4000 resources and without encryption. I am using Nextcloud as sync target and Joplin Android version with same nextcloud settings takes 10 seconds to finish sync. However Linux desktop client takes more than 2 mins to sync.

Funny thing is, if I randomly change the visible note or toggle note list or sidebar a couple of times during the sync, operation finishes in 10 seconds like mobile sync.

It is as like there is an internal timer or tick waiting to trigger next request but get stuck until the UI gets another (unrelated) event.

I know this sounds wierd but I can record a video or something to better show what happens. I have already mentioned this in the forum: https://discourse.joplinapp.org/t/sync-with-nextcloud-fast-with-mobile-extremely-slow-on-linux/4017/23

This looks like #312 but I am not sure.

Environment

Joplin version: 1.0.197
Platform: Linux 5.5.7 x86_64
OS specifics: Opensuse Tumbleweed, Joplin installed with Joplin_install_and_update.sh

Steps to reproduce

  1. Setup nextcloud sync
  2. Trigger sync manually or wait for sync period
  3. Observe sync to take 12x longer
  4. Trigger sync manually again or wait for sync period
  5. Toggle note list or change active note to another one (does not matter which note or notebook)
  6. Observe sync to take 12x quicker

Logfile

Enabled debug console and logs as described in https://joplinapp.org/debugging/ but no errors during or after the sync. I am attaching the log file containing two sync operations, first unattended and second time toggling note list during entire sync operation.

log.txt

@ebayer ebayer added the bug It's a bug label Apr 7, 2020
@laurent22 laurent22 added high High priority issues desktop All desktop platforms labels Apr 7, 2020
@tessus
Copy link
Collaborator

tessus commented Apr 7, 2020

The following also has some great info and problem determination:

https://discourse.joplinapp.org/t/sync-with-nextcloud-fast-with-mobile-extremely-slow-on-linux/4017/11?u=tessus

@laurent22 laurent22 removed the high High priority issues label Apr 9, 2020
@laurent22
Copy link
Owner

Funny thing is, if I randomly change the visible note or toggle note list or sidebar a couple of times during the sync, operation finishes in 10 seconds like mobile sync. It is as like there is an internal timer or tick waiting to trigger next request but get stuck until the UI gets another (unrelated) event.

Hmm, ok it's that good old bug. I had a look at it a few years ago and none of the fixes I've tried worked. I think we'd need an Linux Electron or GUI expert to make sense of this weird bug.

@laurent22
Copy link
Owner

@bedwardly-down, have you ever heard of this kind of bug in Linux? And do you know of any workaround? Essentially, in some cases, sync is stuck on Linux till something updates the UI (for example, by switching notes, open menus, etc.).

The fixes I've tried:

  • When on Linux, force update the UI every x seconds while sync is running (doesn't work)
  • Disable Electron power saving features, which I thought could make the app sleep when it shouldn't (didn't work)

Also I've never managed to replicate this bug so it seems to only happen in certain environments.

@bedwardly-down
Copy link
Contributor

@laurent22, so far resetting the UI by enabling and disabling Webclipper in settings every time the client freezes during sync on 5.5 is the only thing that’s been found to work so far. And the kernel patch that’s supposed to fix the issue has no effect on Electron so far.

The issue is just as bad if not worse on 5.6. @ebayer, can you try to downgrade to kernel 5.4 to see what the results are?

@bedwardly-down
Copy link
Contributor

bedwardly-down commented Apr 9, 2020

Also, i just moved my Nextcloud instance from an Ubuntu Server to an Archlinux one. Arch is now on 5.6 and I’ve noticed that since the move, the Linux client and DAV stuff in general has substantially slowed down. My main system is still on 5.4, but i wonder if the issue here could be the kernel and OS of the server the Nextcloud instance is running on.

I also know that the kernel commit that messed all of this up deals exclusively with asynchronous io calls, so i wonder if it can cause issues server side.

@Robiocop
Copy link

I also encountered this bug. I must change on my computers the sync settings to local folder connected to my nextcloud server.
My system is KDE Neon 5.18, Joplin in the last version (AppImage). The data are stored on a shared server.
Like Ebayer, I've got two systems under KDE Neon (Desktop and Laptop) and the sync for 140 files takes more than 7 hours ! I've also noticed that the server was very slow during this time (even for command lines). When the sync takes only 10 seconds on Android and iOS with WebDAV.

@afv
Copy link

afv commented Apr 19, 2020

Hi!

I'm using Joplin on Arch Linux (two devices) and Android (one device).

This bug does not happen only on Nextcloud sync and I'm not sure it is related with the synchronization. I was using Nextcloud sync since December 2018, but today I tried to change it to file system (using Syncthing) hoping it would be better, since in the last few weeks the desktop has been unusable: for example copying & pasting something would hang the UI (I could continue writing the note but the preview pane would not update and I could not even click other note, as nothing would happen).

After changing to file system sync it kept hanging (after synchronizing some 4 items of 2029 total items); tried to rename the ~/.config/Joplin and ~/.config/joplin-desktop directories to start anew, it started synchronizing with the file system but stopped around item 700, and that's where I found this GitHub issue (thanks for the tip on enabling and disabling Web Clipper in settings; the synchronization went through after doing this a couple of times).

How can I help debugging this further?

Thanks!

@bedwardly-down
Copy link
Contributor

@afv , are you able to install and boot into the lts-linux kernel and have the same issues on both Arch devices?

@tessus tessus added linux sync sync related issue labels Apr 19, 2020
@afv
Copy link

afv commented Apr 19, 2020

Using file system sync.
Was using Linux kernel 5.6.4.arch1-1.
Now on LTS Linux kernel 5.4.32-1, did the following:
Still on 5.6.4:

  • Cleared config directories

  • Set up file sync
  • Stopped at "Fetching items: 1606/1950". (took around 3 minutes)
  • Enabled/disabled Web Clipper, fetching items continued and completed.

  • Set encryption key
  • Decrypting items (batches of 100), stopped at 91/100 after some hundreds
  • Enabled/disabled Web Clipper
  • Decrypting items continued, stopped at the next 56/100 (+65 since stop)
  • Enabled/disabled Web Clipper
  • Decrypting items continued until next 88/100 (+132)
  • Enabled/disabled Web Clipper
  • Decrypting items continued for around 300 items, stopped at 44/100
  • Enabled/disabled Web Clipper
  • Decrypting items continued until next 72/94 (+128)
  • Enabled/disabled Web Clipper
  • Decrypting items continued until 88/94 (+16)
  • Enabled/disabled Web Clipper
  • Decrypting items continued until 89/94 (+1)
  • Enabled/disabled Web Clipper
  • Completed.

Edit:
I was not on LTS (remembered to check uname -r); GRUB reordered the boot entries after I rebooted the second time (LTS went from 3rd place to 1st place as it was the last one used, but I didn't notice it changing) so I ended up booting 5.6.4 again (selected the 3rd entry). 🤦
Now on 5.4.33-3-lts, cleaned up config files and everything was synchronized and decrypted without stopping/hanging.

@bedwardly-down
Copy link
Contributor

bedwardly-down commented Apr 19, 2020

Thanks, @afv. #2518 is the Linux one I was referring to and your issue sounds like it but there may be something else going on here. I'm on the same kernel and haven't ran into the bug yet but haven't done a full reset in awhile either.

Also, was that done as FileSystem Sync or Nextcloud?

@ebayer
Copy link
Contributor Author

ebayer commented Apr 20, 2020

i wonder if the issue here could be the kernel and OS of the server the Nextcloud instance is running on.

My nextcloud instance is running in Centos7 (kernel 3.10.0) and latest nextcloud minor version (18.0.2)

I have done a full reset, nothing changed. I will try to find a 5.4 kernel to try.

@afv
Copy link

afv commented Apr 20, 2020

Thanks, @afv. #2518 is the Linux one I was referring to and your issue sounds like it but there may be something else going on here. I'm on the same kernel and haven't ran into the bug yet but haven't done a full reset in awhile either.

Also, was that done as FileSystem Sync or Nextcloud?

Sorry! I was not using 5.4; on a second reboot I ended up on 5.6 again without noticing (edited my previous comment to explain that). On 5.4 everything looks fine (using file system sync).

@ebayer
Copy link
Contributor Author

ebayer commented Apr 28, 2020

I have done more testing.

First of all, this problem has nothing to do with Nextcloud sync. I have set up a copy of Nextcloud dir in my home directory (cp -a) and tried to sync. Initial sync did not start at all without the afforementioned disable/enable web clipper workaround. All sync operations hanged after initial sync is finished, and I could not find any way to cause a trigger to update the UI and finish syncing. The UI rendering completely stopped, ie. when switching between notes the note list would show the new note highlighted but the editor and display area does not get updated. Menus are working, I can check for application updates, but editor and note display stops working until sync finishes (can happen only with enable/disable webclipper).

When I check the sync folder access with inotify at this moment, I can see that no process is trying to access it. Here is the inotifywait output when a manual sync is started and hangs:

Nextcloud/Joplin/ OPEN,ISDIR .lock
Nextcloud/Joplin/.lock/ OPEN,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR .lock
Nextcloud/Joplin/.lock/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR .lock
Nextcloud/Joplin/.lock/ ACCESS,ISDIR
Nextcloud/Joplin/ CLOSE_NOWRITE,CLOSE,ISDIR .lock
Nextcloud/Joplin/.lock/ CLOSE_NOWRITE,CLOSE,ISDIR
Nextcloud/Joplin/.sync/ OPEN version.txt
Nextcloud/Joplin/.sync/ ACCESS version.txt
Nextcloud/Joplin/.sync/ CLOSE_NOWRITE,CLOSE version.txt
Nextcloud/Joplin/.sync/ MODIFY version.txt
Nextcloud/Joplin/.sync/ OPEN version.txt
Nextcloud/Joplin/.sync/ MODIFY version.txt
Nextcloud/Joplin/.sync/ CLOSE_WRITE,CLOSE version.txt
Nextcloud/Joplin/ OPEN d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ ACCESS d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ CLOSE_NOWRITE,CLOSE d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ MODIFY d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ OPEN d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ MODIFY d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ CLOSE_WRITE,CLOSE d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ OPEN,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ ACCESS,ISDIR
Nextcloud/Joplin/ CLOSE_NOWRITE,CLOSE,ISDIR

After I enable/disable the web clipper, sync finishes and UI goes back to normal:

Nextcloud/Joplin/ OPEN d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ ACCESS d296e143c5404ccb858f90e619446a22.md
Nextcloud/Joplin/ CLOSE_NOWRITE,CLOSE d296e143c5404ccb858f90e619446a22.md

I have installed a 5.4 kernel and tried Nextcloud sync and nothing changed. Exact kernel version I used was 5.4.14-9-default. However local sync hang is fixed with 5.4 kernel.

When I have some time, I will try older Joplin versions to try to pinpoint when this problem was introduced and test if this is Joplin related at all.

Funny thing is, when trying to find a temporary workaround, I discovered that if I use an external editor to edit a note and then save the note inside the external editor while syncing, the sync finishes. I think the reason for this is saving the note in external editor refreshes the note content pane, which triggers UI update, which triggers sync operation to carry on like manually updating the UI.

@bedwardly-down
Copy link
Contributor

bedwardly-down commented Apr 28, 2020

@ebayer, glad for the follow up and test info. I’ve closed #2518 and reopened it as #3114 with more information and a cleaner layout; the UI thing you found is in line with what we’ve discovered there. Laurent is looking into implementing a bandaid fix that may help solve this issue too.

@bedwardly-down
Copy link
Contributor

@ebayer, can you try the following to see if it solves your issue?

  1. Install davfs2 or just davfs with your package manager (it's named both for the same package in different Linux Distros; whichever works, make sure it's version 2 since that's the latest).
  2. Copy the contents of /etc/davfs2 to ~/.davfs2 in your home directory.
  3. Make sure your user account has mounting permissions enabled (may need to add it to the mount user group).
  4. chown -Rv <username:username> ~/.davfs2 (to make sure your user has full rights to that directory)
  5. Add "<full nextcloud path url>" <username> "<password>" to the end of ~/.davfs2/secrets (replace with the correct information; the url and password must be in quotes to register properly, the username only needs them if it has special characters in it)
  6. Follow either the Systemd Mounting or Fstab directions here (I prefer Fstab since I don't use systemd but it requires a couple extra steps to work).
  7. mkdir -pv ~/Nextcloud (or name it whatever you want; make sure it's the same mount directory in Systemd or Fstab)
  8. (Optional) Add mount $HOME/Nextcloud & to your default shell init script to mount the filesystem every time you log in. I use Fish and have it set to only mount on login to prevent it from attempting to recursively mount and throw errors when I open a new terminal window. Your shell is most likely Bash or a derivative, so there's plenty of information on how to check if it's a login shell.
  9. Run mount -v ~/Nextcloud to make sure it worked without errors. If it says anything about not supporting locks, you've succeeded and that warning can be safely ignored.
  10. Set Joplin to Filesystem sync with your ~/Nexcloud/<Joplin subdirectory used for Nextcloud sync>.

If everything worked as intended, Joplin should start updating and resyncing all of your data. Let that fully complete and you should be good to go as long as your Nextcloud instance is always mounted.

There are two caveats here, though:

  1. Depending on your hardware and internet connection, Davfs may be quite a bit slower for large syncs than regular Nextcloud.
  2. If your network were to go out for whatever reason mid sync, you could possibly get some corruption (haven't fully tested yet). Davfs requires being always connected to keep the directory mounted; ~/.davfs2/davfs2.conf does have a timeout setting you can mess around with.

@ebayer
Copy link
Contributor Author

ebayer commented May 17, 2020

@ebayer, can you try the following to see if it solves your issue?

Does using davfs bring something new to this issue? I already have a copy of my nextcloud folder synced with nextcloud linux client and tried filesystem sync on Joplin on this folder before (more details a couple of comments up). I will be happy to test your suggestion if it will bring some new information though.

@bedwardly-down
Copy link
Contributor

bedwardly-down commented May 17, 2020

It’s a bit more convenient. I found that using the terminal client for Nextcloud had to be set on a cron tab for it to stay consistently synced properly. The upside, though, if your net goes out, your folder will stay mounted locally and can still be synced with Filesystem sync. You just won’t get to update it upstream until your network comes back. I’ve also found that it’s substantially faster on lower end hardware.

@ebayer
Copy link
Contributor Author

ebayer commented May 18, 2020

I am using Nextcloud Desktop Client and have it sync automaticly when a file changes on either locally or on the server.

As I said before, using an external editor causes the UI to be updated at every note save and causing the UI update lets the sync operation carry on without hang. I am using this temporary glitch until the issue is fixed.

@bedwardly-down
Copy link
Contributor

bedwardly-down commented May 18, 2020

That definitely is not applicable to my situation then. With 2.6.13, the UI isn’t freezing at all, so resetting isn’t viable. But, switching to Filesystem Sync with my Nextcloud instance mounted seems to have solved my weird issue on my last test on #3114

So, let’s assume your issue is not the same as my second one then since my solution does not fix your problem. I use very few GUI apps and try to go terminal where able because that’s more comfortable for me and i can quickly go about my business.

@bedwardly-down
Copy link
Contributor

I’ve slept for a little bit and had a thought: can you please share a recording of what’s happening because your bug is confusing to work through. I feel that there may be some conflicting information and your bug may not be easily reproducible in its current form. Thanks

@ebayer
Copy link
Contributor Author

ebayer commented May 18, 2020

Here is the video:

https://gofile.io/d/E4JWhB

Note that this behaviour is different than what you discuss in #3114. IN #3114, the app gets completely frozen and does not recover without completely shutting down the application. In my case, only sync operation gets frozen and only for a couple of minutes.

Also note that using davfs will not solve this problem, as filesystem target is also affected by this hang in recent kernels. Using 5.4 kernel fixes this issue on filesystem target, but not on Nextcloud target.

@bedwardly-down
Copy link
Contributor

bedwardly-down commented May 18, 2020

Thanks for the video. So, 5.6.13 does not solve it for you on Filesystem sync, right? You never once stated that you tried that kernel release because the UI issue was fixed there. If you’re still having to use other methods to get out of it (like using external editor), there’s something else going on that could possibly be distro related or quite a few other things.

I don't have OpenSuse but could attempt to try it in a virtual machine to see if your issue shows up for me.

@ebayer
Copy link
Contributor Author

ebayer commented May 19, 2020

hmm, I did not try using 5.6.13, Opensuse Tumbleweed still uses 5.6.12 as latest. I will try to find that kernel from somewhere and try that as soon as possible and report back.

@bedwardly-down
Copy link
Contributor

I don't know how Opensuse handles the kernel building process, but once you get that down, it's like riding a bike. There's not a massive amount you'll need to know about rolling a custom one. If you know your hardware well and know what future hardware you may be wanting to get, you can even trim down your build to the bare minimum and just build it from source every time a new release is available. That's how I've been testing new releases since they sometimes took up to a week to come in.

@sentientnebula
Copy link

sentientnebula commented May 28, 2020

I'm running OpenSUSE Tumbleweed with 5.14 Kernel, and it is glacially slow syncing with a Nextcloud server. Updating from 5.12 to 5.14 made no difference at all. I don't really even think syncing is slow once it actually gets started. Joplin just seems to spin its wheels a long time before it starts the process. If I make a change to a note after starting sync, it "breaks it loose," and syncing is fast after that.

@bedwardly-down
Copy link
Contributor

@sentientnebula have you tried switching to Filesystem sync and using the Nextcloud app to handle the actual syncing? Just setup a local Nextcloud folder and make sure the GUI app runs at startup. Then set Joplin to sync to its location in that folder

@cyrialize
Copy link

cyrialize commented Jun 2, 2020

Sync is slow for me as well. I currently sync my Joplin files over to Fastmail via Webdav.

To get around this issue, I started using the command line tool rclone.

I set up my webdav connection, wrote a script that runs the rclone mount command (with the --daemon flag), and have it called at startup with crontab via the @restart command (I learned about @restart from here).

Here's the script - which essentially is just an rclone command:

#!/bin/bash
rclone mount --daemon fastmail:joplin /home/mxjonny/joplin 
  • fastmail is the name of my config profile
  • joplin is the top-level folder I keep all my files in
  • /home/mxjonny/joplin is the directory to my local folder
  • chmod a+x the file

Here's what my crontab looks like:

@reboot /home/mxjonny/Code/rclone-fastmail-mount

I did not use sudo with editing my crontab.

I use Ubuntu 18.04.

So far it works pretty well. There is some lag between editing a file on my phone and syncing it on my laptop but my test was changing a file on my phone and checking to see if it would update on my laptop immediately. I imagine this has something to do with rclone syncing/detecting changes.

I never use my phone and laptop in this fashion, if I do edit Joplin on my phone probably by the time I get to Joplin on my laptop there won't be any lag.

EDIT:

I recommend setting the flag --poll-interval 5s for the call above. The default is --poll-interval 1m which was the lag I noticed above. So far it works great.

For some reason though, when I pointed Joplin to sync with the directory it recognized all the files as new items and how to download everything. I did not lose any data though and it didn't look like anything changed.

After that my other devices had to re-download too - again, nothing changed and this wasn't a big deal since sync is only slow on Linux and nothing else.

@ebayer
Copy link
Contributor Author

ebayer commented Jun 4, 2020

Today, I realized that there is a new version released 11 days ago (I really need to find a better way to check release announcements :) ) and this issue seems to be fixed with 1.0.216 version.

I checked the release notes and maybe upgrading to Electron 8.2.5 might have fixed the problem.

Thanks everyone for their time and effort, especially @bedwardly-down . I think we can close this issue.

@bedwardly-down
Copy link
Contributor

@ebayer there we ho. Thanks for your help too.

@cyrialize
Copy link

cyrialize commented Jun 4, 2020

Ah I definitely need to upgrade my version then, I'm on 1.0.210.

I did run into an issue with my rclone setup. It says that the fail safe kicked in because 100% of the items would be deleted.

Maybe this is due to rclone, or how Joplin interacts with syncing to a local directory? Does anyone have any insight into this? I can also open an issue if need be. I'm not too worried about it currently since I'm going to update Joplin and switch back to webdav.

EDIT:

Nevermind! I'm silly. My rclone mount wasn't set up. Looks like I need to work on my script since it should mount on startup.

Thanks guys!

@lock lock bot locked and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug It's a bug desktop All desktop platforms linux sync sync related issue
Projects
None yet
Development

No branches or pull requests

8 participants