feat: support multi-machine collaborative distributed load testing #1193

This commit is contained in:
xucong053
2022-07-25 21:14:58 +08:00
committed by 徐聪
parent ab12707fcf
commit 0ab2017f93
29 changed files with 3354 additions and 171 deletions
+29
View File
@@ -6,10 +6,15 @@ import (
"io"
"math"
"os"
"runtime"
"runtime/pprof"
"strings"
"time"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"github.com/shirou/gopsutil/process"
)
func round(val float64, roundOn float64, places int) (newVal float64) {
@@ -75,3 +80,27 @@ func startCPUProfile(file string, duration time.Duration) (err error) {
})
return nil
}
// generate a random nodeID like locust does, using the same algorithm.
func getNodeID() (nodeID string) {
hostname, _ := os.Hostname()
id := strings.Replace(uuid.New().String(), "-", "", -1)
nodeID = fmt.Sprintf("%s_%s", hostname, id)
return
}
// GetCurrentCPUUsage get current CPU usage
func GetCurrentCPUUsage() float64 {
currentPid := os.Getpid()
p, err := process.NewProcess(int32(currentPid))
if err != nil {
log.Printf("Fail to get CPU percent, %v\n", err)
return 0.0
}
percent, err := p.CPUPercent()
if err != nil {
log.Printf("Fail to get CPU percent, %v\n", err)
return 0.0
}
return percent / float64(runtime.NumCPU())
}