Skip to content

Disable FileSystemWatchers creation for subfolders #20488

Description

@VladimirKhil

Is your feature request related to a problem? Please describe.

In the VS debugger I see that my ASP.NET Core 3.1 app running on Ubuntu 18.04 server creates two threads for FileSystemWatchers and one of them creates FSW on every app subfolder that I have. I have a lot of subfolders in my app so all these FSW eat a lot of CPU resources.

I have two configuration files with "reloadOnChange: true"option but I don't think this is the case.

Describe the solution you'd like

Implement a way (API call or Host setting?) to disable FSW creation. My app files are not changed during app lifetime.

Additional context

Activity

  1. javiercn commented on Apr 3, 2020

    @javiercn
    Member

    @VladimirKhil thanks for contacting us. Can you give us more details about the folder that is affected by this? (Name within the solution at least) so that I can determine what area of the product it belongs to?

  2. VladimirKhil commented on Apr 3, 2020

    @VladimirKhil
    Author

    @javiercn this is wwwroot folder. It has thousands of subfolders in my case. The folders hierarchy looks like this: wwwroot -> (1 big folder and several small) -> (several hundreds subfolders in the big folder) -> (4 subfolders in each of them)

  3. javiercn commented on Apr 3, 2020

    @javiercn
    Member

    @VladimirKhil thank. That helps.

    @pranavkm can this be the file watcher used by razor for runtime compilation? Can you provide instructions here on how to turn it off?

  4. added
    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
    on Apr 3, 2020
  5. javiercn commented on Apr 3, 2020

    @javiercn
    Member

    Tentatively moving this to MVC to further look at the issue

  6. javiercn commented on Apr 3, 2020

    @javiercn
    Member

    /cc @Tratcher in case you have some other thoughts

  7. pranavkm commented on Apr 6, 2020

    @pranavkm
    Contributor

    reloadOnChange: true creates a file system watcher. Having it off should disable the watcher. Runtime compilation doesn't have a way to turn off the file system watching.

  8. Tratcher commented on Apr 6, 2020

    @Tratcher
    Member

    reloadOnChange: true creates a file system watcher. Having it off should disable the watcher. Runtime compilation doesn't have a way to turn off the file system watching.

    So you'd have to disable runtime compilation?

  9. pranavkm commented on Apr 6, 2020

    @pranavkm
    Contributor

    @Tratcher it's an optional component in 3.x, not on by default. Having runtime compilation indicates you're interested in watching for file changes at runtime so it doesn't make sense for it have a feature that effectively makes it useless.

    It's not clear that runtime compilation is at fault here. If it was, what might have been useful is if the file system entirely turned off watcher if it was configured to use polling. Right now, polling works in addition to the watcher, so it doesn't really help here.

  10. VladimirKhil commented on Apr 8, 2020

    @VladimirKhil
    Author

    I have disabled all "reloadOnChange: true" options in my code and still sometimes get some high FSW activity in PerfView:

    3
    2
    1

  11. Tratcher commented on Apr 10, 2020

    @Tratcher
    Member

    It should be possible to look at a memory dump and figure out what component is listening for file watcher callbacks.

  12. VladimirKhil commented on Apr 10, 2020

    @VladimirKhil
    Author

    I have a dump. It has some cyrillic letters but they are not really bothering :)

    It seems that NLog and JsonConfigurationProvider do have FileSystemWatchers.

    1
    2
    3

  13. rynowak commented on Apr 10, 2020

    @rynowak
    Contributor

    In case anyone was wondering btw, the IFileProvider implementation watches everything within its scope even if you're just interesting a single file or two (appsettings.json).

    The implementation kinda assumes that you are using globs or will use globs, which is why it watches everything rather than just the files you asked for.

    On linux this sometimes results in exhausting the handles available to epoll (esp in containers).

    @VladimirKhil - is there something about your scenario that's triggering a lot of file changes in wwwroot/? I would expect something is changing these files since you're seeing high CPU usage. Otherwise the filewatcher would just sit there idle.

  14. VladimirKhil commented on Apr 10, 2020

    @VladimirKhil
    Author

    @VladimirKhil - is there something about your scenario that's triggering a lot of file changes in wwwroot/? I would expect something is changing these files since you're seeing high CPU usage. Otherwise the filewatcher would just sit there idle.

    I had such activity earlier. Yes, there was a great count of files creation and deletion. Now I move that logic outside of wwwroot folder. I dont see high CPU activity now. I just only don't know why dotnet-trace catches FileSystemWatcher operations so often.

  15. removed their assignment
    on Apr 16, 2020
  16. pranavkm commented on Apr 16, 2020

    @pranavkm
    Contributor

    We're tracking follow up work for FSWs as part of https://github.com/dotnet/aspnetcore/issues/20733. Marking this as resolved since there isn't a specific issue to track for ASP.NET Core \ Mvc.

  17. added
    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.
    and removed
    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
    on Apr 16, 2020
  18. ghost closed this as completedon Apr 18, 2020
  19. ghost locked as resolved and limited conversation to collaborators on May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions