automaxprocsgo.uber.org/automaxprocs/maxprocs Index | Examples | Files

package maxprocs

import "go.uber.org/automaxprocs/maxprocs"

Package maxprocs lets Go programs easily configure runtime.GOMAXPROCS to match the configured Linux CPU quota. Unlike the top-level automaxprocs package, it lets the caller configure logging and handle errors.

Example

Code:play 

package main

import (
	"log"

	"go.uber.org/automaxprocs/maxprocs"
)

func main() {
	undo, err := maxprocs.Set()
	defer undo()
	if err != nil {
		log.Fatalf("failed to set GOMAXPROCS: %v", err)
	}
	// Insert your application logic here.
}

Index

Examples

Constants

const Version = "1.6.0"

Version is the current package version.

Functions

func Set

func Set(opts ...Option) (func(), error)

Set GOMAXPROCS to match the Linux container CPU quota (if any), returning any error encountered and an undo function.

Set is a no-op on non-Linux systems and in Linux environments without a configured CPU quota.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option alters the behavior of Set.

func Logger

func Logger(printf func(string, ...interface{})) Option

Logger uses the supplied printf implementation for log output. By default, Set doesn't log anything.

Example

Code:play 

package main

import (
	"log"

	"go.uber.org/automaxprocs/maxprocs"
)

func main() {
	// By default, Set doesn't output any logs. You can enable logging by
	// supplying a printf implementation.
	undo, err := maxprocs.Set(maxprocs.Logger(log.Printf))
	defer undo()
	if err != nil {
		log.Fatalf("failed to set GOMAXPROCS: %v", err)
	}
}

func Min

func Min(n int) Option

Min sets the minimum GOMAXPROCS value that will be used. Any value below 1 is ignored.

func RoundQuotaFunc

func RoundQuotaFunc(rf func(v float64) int) Option

RoundQuotaFunc sets the function that will be used to covert the CPU quota from float to int.

Source Files

maxprocs.go version.go

Version
v1.6.0 (latest)
Published
Sep 23, 2024
Platform
windows/amd64
Imports
3 packages
Last checked
now

Tools for package owners.