fix slow cpuinfo on multisocket config
updated win32_Processor struct to exclude loadpercentage field. The loadpercentage takes linearly more time as the # of sockets increases. By default vSphere maps 1 vCPU to 1 socket, resulting in very poor performance when getting CPU info against, saying, 40 vCPU VM (basically 40 sockets as seen by the VM).
This commit is contained in:
parent
b60e8d1895
commit
6a572952f0
|
@ -5,6 +5,7 @@ package cpu
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/StackExchange/wmi"
|
"github.com/StackExchange/wmi"
|
||||||
|
@ -18,7 +19,14 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Win32_Processor struct {
|
type Win32_Processor struct {
|
||||||
LoadPercentage *uint16
|
Win32_ProcessorWithoutLoadPct
|
||||||
|
LoadPercentage *uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadPercentage takes a linearly more time as the number of sockets increases.
|
||||||
|
// For vSphere by default corespersocket = 1, meaning for a 40 vCPU VM Get Processor Info
|
||||||
|
// could take more than half a minute.
|
||||||
|
type Win32_ProcessorWithoutLoadPct struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Manufacturer string
|
Manufacturer string
|
||||||
Name string
|
Name string
|
||||||
|
@ -104,8 +112,9 @@ func Info() ([]InfoStat, error) {
|
||||||
|
|
||||||
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
|
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
|
||||||
var ret []InfoStat
|
var ret []InfoStat
|
||||||
var dst []Win32_Processor
|
var dst []Win32_ProcessorWithoutLoadPct
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := wmi.CreateQuery(&dst, "")
|
||||||
|
q = strings.ReplaceAll(q, "Win32_ProcessorWithoutLoadPct", "Win32_Processor")
|
||||||
if err := common.WMIQueryWithContext(ctx, q, &dst); err != nil {
|
if err := common.WMIQueryWithContext(ctx, q, &dst); err != nil {
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
@ -242,8 +251,9 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
|
||||||
}
|
}
|
||||||
// physical cores https://github.com/giampaolo/psutil/blob/d01a9eaa35a8aadf6c519839e987a49d8be2d891/psutil/_psutil_windows.c#L499
|
// physical cores https://github.com/giampaolo/psutil/blob/d01a9eaa35a8aadf6c519839e987a49d8be2d891/psutil/_psutil_windows.c#L499
|
||||||
// for the time being, try with unreliable and slow WMI call…
|
// for the time being, try with unreliable and slow WMI call…
|
||||||
var dst []Win32_Processor
|
var dst []Win32_ProcessorWithoutLoadPct
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := wmi.CreateQuery(&dst, "")
|
||||||
|
q = strings.ReplaceAll(q, "Win32_ProcessorWithoutLoadPct", "Win32_Processor")
|
||||||
if err := common.WMIQueryWithContext(ctx, q, &dst); err != nil {
|
if err := common.WMIQueryWithContext(ctx, q, &dst); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type win32_Processor struct {
|
type win32_Processor struct {
|
||||||
LoadPercentage *uint16
|
|
||||||
Family uint16
|
Family uint16
|
||||||
Manufacturer string
|
Manufacturer string
|
||||||
Name string
|
Name string
|
||||||
|
|
Loading…
Reference in New Issue