| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package main
- import (
- "log"
- "rocommon"
- "rocommon/socket"
- _ "rocommon/socket/tcp"
- "roserver/serverproto"
- _ "roserver/test/model"
- "sync"
- "time"
- )
- var (
- lock sync.Mutex
- totalConnNum int = 0
- )
- const maxConnNum = 1
- func client() {
- queue := rocommon.NewEventQueue()
- queue.StartQueue()
- node := socket.NewServerNode("tcpConnector", "client", "127.0.0.1:21001", queue)
- rv := rocommon.NewNetSyncRecv(node)
- socket.SetProcessorRPC(node, "tcp.demo", rv.EventCB())
- node.(rocommon.TCPConnector).SetReconnectTime(5 * time.Second)
- node.Start()
- rv.WaitMsg(rocommon.SessionConnected{})
- lock.Lock()
- totalConnNum++
- if totalConnNum >= maxConnNum {
- log.Print("totalConnNum:", totalConnNum)
- }
- lock.Unlock()
- node.(rocommon.TCPConnector).Session().Send(&serverproto.CSPingReq{
- OpenId: "hello",
- })
- begin := time.Now()
- lastCheck := begin
- totalCount := 0
- respTime := time.Now()
- var avgTime float64 = 0
- const total = 100000 * time.Second
- for {
- now := time.Now()
- if now.Sub(begin) >= total {
- break
- }
- if now.Sub(lastCheck) >= 20*time.Second {
- //log.Printf("progress count pid[%v]: %v %v",syscall.Getpid(), totalCount, now.Sub(begin) * 100 / total)
- lastCheck = now
- log.Printf("count:%v, avtTime:%v\n", totalCount, avgTime/float64(totalCount)/1000.0/1000.0)
- totalCount = 0
- avgTime = 0
- }
- rv.Recv(func(ev rocommon.ProcEvent) {
- totalCount++
- if totalCount > 1 {
- recvTime := time.Now()
- avgTime += float64(recvTime.Sub(respTime).Nanoseconds())
- //log.Println("respTime:", recvTime.Sub(respTime))
- respTime = recvTime
- }
- time.Sleep(200 * time.Millisecond)
- respTime = time.Now()
- ev.Session().Send(&serverproto.CSPingReq{
- OpenId: "hello",
- })
- })
- }
- }
- func main() {
- for i := 0; i < maxConnNum-1; i++ {
- go client()
- }
- client()
- }
|