In the latest version of my Undertow-powered tool, I've added support for change listeners in my custom resource manager. I really like this feature as it allows my welcome file cache and servlet path cache to be cleared automatically.
Since my release, I've had a couple users complain about the performance of the XNIO watcher when they have a large number of files in the base path for the resource manager. One user had a CMS with a large amount of static files-- around 100,000 files and they saw a delay of about 60 seconds while starting up the XNIO watcher. Another user had 280,000 files in their base path and their server wouldn't even start, throwing the following error
java.lang.OutOfMemoryError: Java heap space
at java.base/java.io.UnixFileSystem.resolve(Unknown Source)
at java.base/java.io.File.<init>(Unknown Source)
at java.base/java.io.File.listFiles(Unknown Source)
at org.xnio.nio.WatchServiceFileSystemWatcher.doScan(WatchServiceFileSystemWatcher.java:237)
at org.xnio.nio.WatchServiceFileSystemWatcher.watchPath(WatchServiceFileSystemWatcher.java:182)
...
I really like the watcher and I'd like to leave it on by default, but I'm curious how other people handle this. It's a low level sort of feature that my users aren't really going to understand or care about and they want the server tool to "just work" in all cases, lol.
- Is there a reliable way to detect when there will be too many files for the watcher to perform well and disable it programmatically?
- Would it work to try and start the watcher asynchronously, or does the registration of the listener need to be a blocking operation?
- Is there a way to tune the XNIO watchers such as ignoring certain subfolders like node_modules, etc?
- Is there a way to have the watcher fail more gracefully than a java heap space error when there are a large number of files?
- Have other people run into this, or is the change listener really not a super common feature?
Thanks!
~Brad
Developer Advocate
Ortus Solutions, Corp