package main import "lmaxapi" import "log" import "time" import "runtime" import "runtime/pprof" import "os" import "sync/atomic" func main() { runtime.GOMAXPROCS(4) w, err := os.Create("me.pprof") if err != nil { panic(err) } pprof.StartCPUProfile(w) defer pprof.StopCPUProfile() testMtfEchoSync(1000000) //testMtfEcho(1000000) } func testMtfEcho(N int) { now := time.Now() mtf := lmaxapi.NewMtf(nil, nil) go mtf.Start() client := lmaxapi.NewMtfClient(mtf, time.Second, false) k := int64(N) done := make(chan int, 1) go client.Recv(func(msg *lmaxapi.Message) { v := atomic.AddInt64(&k, -1) if v == 0 { log.Println("recv message end") done <- 1 } }) err := client.ConnectPrivate() if err != nil { panic(err) } // log.Println("ready") i := 0 for i = 0; i < N; i++ { client.SendMessageAsyn(lmaxapi.MsgEcho, "echo") } <-done err = client.Close() if err != nil { log.Println(err) return } mtf.Close() // log.Println(time.Now().Sub(now), i) } func testMtfEchoSync(N int) { now := time.Now() mtf := lmaxapi.NewMtf(nil, nil) go mtf.Start() client := lmaxapi.NewMtfClient(mtf, 100*time.Millisecond, false) go client.Recv(func(msg *lmaxapi.Message) { log.Println("err message", msg) }) err := client.ConnectPrivate() if err != nil { panic(err) } // log.Println("ready") i := 0 for i = 0; i < N; i++ { client.SendMessage(lmaxapi.MsgEcho, "echo") } err = client.Close() if err != nil { log.Println(err) return } mtf.Close() // log.Println(time.Now().Sub(now), i) }