update
This commit is contained in:
parent
79a6e8aab7
commit
282f3eb1bb
@ -62,7 +62,7 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co
|
|||||||
|
|
||||||
// Start 模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
|
// Start 模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
|
||||||
func (this *Gateway) Start() (err error) {
|
func (this *Gateway) Start() (err error) {
|
||||||
log.Debugf("dddd")
|
|
||||||
_name2Func := map[string]any{
|
_name2Func := map[string]any{
|
||||||
// 注册用户绑定uid接口 登录成功后触发
|
// 注册用户绑定uid接口 登录成功后触发
|
||||||
string(comm.Rpc_GatewayAgentBind): this.agentMgr.Bind,
|
string(comm.Rpc_GatewayAgentBind): this.agentMgr.Bind,
|
||||||
|
@ -61,6 +61,8 @@ end:
|
|||||||
// 保持连接
|
// 保持连接
|
||||||
chWaitFor := make(chan int, 0)
|
chWaitFor := make(chan int, 0)
|
||||||
<-chWaitFor
|
<-chWaitFor
|
||||||
|
//time.Sleep(15 * time.Millisecond)
|
||||||
|
//return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func InitLog() {
|
|||||||
if err := log.OnInit(op.Setting.Sys["log"]); err != nil {
|
if err := log.OnInit(op.Setting.Sys["log"]); err != nil {
|
||||||
panic(fmt.Sprintf("Sys log Init err:%v", err))
|
panic(fmt.Sprintf("Sys log Init err:%v", err))
|
||||||
} else {
|
} 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 // 请求总时间
|
requestTime uint64 // 请求总时间
|
||||||
maxTime uint64 // 最大时长
|
maxTime uint64 // 最大时长
|
||||||
minTime uint64 // 最小时长
|
minTime uint64 // 最小时长
|
||||||
|
curTime uint64 // 当前消耗时常
|
||||||
successNum uint64 // 成功处理数,code为0
|
successNum uint64 // 成功处理数,code为0
|
||||||
failureNum uint64 // 处理失败数,code不为0 0
|
failureNum uint64 // 处理失败数,code不为0 0
|
||||||
chanIDLen int // 并发数
|
chanIDLen int // 并发数
|
||||||
@ -90,8 +91,9 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
|
|||||||
endTime := uint64(time.Now().UnixNano())
|
endTime := uint64(time.Now().UnixNano())
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
go calculateData(concurrent, processingTime, endTime-statTime, maxTime, minTime, successNum, failureNum,
|
go calculateData(concurrent, processingTime, endTime-statTime, maxTime, minTime, successNum, failureNum,
|
||||||
chanIDLen, errCode, receivedBytes)
|
chanIDLen, errCode, receivedBytes, curTime)
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
|
|
||||||
case <-stopChan:
|
case <-stopChan:
|
||||||
// 处理完成
|
// 处理完成
|
||||||
return
|
return
|
||||||
@ -102,6 +104,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
|
|||||||
for data := range ch {
|
for data := range ch {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
// fmt.Println("处理一条数据", data.ID, data.Time, data.IsSucceed, data.ErrCode)
|
// fmt.Println("处理一条数据", data.ID, data.Time, data.IsSucceed, data.ErrCode)
|
||||||
|
curTime = data.Time
|
||||||
processingTime = processingTime + data.Time
|
processingTime = processingTime + data.Time
|
||||||
if maxTime <= data.Time {
|
if maxTime <= data.Time {
|
||||||
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)
|
requestTimeList = append(requestTimeList, data.Time)
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
|
|
||||||
}
|
}
|
||||||
// 数据全部接受完成,停止定时输出统计数据
|
// 数据全部接受完成,停止定时输出统计数据
|
||||||
stopChan <- true
|
stopChan <- true
|
||||||
endTime := uint64(time.Now().UnixNano())
|
endTime := uint64(time.Now().UnixNano())
|
||||||
requestTime = endTime - statTime
|
requestTime = endTime - statTime
|
||||||
calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum, chanIDLen, errCode,
|
calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum, chanIDLen, errCode,
|
||||||
receivedBytes)
|
receivedBytes, curTime)
|
||||||
|
|
||||||
log.Infof("\n\n")
|
log.Infof("\n\n")
|
||||||
log.Infof("************************* 结果 stat ****************************")
|
log.Infof("************************* 结果 stat ****************************")
|
||||||
@ -160,15 +164,15 @@ func printTop(requestTimeList []uint64) {
|
|||||||
all := tools.MyUint64List{}
|
all := tools.MyUint64List{}
|
||||||
all = requestTimeList
|
all = requestTimeList
|
||||||
sort.Sort(all)
|
sort.Sort(all)
|
||||||
log.Infof("tp90:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.90)]/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("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("tp99:", fmt.Sprintf("%.3f", float64(all[int(float64(len(all))*0.99)]/1e6)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculateData 计算数据
|
// calculateData 计算数据
|
||||||
func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum uint64,
|
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 {
|
if processingTime == 0 {
|
||||||
processingTime = 1
|
processingTime = 1
|
||||||
}
|
}
|
||||||
@ -190,7 +194,7 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
|
|||||||
// 纳秒=>毫秒
|
// 纳秒=>毫秒
|
||||||
maxTimeFloat = float64(maxTime) / 1e6
|
maxTimeFloat = float64(maxTime) / 1e6
|
||||||
minTimeFloat = float64(minTime) / 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,
|
table(successNum, failureNum, errCode, qps, averageTime, maxTimeFloat, minTimeFloat, requestTimeFloat, chanIDLen,
|
||||||
receivedBytes)
|
receivedBytes)
|
||||||
@ -200,9 +204,9 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
|
|||||||
func header() {
|
func header() {
|
||||||
log.Infof("\n\n")
|
log.Infof("\n\n")
|
||||||
// 打印的时长都为毫秒 总请数
|
// 打印的时长都为毫秒 总请数
|
||||||
log.Infof("─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────")
|
log.Infof("─────┬───────┬───────┬───────┬────────┬───────────┬───────────┬───────────┬────────┬─────────┬───────")
|
||||||
log.Infof(" 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│下载字节│字节每秒│ 状态码")
|
log.Infof(" 耗时│ 并发数│ 成功数│ 失败数 │ qps │最长耗时 ms │最短耗时 ms│平均耗时 ms│下载字节│ 字节每秒 │ 状态码")
|
||||||
log.Infof("─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────")
|
log.Infof("─────┼───────┼───────┼───────┼────────┼───────────┼───────────┼───────────┼────────┼─────────┼───────")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,8 +216,8 @@ func table(successNum, failureNum uint64, errCode *sync.Map,
|
|||||||
var (
|
var (
|
||||||
speed int64
|
speed int64
|
||||||
)
|
)
|
||||||
if requestTimeFloat > 0 {
|
if averageTime > 0 {
|
||||||
speed = int64(float64(receivedBytes) / requestTimeFloat)
|
speed = int64(float64(receivedBytes) / averageTime * 1e6 / 8 / 1024)
|
||||||
} else {
|
} else {
|
||||||
speed = 0
|
speed = 0
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,9 @@ import (
|
|||||||
"go_dreamfactory/stress/model"
|
"go_dreamfactory/stress/model"
|
||||||
"go_dreamfactory/stress/server"
|
"go_dreamfactory/stress/server"
|
||||||
"go_dreamfactory/stress/server/statistics"
|
"go_dreamfactory/stress/server/statistics"
|
||||||
"io/ioutil"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// array 自定义数组参数
|
// array 自定义数组参数
|
||||||
@ -77,34 +74,13 @@ type Options struct {
|
|||||||
Setting core.ServiceSttings //服务参数配置
|
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
|
//go:generate go build main.go
|
||||||
func main() {
|
func main() {
|
||||||
runtime.GOMAXPROCS(cpuNumber)
|
runtime.GOMAXPROCS(cpuNumber)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
statistics.InitLog()
|
statistics.InitLog()
|
||||||
// op := newOptions("./conf/stress_1.yaml")
|
|
||||||
// if err := log.OnInit(op.Setting.Sys["log"]); err != nil {
|
concurrency = 1000
|
||||||
// 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
|
|
||||||
totalNumber = 1
|
totalNumber = 1
|
||||||
debugStr = "false"
|
debugStr = "false"
|
||||||
requestURL = "ws://10.0.0.9:7891/gateway"
|
requestURL = "ws://10.0.0.9:7891/gateway"
|
||||||
|
Loading…
Reference in New Issue
Block a user