mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
numa: enable numa topology detection (#18146)
* client: refactor cgroups management in client * client: fingerprint numa topology * client: plumb numa and cgroups changes to drivers * client: cleanup task resource accounting * client: numa client and config plumbing * lib: add a stack implementation * tools: remove ec2info tool * plugins: fixup testing for cgroups / numa changes * build: update makefile and package tests and cl
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
// Code generated from hashicorp/nomad/tools/ec2info; DO NOT EDIT.
|
||||
|
||||
package {{.Package}}
|
||||
|
||||
// CPU contains virtual core count and processor baseline performance.
|
||||
type CPU struct {
|
||||
// use small units to reduce size of the embedded table
|
||||
Cores uint32 // good for 4 billion cores
|
||||
MHz uint32 // good for 4 billion MHz
|
||||
}
|
||||
|
||||
// Ticks computes the total number of cycles available across the virtual
|
||||
// cores of a CPU.
|
||||
func (c CPU) Ticks() int {
|
||||
return int(c.MHz) * int(c.Cores)
|
||||
}
|
||||
|
||||
// GHz returns the speed of CPU in ghz.
|
||||
func (c CPU) GHz() float64 {
|
||||
return float64(c.MHz) / 1000.0
|
||||
}
|
||||
|
||||
// newCPU create a CPUSpecs from the given virtual core count and core speed.
|
||||
func newCPU(cores uint32, ghz float64) CPU {
|
||||
return CPU{
|
||||
Cores: cores,
|
||||
MHz: uint32(ghz * 1000),
|
||||
}
|
||||
}
|
||||
|
||||
// LookupEC2CPU returns the virtual core count and core speed information from a
|
||||
// lookup table generated from the Amazon EC2 API.
|
||||
//
|
||||
// If the instance type does not exist, nil is returned.
|
||||
func LookupEC2CPU(instanceType string) *CPU {
|
||||
specs, exists := instanceTypeCPU[instanceType]
|
||||
if !exists {
|
||||
return nil
|
||||
}
|
||||
return &specs
|
||||
}
|
||||
|
||||
{{with .Data}}
|
||||
var instanceTypeCPU = map[string]CPU {
|
||||
{{ range $key, $value := . }}
|
||||
"{{ $key }}": newCPU({{$value.Cores}}, {{$value.Speed}}), {{ end }}
|
||||
}
|
||||
{{end}}
|
||||
@@ -1,213 +0,0 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
// Command ec2info provides a tool for generating a CPU performance lookup
|
||||
// table indexed by EC2 instance types.
|
||||
//
|
||||
// By default the generated file will overwrite `env_aws_cpu.go` in Nomad's
|
||||
// client/fingerprint package, when run from this directory.
|
||||
//
|
||||
// Requires AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN.
|
||||
//
|
||||
// Usage (invoke from Nomad's makefile)
|
||||
//
|
||||
// make ec2info
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"text/template"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
)
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
pkg, region, output := "fingerprint", "us-west-1", "client/fingerprint/env_aws_cpu.go"
|
||||
|
||||
client, err := clientForRegion(region)
|
||||
check(err)
|
||||
|
||||
regions, err := getRegions(client)
|
||||
check(err)
|
||||
|
||||
data, err := getData(regions)
|
||||
check(err)
|
||||
|
||||
flat := flatten(data)
|
||||
|
||||
f, err := open(output)
|
||||
check(err)
|
||||
defer func() {
|
||||
check(f.Close())
|
||||
}()
|
||||
|
||||
check(write(f, flat, pkg))
|
||||
check(format(output))
|
||||
}
|
||||
|
||||
func clientForRegion(region string) (*ec2.EC2, error) {
|
||||
sess, err := session.NewSession(&aws.Config{
|
||||
Region: ®ion,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ec2.New(sess), nil
|
||||
}
|
||||
|
||||
func getRegions(client *ec2.EC2) ([]*ec2.Region, error) {
|
||||
all := false // beyond account access
|
||||
regions, err := client.DescribeRegions(&ec2.DescribeRegionsInput{
|
||||
AllRegions: &all,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("failed to create AWS session; make sure environment is setup")
|
||||
log.Println("must have environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN")
|
||||
log.Println("or ~/.aws/credentials configured properly")
|
||||
return nil, err
|
||||
}
|
||||
return regions.Regions, nil
|
||||
}
|
||||
|
||||
type specs struct {
|
||||
Cores int
|
||||
Speed float64
|
||||
}
|
||||
|
||||
func (s specs) String() string {
|
||||
return fmt.Sprintf("(%d %.2f)", s.Cores, s.Speed)
|
||||
}
|
||||
|
||||
func getData(regions []*ec2.Region) (map[string]map[string]specs, error) {
|
||||
data := make(map[string]map[string]specs)
|
||||
|
||||
for _, region := range regions {
|
||||
rData, rProblems, err := getDataForRegion(*region.RegionName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data[*region.RegionName] = rData
|
||||
|
||||
log.Println("region", *region.RegionName, "got data for", len(rData), "instance types", len(rProblems), "incomplete")
|
||||
instanceProblems(rProblems)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func instanceProblems(problems map[string]string) {
|
||||
types := make([]string, 0, len(problems))
|
||||
for k := range problems {
|
||||
types = append(types, k)
|
||||
}
|
||||
sort.Strings(types)
|
||||
for _, iType := range types {
|
||||
log.Println(" ->", iType, problems[iType])
|
||||
}
|
||||
}
|
||||
|
||||
func getDataForRegion(region string) (map[string]specs, map[string]string, error) {
|
||||
client, err := clientForRegion(region)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
data := make(map[string]specs)
|
||||
problems := make(map[string]string)
|
||||
regionInfoPage(client, true, region, nil, data, problems)
|
||||
return data, problems, nil
|
||||
}
|
||||
|
||||
func regionInfoPage(client *ec2.EC2, first bool, region string, token *string, data map[string]specs, problems map[string]string) {
|
||||
if first || token != nil {
|
||||
output, err := client.DescribeInstanceTypes(&ec2.DescribeInstanceTypesInput{
|
||||
NextToken: token,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// recursively accumulate each page of data
|
||||
regionInfoAccumulate(output, data, problems)
|
||||
regionInfoPage(client, false, region, output.NextToken, data, problems)
|
||||
}
|
||||
}
|
||||
|
||||
func regionInfoAccumulate(output *ec2.DescribeInstanceTypesOutput, data map[string]specs, problems map[string]string) {
|
||||
for _, iType := range output.InstanceTypes {
|
||||
switch {
|
||||
|
||||
case iType.ProcessorInfo == nil:
|
||||
fallthrough
|
||||
case iType.ProcessorInfo.SustainedClockSpeedInGhz == nil:
|
||||
problems[*iType.InstanceType] = "missing clock Speed"
|
||||
continue
|
||||
|
||||
case iType.VCpuInfo == nil:
|
||||
fallthrough
|
||||
case iType.VCpuInfo.DefaultVCpus == nil:
|
||||
problems[*iType.InstanceType] = "missing virtual cpu Cores"
|
||||
continue
|
||||
|
||||
default:
|
||||
data[*iType.InstanceType] = specs{
|
||||
Speed: *iType.ProcessorInfo.SustainedClockSpeedInGhz,
|
||||
Cores: int(*iType.VCpuInfo.DefaultVCpus),
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// open the output file for writing.
|
||||
func open(output string) (io.ReadWriteCloser, error) {
|
||||
return os.Create(output)
|
||||
}
|
||||
|
||||
// flatten region data, assuming instance type is the same across regions.
|
||||
func flatten(data map[string]map[string]specs) map[string]specs {
|
||||
result := make(map[string]specs)
|
||||
for _, m := range data {
|
||||
for iType, specifications := range m {
|
||||
result[iType] = specifications
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
type Template struct {
|
||||
Package string
|
||||
Data map[string]specs
|
||||
}
|
||||
|
||||
// write the data using the cpu_table.go.template to w.
|
||||
func write(w io.Writer, data map[string]specs, pkg string) error {
|
||||
tmpl, err := template.ParseFiles("tools/ec2info/cpu_table.go.template")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tmpl.Execute(w, Template{
|
||||
Package: pkg,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
// format the file using gofmt.
|
||||
func format(file string) error {
|
||||
cmd := exec.Command("gofmt", "-w", file)
|
||||
_, err := cmd.CombinedOutput()
|
||||
return err
|
||||
}
|
||||
@@ -3,12 +3,8 @@ module github.com/hashicorp/nomad/tools
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go v1.44.249
|
||||
github.com/hashicorp/go-set v0.1.11
|
||||
github.com/shoenig/test v0.6.4
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
)
|
||||
require github.com/google/go-cmp v0.5.9 // indirect
|
||||
|
||||
42
tools/go.sum
42
tools/go.sum
@@ -1,48 +1,6 @@
|
||||
github.com/aws/aws-sdk-go v1.44.249 h1:UbUvh/oYHdAD3vZjNi316M0NIupJsrqAcJckVuhaCB8=
|
||||
github.com/aws/aws-sdk-go v1.44.249/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/hashicorp/go-set v0.1.11 h1:EZU3AzhNfCcMHtU0hCo2j4FAp7OHFDe/KTfmsbu1QIM=
|
||||
github.com/hashicorp/go-set v0.1.11/go.mod h1:BaYYjrI6m7H3D0j+N5Z0rZkCbBXOgNtuoDHrMJfORsk=
|
||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
|
||||
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
Reference in New Issue
Block a user