Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
ee081b1e99
@ -203,7 +203,14 @@ func (r *Robot) MessageRsp(mainType, subType string) (bool, int64) {
|
|||||||
}
|
}
|
||||||
//fmt.Printf("接收消息=====loginData:%v,userExpand:%v\n", resp.Data, resp.Ex)
|
//fmt.Printf("接收消息=====loginData:%v,userExpand:%v\n", resp.Data, resp.Ex)
|
||||||
return true, byteLen
|
return true, byteLen
|
||||||
} else if msg.MainType == "goutmet" && msg.SubType == "getranduser" {
|
} else if msg.MainType == "gourmet" && msg.SubType == "getranduser" {
|
||||||
|
resp := &pb.GourmetGetRandUserResp{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
|
return false, byteLen
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, byteLen
|
||||||
|
} else if msg.MainType == "gourmet" && msg.SubType == "getlist" {
|
||||||
resp := &pb.GourmetGetRandUserResp{}
|
resp := &pb.GourmetGetRandUserResp{}
|
||||||
if !comm.ProtoUnmarshal(msg, resp) {
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
return false, byteLen
|
return false, byteLen
|
||||||
@ -220,12 +227,12 @@ func (r *Robot) CloseHandler() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Robot) GetMessagedata() []byte {
|
func (r *Robot) GetMessagedata() (data []byte, err error) {
|
||||||
_, data, err := r.ws.ReadMessage()
|
_, data, err = r.ws.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("readMessage err:%v", err)
|
fmt.Printf("readMessage err:%v", err)
|
||||||
}
|
}
|
||||||
return data
|
return data, err
|
||||||
}
|
}
|
||||||
func (r *Robot) Login() error {
|
func (r *Robot) Login() error {
|
||||||
msg := &pb.UserMessage{MainType: "user", SubType: "login"}
|
msg := &pb.UserMessage{MainType: "user", SubType: "login"}
|
||||||
@ -242,8 +249,8 @@ func (r *Robot) Login() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r Robot) GetRandUser() bool {
|
func (r Robot) GetRandUser() bool {
|
||||||
mainType := "goutmet"
|
mainType := "gourmet"
|
||||||
subType := "getlist"
|
subType := "getranduser"
|
||||||
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||||
|
|
||||||
rsp := &pb.GourmetGetRandUserReq{
|
rsp := &pb.GourmetGetRandUserReq{
|
||||||
@ -258,12 +265,12 @@ func (r Robot) GetRandUser() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
for {
|
||||||
if b, _ := r.MessageRsp(mainType, subType); b {
|
if b, _ := r.MessageRsp(mainType, subType); b {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
//return true
|
||||||
}
|
}
|
||||||
func (r *Robot) Create() bool {
|
func (r *Robot) Create() bool {
|
||||||
mainType := "user"
|
mainType := "user"
|
||||||
@ -287,24 +294,22 @@ func (r *Robot) Create() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 100; i++ { // 防止丢包
|
for { // 防止丢包
|
||||||
if b, _ := r.MessageRsp(mainType, subType); b {
|
if b, _ := r.MessageRsp(mainType, subType); b {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
//return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取美食家信息列表数据
|
// 获取美食家信息列表数据
|
||||||
func (r Robot) GetGourmetList() int64 {
|
func (r Robot) GetGourmetList() {
|
||||||
var byteLen int64
|
|
||||||
mainType := "goutmet"
|
mainType := "gourmet"
|
||||||
subType := "getranduser"
|
subType := "getlist"
|
||||||
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||||
|
|
||||||
rsp := &pb.GourmetGetRandUserReq{
|
rsp := &pb.GourmetGetListReq{}
|
||||||
People: 3,
|
|
||||||
}
|
|
||||||
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)
|
||||||
@ -314,30 +319,31 @@ func (r Robot) GetGourmetList() int64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
// for {
|
||||||
var msg *pb.UserMessage = &pb.UserMessage{}
|
// var msg *pb.UserMessage = &pb.UserMessage{}
|
||||||
_, data, err := r.ws.ReadMessage()
|
// _, data, err := r.ws.ReadMessage()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
fmt.Printf("readMessage err:%v", err)
|
// fmt.Printf("readMessage err:%v", err)
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
byteLen += int64(len(data))
|
|
||||||
if err = proto.Unmarshal(data, msg); err != nil {
|
// if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
fmt.Printf("unmarshal err:%v", err)
|
// fmt.Printf("unmarshal err:%v", err)
|
||||||
}
|
// }
|
||||||
if msg.MainType == "goutmet" && msg.SubType == "getlist" {
|
// if msg.MainType == mainType && msg.SubType == subType {
|
||||||
resp := &pb.GourmetGetListResp{}
|
// byteLen += int64(len(data))
|
||||||
if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
|
// resp := &pb.GourmetGetListResp{}
|
||||||
break
|
// if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
|
||||||
}
|
// break
|
||||||
break
|
// }
|
||||||
}
|
// break
|
||||||
}
|
// }
|
||||||
return byteLen
|
// }
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// addItem
|
// addItem
|
||||||
func (r Robot) AddGrormetItem() {
|
func (r Robot) AddGrormetItem() bool {
|
||||||
mainType := "gm"
|
mainType := "gm"
|
||||||
subType := "cmd"
|
subType := "cmd"
|
||||||
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
msg := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||||
@ -353,4 +359,8 @@ func (r Robot) AddGrormetItem() {
|
|||||||
fmt.Printf("WriteMessage err:%v", err)
|
fmt.Printf("WriteMessage err:%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (r *Robot) SetAccount(account string) {
|
||||||
|
r.account = account
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"go_dreamfactory/stress/model"
|
"go_dreamfactory/stress/model"
|
||||||
"go_dreamfactory/stress/robot"
|
"go_dreamfactory/stress/robot"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -53,7 +54,7 @@ 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)))
|
||||||
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
|
go golink.WebSocket(ctx, i, ch, totalNumber, &wg, request, r)
|
||||||
case 2:
|
case 2:
|
||||||
// 并发建立长链接
|
// 并发建立长链接
|
||||||
|
@ -3,13 +3,17 @@ package golink
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/stress/helper"
|
"go_dreamfactory/stress/helper"
|
||||||
"go_dreamfactory/stress/model"
|
"go_dreamfactory/stress/model"
|
||||||
"go_dreamfactory/stress/robot"
|
"go_dreamfactory/stress/robot"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -23,7 +27,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
keepAlive = false
|
keepAlive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSocket webSocket go link
|
// WebSocket webSocket go link
|
||||||
@ -75,12 +79,13 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
|
|||||||
errCode = model.HTTPOk
|
errCode = model.HTTPOk
|
||||||
byteLen int64 // 协议传输字节数
|
byteLen int64 // 协议传输字节数
|
||||||
)
|
)
|
||||||
|
|
||||||
// 需要发送的数据
|
// 需要发送的数据
|
||||||
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()
|
//time.Sleep(1 * time.Millisecond)
|
||||||
// for {
|
// for {
|
||||||
// if b, len := r.MessageRsp("user", "login"); b {
|
// if b, len := r.MessageRsp("user", "login"); b {
|
||||||
// byteLen += len
|
// byteLen += len
|
||||||
@ -89,10 +94,37 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
|
|||||||
// break
|
// break
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// r.Create()
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
//r.Create()
|
||||||
|
//isSucceed = r.AddGrormetItem()
|
||||||
|
|
||||||
|
//startTime := time.Now()
|
||||||
// r.GetRandUser() // 获取随机在线玩家数据
|
// r.GetRandUser() // 获取随机在线玩家数据
|
||||||
byteLen = r.GetGourmetList()
|
|
||||||
|
r.GetGourmetList()
|
||||||
|
|
||||||
|
for {
|
||||||
|
var msg *pb.UserMessage = &pb.UserMessage{}
|
||||||
|
data, err := r.GetMessagedata()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("readMessage err:%v", err)
|
||||||
|
isSucceed = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
|
fmt.Printf("unmarshal err:%v", err)
|
||||||
|
}
|
||||||
|
if msg.MainType == "gourmet" && msg.SubType == "getlist" {
|
||||||
|
byteLen += int64(len(data))
|
||||||
|
isSucceed = true
|
||||||
|
resp := &pb.GourmetGetListResp{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, resp) { //反序列化失败
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
requestTime := uint64(helper.DiffNano(startTime))
|
requestTime := uint64(helper.DiffNano(startTime))
|
||||||
requestResults := &model.RequestResults{
|
requestResults := &model.RequestResults{
|
||||||
ID: "",
|
ID: "",
|
||||||
|
@ -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.0fs│%7d│%7d│%7d│%8.2f│%8.2f│%8.2f│%8.2f│%8s│%8s│%v",
|
result := fmt.Sprintf("%4.0fms│%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))
|
||||||
|
@ -79,7 +79,7 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
statistics.InitLog()
|
statistics.InitLog()
|
||||||
|
|
||||||
concurrency = 12
|
concurrency = 10
|
||||||
totalNumber = 1
|
totalNumber = 1
|
||||||
debugStr = "false"
|
debugStr = "false"
|
||||||
requestURL = "ws://10.0.0.85:7891/gateway"
|
requestURL = "ws://10.0.0.85:7891/gateway"
|
||||||
|
Loading…
Reference in New Issue
Block a user