cpulimit

package module
v0.0.0-...-90ccf65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2016 License: BSD-2-Clause Imports: 2 Imported by: 0

README

go-cpulimit

GoDoc

Package cpulimit implements a simple CPU usage instrument that communicates whether the CPU is running "cold" or "hot" via two distinct channels. It is intended to be used for self-restraining resource-hungry programs.

Copyright 2016 Hilko Bengen bengen@hilluzination.de

License

BSD 2-clause, see LICENSE file in the source distribution.

Documentation

Overview

Package cpulimit implements a simple CPU usage instrument that communicates whether the CPU is running "cold" or "hot" via two distinct channels. It is intended to be used for self-restraining resource-hungry programs.

The author is well aware that all modern operating systems provide means of providing the task scheduler with priority hints (e.g. nice(), SetPriorityClass(). This package is intended to help with limiting actual CPU usage, e.g. to work around system administrators who are scared by high CPU load even if the load is predominantly caused by low-priority processes that do actual work.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Current, Average float64
}

type Limiter

type Limiter struct {
	// MaxCPUUsage is the CPU usage threshold, in percent, above which
	// the CPU is considered as "hot". This value can be set while the
	// measurement process is running. Default: 50.0
	MaxCPUUsage float64
	// SwitchPeriod determines how often the Limiter decides whether
	// the CPU is "hot" or "cold". Default: 1 second
	SwitchPeriod time.Duration
	// MeasurePeriod determines how often CPU usage is
	// measured. Default: SwitchPeriod / 4 (if MeasurePeriod >=
	// SwitchPeriod/2)
	MeasurePeriod time.Duration
	// For deciding whether the CPU is "hot" or "cold", a rolling
	// average over MeasureDuration is taken.  Default: 10 *
	// SwitchPeriod (if MeasureDuration <= SwitchPeriod)
	MeasureDuration time.Duration
	// The rolling average and the current CPU usage will be sent to H
	// ("hot") whenever average CPU usage over the Measurements period
	// is equal to or higher than MaxCPUUsage.
	H chan Info
	// The rolling average and the current CPU usage will be sent to C
	// ("cold") whenever average CPU usage over the Measurements
	// period is below MaxCPUUsage.
	C chan Info
	// contains filtered or unexported fields
}

func (*Limiter) Start

func (l *Limiter) Start()

Start initializes and starts the measurement process using the pre-set values.

func (*Limiter) Stop

func (l *Limiter) Stop()

Stop halts the measurement process. Both H and C channels are closed so that any waiting goroutines are unblocked.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL