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 // 设置竞技场用户积分
15bingo:sociatyexp,100 // 设置工会经验
15bingo:sociatyactivity,100 // 设置工会活跃
15bingo:alltask // bingo所有任务
*/
//参数校验
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))
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{
ws: ws,
sid: "dfmxf",
sid: "df01",
}
r.account = r.RandStr1(13)
return r
@ -234,7 +234,8 @@ func (r *Robot) GetMessagedata() (data []byte, err error) {
}
return data, err
}
func (r *Robot) Login() error {
func (r *Robot) Login() int64 {
var byteLen int64
msg := &pb.UserMessage{MainType: "user", SubType: "login"}
rsp := &pb.UserLoginReq{
Account: "user001",
@ -243,9 +244,36 @@ func (r *Robot) Login() error {
msg.Sec = r.BuildSecStr()
if comm.ProtoMarshal(rsp, 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 {
@ -272,7 +300,8 @@ func (r Robot) GetRandUser() bool {
}
//return true
}
func (r *Robot) Create() bool {
func (r *Robot) Create() int64 {
var byteLen int64
mainType := "user"
subType := "create"
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
@ -294,12 +323,34 @@ func (r *Robot) Create() bool {
}
}
for { // 防止丢包
if b, _ := r.MessageRsp(mainType, subType); b {
return true
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 == "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 (
"context"
"fmt"
"go_dreamfactory/pb"
"go_dreamfactory/stress/model"
"go_dreamfactory/stress/robot"
"strconv"
@ -55,11 +54,13 @@ func Dispose(ctx context.Context, concurrency, totalNumber uint64, request *mode
case 1:
// 连接以后再启动协程
r := robot.NewRobot(request.URL)
r.SetAccount("00000" + strconv.Itoa(int(i)))
head := &pb.UserMessage{MainType: "user", SubType: "login"}
r.SetAccount("21112" + strconv.Itoa(int(i)))
//head := &pb.UserMessage{MainType: "user", SubType: "login"}
// 先登录
r.SendToClient(head, &pb.UserLoginReq{})
//r.SendToClient(head, &pb.UserLoginReq{})
//r.AddGrormetItem()
//r.Create()
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
case 2:
// 并发建立长链接

View File

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

View File

@ -192,7 +192,7 @@ func calculateData(concurrent, processingTime, requestTime, maxTime, minTime, su
// 纳秒=>毫秒
maxTimeFloat = float64(maxTime) / 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,
receivedBytes)
@ -233,7 +233,7 @@ func table(successNum, failureNum uint64, errCode *sync.Map,
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,
receivedBytesStr, speedStr,
printMap(errCode))

View File

@ -9,6 +9,7 @@ import (
"go_dreamfactory/stress/model"
"go_dreamfactory/stress/server"
"go_dreamfactory/stress/server/statistics"
"runtime"
"strings"
"time"
)
@ -75,14 +76,14 @@ type Options struct {
//go:generate go build main.go
func main() {
//runtime.GOMAXPROCS(cpuNumber)
runtime.GOMAXPROCS(cpuNumber)
flag.Parse()
statistics.InitLog()
concurrency = 10
concurrency = 1000
totalNumber = 1
debugStr = "false"
requestURL = "ws://10.0.0.85:7891/gateway"
requestURL = "ws://106.54.189.74:7891/gateway"
verify = "pb"
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")