Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Increase syscall timeouts to decrease CPU usage? #58

Open
phred opened this issue Aug 22, 2013 · 2 comments
Open

Increase syscall timeouts to decrease CPU usage? #58

phred opened this issue Aug 22, 2013 · 2 comments

Comments

@phred
Copy link

phred commented Aug 22, 2013

I've been running https://github.com/azer/boxcars locally, which uses fsnotify to watch a single configuration file. Today I noticed that it's taking up 0.2% CPU even when idle, which struck me as odd.

Digging in, I found that it was due to the 100ms timeout that fsnotify uses for a timeout on the kevent() system call. As an experiment, I increased it to 1 second, and even 10 seconds. In both cases: CPU usage drops to 0%, and events still trigger as soon as the file modification happens.

Other than for tests, which should run quickly, is there any reason NOT to increase the syscall timeout? The kevent call is in a goroutine, so it doesn't matter if it's blocked. I'd rather that my programs sleep until events are ready instead of retriggering the syscall 10 times per second.

In any case, I'm keeping my local modification, as it works for me. :-) Thanks for this nice and clean little library!

@howeyc
Copy link
Owner

howeyc commented Sep 8, 2013

But if you experienced no slow down, then shouldn't the tests kick off when modifications happen as well?

I did try this, my test suite ran a lot slower.

@nathany
Copy link
Contributor

nathany commented Jul 7, 2014

@phred I've been doing some experimentation with kqueue. When using a nil timeout to block until there is an event, CPU usage is reduced to 0% while idle.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants