Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
79a6e8aab7
@ -62,6 +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,
|
||||||
|
@ -26,6 +26,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
s.OnInstallComp( //装备组件
|
s.OnInstallComp( //装备组件
|
||||||
)
|
)
|
||||||
|
|
||||||
lego.Run(s, //运行模块
|
lego.Run(s, //运行模块
|
||||||
gateway.NewModule(),
|
gateway.NewModule(),
|
||||||
)
|
)
|
||||||
|
@ -3,17 +3,21 @@ package statistics
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/stress/tools"
|
"go_dreamfactory/stress/tools"
|
||||||
|
|
||||||
|
"go_dreamfactory/stress/model"
|
||||||
|
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"golang.org/x/text/message"
|
"golang.org/x/text/message"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
"go_dreamfactory/stress/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -23,6 +27,35 @@ var (
|
|||||||
requestTimeList []uint64 // 所有请求响应时间
|
requestTimeList []uint64 // 所有请求响应时间
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
ConfPath string //配置文件路径
|
||||||
|
Version string //服务版本
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func 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("ddddd Sys log Init success !")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ReceivingResults 接收结果并处理
|
// ReceivingResults 接收结果并处理
|
||||||
// 统计的时间都是纳秒,显示的时间 都是毫秒
|
// 统计的时间都是纳秒,显示的时间 都是毫秒
|
||||||
// concurrent 并发数
|
// concurrent 并发数
|
||||||
@ -30,6 +63,7 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
|
|||||||
defer func() {
|
defer func() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var stopChan = make(chan bool)
|
var stopChan = make(chan bool)
|
||||||
// 时间
|
// 时间
|
||||||
var (
|
var (
|
||||||
@ -105,16 +139,17 @@ func ReceivingResults(concurrent uint64, ch <-chan *model.RequestResults, wg *sy
|
|||||||
calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum, chanIDLen, errCode,
|
calculateData(concurrent, processingTime, requestTime, maxTime, minTime, successNum, failureNum, chanIDLen, errCode,
|
||||||
receivedBytes)
|
receivedBytes)
|
||||||
|
|
||||||
fmt.Printf("\n\n")
|
log.Infof("\n\n")
|
||||||
fmt.Println("************************* 结果 stat ****************************")
|
log.Infof("************************* 结果 stat ****************************")
|
||||||
fmt.Println("处理协程数量:", concurrent)
|
log.Infof("处理协程数量:", concurrent)
|
||||||
// fmt.Println("处理协程数量:", concurrent, "程序处理总时长:", fmt.Sprintf("%.3f", float64(processingTime/concurrent)/1e9), "秒")
|
|
||||||
fmt.Println("请求总数(并发数*请求数 -c * -n):", successNum+failureNum, "总请求时间:",
|
// fmt.Println("处理协程数量:", concurrent, "程序处理总时长:", log("%.3f", float64(processingTime/concurrent)/1e9), "秒")
|
||||||
|
log.Infof("请求总数(并发数*请求数 -c * -n):", successNum+failureNum, "总请求时间:",
|
||||||
fmt.Sprintf("%.3f", float64(requestTime)/1e9),
|
fmt.Sprintf("%.3f", float64(requestTime)/1e9),
|
||||||
"秒", "successNum:", successNum, "failureNum:", failureNum)
|
"秒", "successNum:", successNum, "failureNum:", failureNum)
|
||||||
printTop(requestTimeList)
|
printTop(requestTimeList)
|
||||||
fmt.Println("************************* 结果 end ****************************")
|
log.Infof("************************* 结果 end ****************************")
|
||||||
fmt.Printf("\n\n")
|
log.Infof("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// printTop 排序后计算 top 90 95 99
|
// printTop 排序后计算 top 90 95 99
|
||||||
@ -125,9 +160,10 @@ func printTop(requestTimeList []uint64) {
|
|||||||
all := tools.MyUint64List{}
|
all := tools.MyUint64List{}
|
||||||
all = requestTimeList
|
all = requestTimeList
|
||||||
sort.Sort(all)
|
sort.Sort(all)
|
||||||
fmt.Println("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)))
|
||||||
fmt.Println("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)))
|
||||||
fmt.Println("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 计算数据
|
||||||
@ -162,11 +198,11 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
|
|||||||
|
|
||||||
// header 打印表头信息
|
// header 打印表头信息
|
||||||
func header() {
|
func header() {
|
||||||
fmt.Printf("\n\n")
|
log.Infof("\n\n")
|
||||||
// 打印的时长都为毫秒 总请数
|
// 打印的时长都为毫秒 总请数
|
||||||
fmt.Println("─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────")
|
log.Infof("─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────")
|
||||||
fmt.Println(" 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│下载字节│字节每秒│ 状态码")
|
log.Infof(" 耗时│ 并发数│ 成功数│ 失败数│ qps │最长耗时│最短耗时│平均耗时│下载字节│字节每秒│ 状态码")
|
||||||
fmt.Println("─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────")
|
log.Infof("─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +234,7 @@ func table(successNum, failureNum uint64, errCode *sync.Map,
|
|||||||
requestTimeFloat, chanIDLen, successNum, failureNum, qps, maxTimeFloat, minTimeFloat, averageTime,
|
requestTimeFloat, chanIDLen, successNum, failureNum, qps, maxTimeFloat, minTimeFloat, averageTime,
|
||||||
receivedBytesStr, speedStr,
|
receivedBytesStr, speedStr,
|
||||||
printMap(errCode))
|
printMap(errCode))
|
||||||
fmt.Println(result)
|
log.Infof(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,11 +5,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/stress/model"
|
"go_dreamfactory/stress/model"
|
||||||
"go_dreamfactory/stress/server"
|
"go_dreamfactory/stress/server"
|
||||||
|
"go_dreamfactory/stress/server/statistics"
|
||||||
|
"io/ioutil"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// array 自定义数组参数
|
// array 自定义数组参数
|
||||||
@ -66,14 +71,43 @@ func init() {
|
|||||||
// main go 实现的压测工具
|
// main go 实现的压测工具
|
||||||
// 编译可执行文件
|
// 编译可执行文件
|
||||||
//
|
//
|
||||||
|
type Options struct {
|
||||||
|
ConfPath string //配置文件路径
|
||||||
|
Version string //服务版本
|
||||||
|
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()
|
||||||
|
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
|
//go run .\main.go -c 10 -n 10 -u ws://10.0.5.101:7891/gateway
|
||||||
concurrency = 100
|
concurrency = 1
|
||||||
totalNumber = 100
|
totalNumber = 1
|
||||||
debugStr = "false"
|
debugStr = "false"
|
||||||
requestURL = "ws://10.0.0.85:7891/gateway"
|
requestURL = "ws://10.0.0.9:7891/gateway"
|
||||||
verify = "pb"
|
verify = "pb"
|
||||||
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
|
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
|
||||||
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")
|
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")
|
||||||
|
Loading…
Reference in New Issue
Block a user