-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
High CPU usage in watch mode due to polling (chokidar) #1796
Comments
You're welcome; I wish I could share my implementation, but it's rudimentary and somewhat project specific. I've also incorporated my workaround for avoiding unnecessary builds from #1570, i.e., the watch script updates the cache so that running the build script doesn't rebuild unnecessarily. |
Why is polling used in the first place? Based on chokidar's docs, it has non-polling solutions for all platforms? I should also note that I'm asking because I considered submitting a PR but then thought "Well but despite what the docs say, maybe they experienced issues on macOS and/or Linux." |
We're running into the High CPU usage as well. Especially on lower end systems (not every developer has the newest laptop) it becomes an issue. Would be nice if we could switch to file system events :) |
Apparently I'm retarded and need to read the documentation, the following solved it for me: documents:
- '**/*.graphql'
- '!generated/*.graphql'
- '!node_modules/**' |
I was also seeing a node process pegged at 100% cpu for hours at a time and can verify that it's because chokidar was told to use polling rather than the default and lightweight filesystem events.
Looking at the docs for usePolling. I think this should be set to In the meantime, as a user you can avoid this whole garbage fire by setting the environment variable |
@mikelovesrobots That is giving me issues like:
It seems to be watching all files in the node_modules folder as well, which isn't really a thing when using polling, but to use file system events chokidar probably needs to be configured differently? |
@paales Oh that's wild. We've also got a
Sounds like turning off |
@mikelovesrobots I've reduced the scope of the files that it scans and doesn't run into issues anymore and your proposed solution does work. |
Due to dotansimha/graphql-code-generator#1796, gulp is currently consuming a non-trivial amount of a CPU core watching for updates that regenerate the GraphQL operations files. Let's use Chokidar directly (via Gulp) and then we can be smarter about when we actually trigger the several second generation process.
* gulp: disable graphql-codegen's watch feature Due to dotansimha/graphql-code-generator#1796, gulp is currently consuming a non-trivial amount of a CPU core watching for updates that regenerate the GraphQL operations files. Let's use Chokidar directly (via Gulp) and then we can be smarter about when we actually trigger the several second generation process. * Hush eslint. * Simplify logic and ensure graphql types are generated before first run of webpack Co-authored-by: Erik Seliger <[email protected]>
I think this issue can be closed, as in #4823 the default was changed to not use polling. In the development workflow docs it also says:
There is no high CPU usage for me. However, the watch mode is still not very smart (#5642) and generates all the files freshly, even if only one source file changed, which leads to some CPU usage, but only once a file changed. |
The watch mode uses chokidar with polling, which in a large project means high CPU usage; in my case (thousands of source files) it uses almost an entire core at idle. Polling is useful in some compatibility scenarios, but it shouldn't be the default, and it should be configurable. I've currently
worked around the issue by making my own watch mode with some additional enhancements like triggering the build selectively (only for source files that actually feature GraphQL), and I can confirm that chokidar works fine without polling.
The text was updated successfully, but these errors were encountered: