This commit is contained in:
meixiongfeng 2022-12-05 08:41:05 +08:00
parent 79a6e8aab7
commit 282f3eb1bb
4 changed files with 22 additions and 40 deletions

View File

@ -62,7 +62,7 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co
// Start 模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
func (this *Gateway) Start() (err error) {
log.Debugf("dddd")
_name2Func := map[string]any{
// 注册用户绑定uid接口 登录成功后触发
string(comm.Rpc_GatewayAgentBind): this.agentMgr.Bind,

View File

@ -61,6 +61,8 @@ end:
// 保持连接
chWaitFor := make(chan int, 0)
<-chWaitFor
//time.Sleep(15 * time.Millisecond)
//return
}
return
}

View File

@ -52,7 +52,7 @@ func InitLog() {
if err := log.OnInit(op.Setting.Sys["log"]); err != nil {
panic(fmt.Sprintf("Sys log Init err:%v", err))
} else {
log.Infof("ddddd Sys log Init success !")
log.Infof("stress Sys log Init success !")
}
}
@ -71,6 +71,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
requestTime uint64 // 请求总时间
maxTime uint64 // 最大时长
minTime uint64 // 最小时长
curTime uint64 // 当前消耗时常
successNum uint64 // 成功处理数code为0
failureNum uint64 // 处理失败数code不为0 0
chanIDLen int // 并发数
@ -90,8 +91,9 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
endTime := uint64(time.Now().UnixNano())
mutex.Lock()
go calculateData(concurrent, processingTime, endTime-statTime, maxTime, minTime, successNum, failureNum,
chanIDLen, errCode, receivedBytes)
chanIDLen, errCode, receivedBytes, curTime)
mutex.Unlock()
case <-stopChan:
// 处理完成
return
@ -102,6 +104,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
for data := range ch {
mutex.Lock()
// fmt.Println("处理一条数据", data.ID, data.Time, data.IsSucceed, data.ErrCode)
curTime = data.Time
processingTime = processingTime + data.Time
if maxTime <= data.Time {
maxTime = data.Time
@ -131,13 +134,14 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
}
requestTimeList = append(requestTimeList, data.Time)
mutex.Unlock()
}
// 数据全部接受完成,停止定时输出统计数据
stopChan <- true
endTime := uint64(time.Now().UnixNano())
requestTime = endTime - statTime
calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum, chanIDLen, errCode,
receivedBytes)
receivedBytes, curTime)
log.Infof("\n\n")
log.Infof("************************* 结果 stat ****************************")
@ -160,15 +164,15 @@ func printTop(requestTimeList []uint64) {
all := tools.MyUint64List{}
all = requestTimeList
sort.Sort(all)
log.Infof("tp90:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.90)]/1e6)))
log.Infof("tp95:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.95)]/1e6)))
log.Infof("tp99:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.99)]/1e6)))
// log.Infof("tp90:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.90)]/1e6)))
// log.Infof("tp95:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.95)]/1e6)))
// log.Infof("tp99:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.99)]/1e6)))
}
// calculateData 计算数据
func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum uint64,
chanIDLen int, errCode *sync.Map, receivedBytes int64) {
chanIDLen int, errCode *sync.Map, receivedBytes int64, curTime uint64) {
if processingTime == 0 {
processingTime = 1
}
@ -190,7 +194,7 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
// 纳秒=>毫秒
maxTimeFloat = float64(maxTime) / 1e6
minTimeFloat = float64(minTime) / 1e6
requestTimeFloat = float64(requestTime) / 1e9
requestTimeFloat = float64(curTime) / 1e6 // float64(requestTime) / 1e9
// 打印的时长都为毫秒
table(successNum, failureNum, errCode, qps, averageTime, maxTimeFloat, minTimeFloat, requestTimeFloat, chanIDLen,
receivedBytes)
@ -200,9 +204,9 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
func header() {
log.Infof("\n\n")
// 打印的时长都为毫秒 总请数
log.Infof("─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬───────")
log.Infof(" 耗时│ 并发数│ 成功数│ 失败数 qps │最长耗时│最短耗时│平均耗时│下载字节│字节每秒│ 状态码")
log.Infof("─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼───────")
log.Infof("─────┬───────┬───────┬───────┬────────┬──────────────────────┬───────────┬────────┬─────────┬───────")
log.Infof(" 耗时│ 并发数│ 成功数│ 失败数 qps │最长耗时 ms │最短耗时 ms│平均耗时 ms│下载字节│ 字节每秒 │ 状态码")
log.Infof("─────┼───────┼───────┼───────┼────────┼──────────────────────┼───────────┼────────┼─────────┼───────")
return
}
@ -212,8 +216,8 @@ func table(successNum, failureNum uint64, errCode *sync.Map,
var (
speed int64
)
if requestTimeFloat > 0 {
speed = int64(float64(receivedBytes) / requestTimeFloat)
if averageTime > 0 {
speed = int64(float64(receivedBytes) / averageTime * 1e6 / 8 / 1024)
} else {
speed = 0
}

View File

@ -9,12 +9,9 @@ import (
"go_dreamfactory/stress/model"
"go_dreamfactory/stress/server"
"go_dreamfactory/stress/server/statistics"
"io/ioutil"
"runtime"
"strings"
"time"
"gopkg.in/yaml.v2"
)
// array 自定义数组参数
@ -77,34 +74,13 @@ type Options struct {
Setting core.ServiceSttings //服务参数配置
}
func newOptions(path string) *Options {
options := &Options{}
yamlFile, err := ioutil.ReadFile(path)
if err != nil {
panic(fmt.Sprintf("读取服务配置【%s】文件失败err:%v:", options.ConfPath, err))
}
err = yaml.Unmarshal(yamlFile, &options.Setting)
if err != nil {
panic(fmt.Sprintf("读取服务配置【%s】文件失败err:%v:", options.ConfPath, err))
}
return options
}
//go:generate go build main.go
func main() {
runtime.GOMAXPROCS(cpuNumber)
flag.Parse()
statistics.InitLog()
// op := newOptions("./conf/stress_1.yaml")
// if err := log.OnInit(op.Setting.Sys["log"]); err != nil {
// panic(fmt.Sprintf("Sys log Init err:%v", err))
// } else {
// log.Infof("Sys log Init success !")
// }
// log.Debugf("ddddd")
//go run .\main.go -c 10 -n 10 -u ws://10.0.5.101:7891/gateway
concurrency = 1
concurrency = 1000
totalNumber = 1
debugStr = "false"
requestURL = "ws://10.0.0.9:7891/gateway"