Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev

This commit is contained in:
meixiongfeng 2022-12-08 15:51:25 +08:00
commit ecbcd34e31
7 changed files with 98 additions and 24 deletions

View File

@ -29,6 +29,7 @@ import (
14bingo:arena,100 // 设置竞技场用户积分 14bingo:arena,100 // 设置竞技场用户积分
15bingo:sociatyexp,100 // 设置工会经验 15bingo:sociatyexp,100 // 设置工会经验
15bingo:sociatyactivity,100 // 设置工会活跃 15bingo:sociatyactivity,100 // 设置工会活跃
15bingo:alltask // bingo所有任务
*/ */
//参数校验 //参数校验
func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) { func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) {

View File

@ -244,6 +244,16 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
} }
module1.(comm.ISociaty).BingoSetActivity(session, int32(num)) module1.(comm.ISociaty).BingoSetActivity(session, int32(num))
this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]})
} else if len(datas) == 1 && (datas[0] == "alltask") { // 设置工会活跃度
module, err := this.service.GetModule(comm.ModuleWorldtask)
if err != nil {
return
}
if wt, ok := module.(comm.IWorldtask); ok {
if err = wt.BingoAllTask(session); err != nil {
this.Error("bingo 世界任务", log.Fields{"params": datas, "err": err.Error()})
}
}
} }
} }

View File

@ -57,7 +57,7 @@ func NewRobot(url string) *Robot {
} }
r := &Robot{ r := &Robot{
ws: ws, ws: ws,
sid: "dfmxf", sid: "df01",
} }
r.account = r.RandStr1(13) r.account = r.RandStr1(13)
return r return r
@ -234,7 +234,8 @@ func (r *Robot) GetMessagedata() (data []byte, err error) {
} }
return data, err return data, err
} }
func (r *Robot) Login() error { func (r *Robot) Login() int64 {
var byteLen int64
msg := &pb.UserMessage{MainType: "user", SubType: "login"} msg := &pb.UserMessage{MainType: "user", SubType: "login"}
rsp := &pb.UserLoginReq{ rsp := &pb.UserLoginReq{
Account: "user001", Account: "user001",
@ -243,9 +244,36 @@ func (r *Robot) Login() error {
msg.Sec = r.BuildSecStr() msg.Sec = r.BuildSecStr()
if comm.ProtoMarshal(rsp, msg) { if comm.ProtoMarshal(rsp, msg) {
data, _ := proto.Marshal(msg) data, _ := proto.Marshal(msg)
return r.ws.WriteMessage(websocket.BinaryMessage, data) r.ws.WriteMessage(websocket.BinaryMessage, data)
} }
return nil for {
var msg *pb.UserMessage = &pb.UserMessage{}
_, data, err := r.ws.ReadMessage()
if err != nil {
fmt.Printf("readMessage err:%v", err)
continue
}
if err = proto.Unmarshal(data, msg); err != nil {
fmt.Printf("unmarshal err:%v", err)
}
if msg.MainType == "user" && msg.SubType == "login" {
byteLen += int64(len(data))
resp := &pb.UserLoginResp{}
if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
break
}
break
} else if msg.MainType == "notify" && msg.SubType == "errornotify" {
rsp := &pb.NotifyErrorNotifyPush{}
if !comm.ProtoUnmarshal(msg, rsp) { // 记录错误码
byteLen = 0
break
}
}
}
return byteLen
} }
func (r Robot) GetRandUser() bool { func (r Robot) GetRandUser() bool {
@ -272,7 +300,8 @@ func (r Robot) GetRandUser() bool {
} }
//return true //return true
} }
func (r *Robot) Create() bool { func (r *Robot) Create() int64 {
var byteLen int64
mainType := "user" mainType := "user"
subType := "create" subType := "create"
msg := &pb.UserMessage{MainType: mainType, SubType: subType} msg := &pb.UserMessage{MainType: mainType, SubType: subType}
@ -294,12 +323,34 @@ func (r *Robot) Create() bool {
} }
} }
for { // 防止丢包 for {
if b, _ := r.MessageRsp(mainType, subType); b { var msg *pb.UserMessage = &pb.UserMessage{}
return true _, data, err := r.ws.ReadMessage()
if err != nil {
fmt.Printf("readMessage err:%v", err)
continue
}
if err = proto.Unmarshal(data, msg); err != nil {
fmt.Printf("unmarshal err:%v", err)
}
if msg.MainType == "user" && msg.SubType == "create" {
byteLen += int64(len(data))
resp := &pb.UserCreateResp{}
if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
break
}
break
} else if msg.MainType == "notify" && msg.SubType == "errornotify" {
rsp := &pb.NotifyErrorNotifyPush{}
if !comm.ProtoUnmarshal(msg, rsp) { // 记录错误码
byteLen = 0
break
} }
} }
//return false }
return byteLen
} }
// 获取美食家信息列表数据 // 获取美食家信息列表数据

View File

@ -4,7 +4,6 @@ package server
import ( import (
"context" "context"
"fmt" "fmt"
"go_dreamfactory/pb"
"go_dreamfactory/stress/model" "go_dreamfactory/stress/model"
"go_dreamfactory/stress/robot" "go_dreamfactory/stress/robot"
"strconv" "strconv"
@ -55,11 +54,13 @@ func Dispose(ctx context.Context, concurrency, totalNumber uint64, request *mode
case 1: case 1:
// 连接以后再启动协程 // 连接以后再启动协程
r := robot.NewRobot(request.URL) r := robot.NewRobot(request.URL)
r.SetAccount("00000" + strconv.Itoa(int(i))) r.SetAccount("21112" + strconv.Itoa(int(i)))
head := &pb.UserMessage{MainType: "user", SubType: "login"} //head := &pb.UserMessage{MainType: "user", SubType: "login"}
// 先登录 // 先登录
r.SendToClient(head, &pb.UserLoginReq{}) //r.SendToClient(head, &pb.UserLoginReq{})
//r.AddGrormetItem() //r.AddGrormetItem()
//r.Create()
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r) go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
case 2: case 2:
// 并发建立长链接 // 并发建立长链接

View File

@ -22,7 +22,7 @@ var (
) )
func init() { func init() {
keepAlive = true keepAlive = false
} }
// WebSocket webSocket go link // WebSocket webSocket go link
@ -76,16 +76,26 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
) )
startTime := time.Now() startTime := time.Now()
isSucceed = true
//r.Create() //r.Create()
//isSucceed = r.AddGrormetItem() //isSucceed = r.AddGrormetItem()
byteLen = r.Login()
if byteLen == 0 {
isSucceed = false
} else {
byteLen += r.Create()
}
if byteLen == 0 {
isSucceed = false
}
//startTime := time.Now() //startTime := time.Now()
// r.GetRandUser() // 获取随机在线玩家数据 // r.GetRandUser() // 获取随机在线玩家数据
//r.GetGourmetList()
byteLen = r.GourmetOrder() //byteLen = r.GourmetOrder()
if byteLen > 0 { // if byteLen > 0 {
isSucceed = true // isSucceed = true
} // }
// for { // for {
// var msg *pb.UserMessage = &pb.UserMessage{} // var msg *pb.UserMessage = &pb.UserMessage{}
// data, err := r.GetMessagedata() // data, err := r.GetMessagedata()

View File

@ -192,7 +192,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(curTime) / 1e6 // float64(requestTime) / 1e9 requestTimeFloat = float64(requestTime) / 1e9 // float64(curTime) / 1e6 //
// 打印的时长都为毫秒 // 打印的时长都为毫秒
table(successNum, failureNum, errCode, qps, averageTime, maxTimeFloat, minTimeFloat, requestTimeFloat, chanIDLen, table(successNum, failureNum, errCode, qps, averageTime, maxTimeFloat, minTimeFloat, requestTimeFloat, chanIDLen,
receivedBytes) receivedBytes)
@ -233,7 +233,7 @@ func table(successNum, failureNum uint64, errCode *sync.Map,
speedStr = p.Sprintf("%d", speed) speedStr = p.Sprintf("%d", speed)
} }
// 打印的时长都为毫秒 // 打印的时长都为毫秒
result := fmt.Sprintf("%4.0fms│%7d│%7d│%7d│%8.2f│%8.2f│%8.2f│%8.2f│%8s│%8s│%v", result := fmt.Sprintf("%4.0fs│%7d│%7d│%7d│%8.2f│%8.2f│%8.2f│%8.2f│%8s│%8s│%v",
requestTimeFloat, chanIDLen, successNum, failureNum, qps, maxTimeFloat, minTimeFloat, averageTime, requestTimeFloat, chanIDLen, successNum, failureNum, qps, maxTimeFloat, minTimeFloat, averageTime,
receivedBytesStr, speedStr, receivedBytesStr, speedStr,
printMap(errCode)) printMap(errCode))

View File

@ -9,6 +9,7 @@ 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"
"runtime"
"strings" "strings"
"time" "time"
) )
@ -75,14 +76,14 @@ type Options struct {
//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()
concurrency = 10 concurrency = 1000
totalNumber = 1 totalNumber = 1
debugStr = "false" debugStr = "false"
requestURL = "ws://10.0.0.85:7891/gateway" requestURL = "ws://106.54.189.74: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")