<div dir="ltr">I benchmarked this implementation (well, the implementation this one is
based on, now it's become quite different) extensively. The main
advantage of FSEvents over polling was near-0 CPU usage when there were
small number of changes to the directory being watched, while polling
naturally always has some background job to do and its CPU usage heavily
depends on refresh speed (like 25% with SENSITIVITY_HIGH and modest
rate of changes).</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 10, 2022 at 6:22 AM Michael Hall <<a href="mailto:mik3hall@gmail.com">mik3hall@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
I think someone may of mentioned benchmarks at some point. <br>
<br>
My thought on a watch service to try this on was monitoring the blockchain blocks for a full bitcoin client.<br>
<br>
It doesn’t update all that often so not really a benchmark stress test. But a pretty easy one. Run both a polling and a FSEvents service.<br>
<br>
java SimpleBTCWatcher<br>
WatchService sun.nio.fs.PollingWatchService@1b6d3586<br>
Watching for events on /Volumes/BTC/Bitcoin/blocks<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043049779 block access time 1668042238000 block modified time 1668043049610<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043251780 block access time 1668043050000 block modified time 1668043251540<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043609759 block access time 1668043608000 block modified time 1668043608650<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043813761 block access time 1668043608000 block modified time 1668043813380<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043943766 block access time 1668043814000 block modified time 1668043943550<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668044651774 block access time 1668043944000 block modified time 1668044651360<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668045843727 block access time 1668045842000 block modified time 1668045842250<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668045955806 block access time 1668045954000 block modified time 1668045954320<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668046521801 block access time 1668045954000 block modified time 1668046520890<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668047175806 block access time 1668047174000 block modified time 1668047174070<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668047485805 block access time 1668047174000 block modified time 1668047485660<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668047815828 block access time 1668047486000 block modified time 1668047814900<br>
<br>
/Users/mjh/Documents/GitHub/jdk/build/*/images/jdk/bin/java -Dsun.nio.fs.MacOSXWatchService.use=true SimpleBTCWatcher<br>
WatchService sun.nio.fs.MacOSXWatchService@5c647e05<br>
Watching for events on /Volumes/BTC/Bitcoin/blocks<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043050347 block access time 1668042238000 block modified time 1668043049610<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043252163 block access time 1668043050000 block modified time 1668043251540<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043609299 block access time 1668043608000 block modified time 1668043608650<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043814008 block access time 1668043608000 block modified time 1668043813380<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668043944009 block access time 1668043814000 block modified time 1668043943550<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668044652033 block access time 1668043944000 block modified time 1668044651360<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668045843305 block access time 1668044652000 block modified time 1668045842250<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668045954853 block access time 1668045842000 block modified time 1668045954320<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668046521441 block access time 1668045954000 block modified time 1668046520890<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668047175552 block access time 1668047174000 block modified time 1668047174070<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668047486484 block access time 1668047174000 block modified time 1668047485660<br>
ENTRY_MODIFY occurred on blk03268.dat at 1668047815507 block access time 1668047486000 block modified time 1668047814900<br>
<br>
The ‘at’ is System.currentTimeMillis. Polling often faster somewhat surprisingly? <br>
<br>
Running jconsole on both the only really significant difference I notice is gc. For FSEvents…<br>
<br>
Time: 2022-11-09 20:45:24<br>
Used: 155,387 kbytes<br>
Committed: 266,240 kbytes<br>
Max: 4,194,304 kbytes<br>
GC time: 0.021 seconds on G1 Young Generation (2 collections) <br>
0.000 seconds on G1 Old Generation (0 collections) <br>
<br>
And for polling…<br>
<br>
Time: 2022-11-09 20:46:05<br>
Used: 106,701 kbytes<br>
Committed: 266,240 kbytes<br>
Max: 4,194,304 kbytes<br>
GC time: 0.081 seconds on G1 Young Generation (51 collections) <br>
0.000 seconds on G1 Old Generation (0 collections)<br>
<br>
Polling gc’s considerably more often and takes relatively longer doing it. Still hundredths of a second. <br>
A more stressful watch service might make this difference or other ones more significant.<br>
<br>
Have any other platform implementations been benchmarked relative to polling?</blockquote></div>