RFR: 8285956: (fs) Excessive default poll interval in PollingWatchService [v4]

Tyler Steele duke at openjdk.java.net
Mon May 2 22:34:23 UTC 2022


On Mon, 2 May 2022 21:24:13 GMT, Tyler Steele <duke at openjdk.java.net> wrote:

>> PollingWatchService.java contains the WatchService and WatchKey implementation for AIX and BSD. When a Path is [register](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Path.html#register(java.nio.file.WatchService,java.nio.file.WatchEvent.Kind...))ed this implementation creates a  polling thread to monitor for file system changes. Currently, this thread waits 10 seconds before it's first poll, and then waits 10 seconds between subsequent polls. This interval leads to sluggish performance.
>> 
>> This PR makes the following changes:
>> - Sets the initial interval to 1 second regardless of the period.
>> - Change the default period to 1 second.
>> 
>> All tests in `test/jdk/java/nio/file/WatchService` passing.
>
> Tyler Steele has updated the pull request incrementally with one additional commit since the last revision:
> 
>   modifies comment as requested

I agree it is good to consider whether or not the design makes it easy to load up so many changes that performance degrades. But I think we're well clear of that point even with 1s. I think it helps that [scheduleAtFixedRate](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/concurrent/ScheduledExecutorService.html#scheduleAtFixedRate(java.lang.Runnable,long,long,java.util.concurrent.TimeUnit)) guarantees that the tasks will not run concurrently and [Watchable](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Watchable.html#register(java.nio.file.WatchService,java.nio.file.WatchEvent.Kind%5B%5D,java.nio.file.WatchEvent.Modifier...)) specifies that the key should only be created if one doesn't already exist.

If a user were to register enough unique Watchable objects to degrade the performance of their system, I am hopeful that the reason for the slow down would be clear to them.

An alternative would be to keep the initial wait at 1s and increase the default polling interval to 2s.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8479


More information about the nio-dev mailing list