dcosson / vagrant-unison2

Vagrant plugin to sync local files to VM using Unison over SSH
MIT License
50 stars 8 forks source link

High CPU usage #32

Closed paales closed 4 years ago

paales commented 7 years ago

Hi there,

We're syncing a rather large project (Magento 2) to our box which causes a rather large CPU usage (even when no files are changed).

schermafbeelding 2017-05-03 om 12 01 41

Ideas how to reduce the CPU usage?

paales commented 7 years ago

Maybe it is an idea to reintroduce some sort of filesystem events for the host and OSX?

moleman commented 7 years ago

We also have this issue when working with Magento2 projects but found a possible solution by using "-repeat watch", filesystem events, instead of polling by seconds.

  1. Config: vps.unison.repeat = "watch"

  2. Host (https://github.com/hnsl/unox): brew tap eugenmayer/dockersync brew install eugenmayer/dockersync/unox

  3. Guest: Increased files that can be watched in the guest echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

  4. Guest: Uninstalled unison, compiled Unison from source code (to get unison-fsmonitor), copied unison + unison-fsmonitor to /usr/local/bin

paales commented 7 years ago

Ohh! That might be a great solution! Working with Magento 2 as well. You mention 'possible solution', in the sense that not everything is integrated 100% yet, or that you haven't tried yet?

When I've got the time, I will take a look at it as well. As I understand, this should also considerably improve the time it takes to sync, because we don't have the extra second any more?

moleman commented 7 years ago

With 'possible solution' I meant that we have not rolled it out to our developers yet so we don't have any real usage data. Only done some initial testing and it seems to solve the CPU issue when no files are changed.

paales commented 7 years ago

Thanks for the response :)

dasginganinja commented 4 years ago

We [...] found a possible solution by using "-repeat watch", filesystem events, instead of polling by seconds.

I'm using this in my project now and can certainly say that there is an extreme increase in performance after switching to the "watch" version.

dasginganinja commented 4 years ago

I have modified my Vagrantfile as such to support this with a fallback to seconds if watch is not supported.

Maybe this could be implemented as a new parameter for vagrant-unison2 so that it automatically falls back? I definitely think there should be some sort of callout in the docs for "watch" support.

# Check whether host system has unison-fsmonitor
def has_unison_fsmonitor?()
  system("which unison-fsmonitor")
end

Vagrant.configure(2) do |config|
[...]
  if Vagrant.has_plugin?("vagrant-unison2")
    [...] # Other vagrant-unison2 parameters
    # Change polling interval (in seconds) at which to sync changes
    config.unison.repeat = "5"
    config.unison.repeat = "watch" if has_unison_fsmonitor?
  end
  config.vm.synced_folder '.', '/vagrant', disabled: true
end

Hopefully this helps those looking to implement the watch syntax if their host has unison-fsmonitor.

paales commented 4 years ago

@dasginganinja We've since migrated to https://mutagen.io, works faster and is relatively easy to set up.