Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement load averages for Windows #115

Closed
wants to merge 12 commits into from

Conversation

ycombinator
Copy link

@ycombinator ycombinator commented Apr 10, 2019

Resolves #114.

This PR attempts to implement this method:

gosigar/sigar_windows.go

Lines 57 to 59 in 7bed239

func (self *LoadAverage) Get() error {
return ErrNotImplemented{runtime.GOOS}
}

Concretely, it does the following:

  1. Whenever the above method is called, i.e. load averages for a Windows system are requested, the code actually takes a sample of the current load average. This load average is based on the length of the processor queue, which is the number of processes waiting for CPU time. It's not a perfect approximation of system load.

  2. Over time, several samples get collected. Adding a new sample also does a bit of clean up to make sure we don't keep samples older than 15 minutes, which is the max. time necessary to generate the 15-minute load average.

  3. The samples are used to compute the 1-minute, 10-minute, and 15-minute averages.

Caveats

This implementation is simple but suffers from a couple of drawbacks:

  1. The first few invocations of the above method will not return useful load averages, as enough samples have not yet been collected.

  2. The frequency of sample collection == frequency of method invocation. So if the method is invoked very infrequently, fewer samples will be collected, leading to very imprecise load averages.

An alternative implementation could involve decoupling the sampling from the invocation of the above method. Sampling go happen on a timer in a goroutine.

@ycombinator ycombinator marked this pull request as ready for review April 10, 2019 14:22
@ycombinator
Copy link
Author

Chatted with @narph and @andrewkroh off-PR and came up with a few things to look into:

  1. Look into how *nix systems calculate load and try to mirror the same algorithm in this PR. Else, call the metric something other than "load" to avoid confusion.

  2. Move low-level Windows code from this package/PR into https://github.com/elastic/go-windows.

  3. If possible, stay away from WMI/WQL. @narph suggested looking into https://github.com/shirou/gopsutil.

@ycombinator
Copy link
Author

Here's the code of how Linux calculates load averages: https://github.com/torvalds/linux/blob/master/kernel/sched/loadavg.c

@cachedout
Copy link

@ycombinator Given that we closed elastic/beats#9944 were you thinking that we would keep this open or close it?

@ycombinator
Copy link
Author

Thanks @cachedout. Yes, we should close this one too.

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

Successfully merging this pull request may close these issues.

Implement load averages for Windows
2 participants