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

node cpu when watch #145

Closed
kud opened this issue Jul 5, 2013 · 7 comments
Closed

node cpu when watch #145

kud opened this issue Jul 5, 2013 · 7 comments

Comments

@kud
Copy link

kud commented Jul 5, 2013

When watching, node takes a lots of cpu, it's maybe normal but quite frightening

node_cpu

My config:

watch: {
      assets: {
        files: ['app/assets/*'],
        tasks: ['copy:assets']
      },
      img: {
        files: ['app/assets/img/design/**/*'],
        tasks: ['copy:img']
      },
      scripts: {
        files: ['app/scripts/**/*', 'bower_components/**/*.js'],
        tasks: ['concat:scripts', 'jshint:all']
      },
      styles: {
        files: ['app/styles/**/*'],
        tasks: ['sass:dev']
      },
      images: {
        files: ['app/assets/assets/img/**/*'],
        tasks: ['copy:img']
      },
      cache: {
        files: ['../views/**/*'],
        tasks: ['clean:cache', 'notify:complete'],
        livereload: true
      },
      livereload: {
        files: ['../www/**/*.*'],
        tasks: ['livereload', 'notify:complete'],
        livereload: true
      }
    }

Can I reduce the cpu taking? or could we optimise that?

@shama
Copy link
Member

shama commented Jul 5, 2013

It's likely because of the low interval default in gaze. Try increasing it with: options: { interval: 5007 }. 5007 is the old node polling default.

@shama
Copy link
Member

shama commented Jul 5, 2013

Oh yeah and see #35 for related issue.

@kud
Copy link
Author

kud commented Jul 5, 2013

Wow.

screen shot 2013-07-05 at 18 05 51

@shama
Copy link
Member

shama commented Jul 5, 2013

Yeah I need to figure out a happy medium. It seems more files watched needs a higher interval. I guess until Grunt is node >= 0.10 and we might be able to stop relying so much on polling. Right now gaze uses a combination of polling and watching to support all the use cases amassed in the past year.

@kud
Copy link
Author

kud commented Jul 5, 2013

Okay thank you ;)

I can now close the ticket so. Maybe you should specify it in the readme for the moment until it's ok.

@mattkime
Copy link

mattkime commented Aug 1, 2013

@shama - can you expand on how node >= 0.10 would impact this issue?

@shama
Copy link
Member

shama commented Aug 2, 2013

@mattkime Well I can't confirm anything besides I notice a lot less watch issues with 0.10, especially with OSX. Although 0.10 uses fsevents on osx for directories which should reduce CPU usage. See this issue: shama/gaze#5.

I think most of the CPU usage now comes from the polling. Unfortunately we can't just not use polling as it breaks a number of existing tests cases that we would like to continue to support. Also users will likely hit EMFILE errors sooner if we fs.watch everything. Plus there are a number of issues down at the OS level we can't get around with fs.watch only.

So we're trying to balance between working around known issues and speed/cpu usage. The less issues there are upstream the more efficient we can make the watch operate here. 0.10 has less issues.

naz added a commit to naz/Ghost that referenced this issue Apr 2, 2019
closes TryGhost#9718

- fs.fileWatch that is used internally by 'gase' in 'grunt-contrib-watch', is having 100ms pooling default (https://github.com/shama/gaze/blob/07828a684566b6d4844f12b747e74e376fa31744/lib/gaze.js#L36). This is causing hight CPU usage for large amount of files.
- As suggested in https://github.com/gruntjs/grunt-contrib-watch#why-is-the-watch-devouring-all-my-memorycpu the watch interval was set to higher 500ms because the recommended default of 5s (gruntjs/grunt-contrib-watch#145 (comment)) was visible in the development flow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants