func BenchmarkRemotingServer(t *testing.B) { //初始化存储 var kiteClient *client.KiteQClient var kiteQServer *KiteQServer var c int32 = 0 var lc int32 = 0 rc := turbo.NewRemotingConfig( "remoting-localhost:13800", 2000, 16*1024, 16*1024, 10000, 10000, 10*time.Second, 160000) kc := NewKiteQConfig("kiteq-localhost:13800", "localhost:13800", "localhost:2181", true, 1*time.Second, 10, 1*time.Minute, []string{"trade"}, "memory://", rc) kiteQServer = NewKiteQServer(kc) kiteQServer.Start() log.Println("KiteQServer START....") kiteClient = client.NewKiteQClient("localhost:2181", "s-trade-a", "123456", &defualtListener{}) kiteClient.SetTopics([]string{"trade"}) kiteClient.SetBindings([]*binding.Binding{ binding.Bind_Direct("s-trade-a", "trade", "pay-succ", 1000, true), }) kiteClient.Start() go func() { for { time.Sleep(1 * time.Second) log.Printf("%d\n", (c - lc)) lc = c } }() t.SetParallelism(4) t.RunParallel(func(pb *testing.PB) { for pb.Next() { err := kiteClient.SendStringMessage(buildStringMessage("1")) if nil != err { t.Logf("SEND MESSAGE |FAIL|%s\n", err) } } }) kiteClient.Destory() kiteQServer.Shutdown() }
func main() { logxml := flag.String("logxml", "../log/log_consumer.xml", "-logxml=../log/log_consumer.xml") zkhost := flag.String("zkhost", "localhost:2181", "-zkhost=localhost:2181") flag.Parse() runtime.GOMAXPROCS(8) log.LoadConfiguration(*logxml) go func() { log.Info(http.ListenAndServe(":38000", nil)) }() lis := &defualtListener{} go lis.monitor() kite := client.NewKiteQClient(*zkhost, "s-mts-test", "123456", lis) kite.SetBindings([]*binding.Binding{ binding.Bind_Direct("s-mts-test", "relation", "pay-succ", 1000, true), }) kite.Start() var s = make(chan os.Signal, 1) signal.Notify(s, syscall.SIGKILL, syscall.SIGUSR1) //是否收到kill的命令 for { cmd := <-s if cmd == syscall.SIGKILL { break } else if cmd == syscall.SIGUSR1 { //如果为siguser1则进行dump内存 unixtime := time.Now().Unix() path := "./heapdump-consumer" + fmt.Sprintf("%d", unixtime) f, err := os.Create(path) if nil != err { continue } else { debug.WriteHeapDump(f.Fd()) } } } kite.Destory() }
func main() { logxml := flag.String("logxml", "./log/log_producer.xml", "-logxml=./log/log_producer.xml") k := flag.Int("k", 1, "-k=1 //kiteclient num ") c := flag.Int("c", 1, "-c=100") tx := flag.Bool("tx", false, "-tx=true send Tx Message") zkhost := flag.String("zkhost", "localhost:2181", "-zkhost=localhost:2181") flag.Parse() runtime.GOMAXPROCS(8) log.LoadConfiguration(*logxml) go func() { log.Info(http.ListenAndServe(":28000", nil)) }() count := int32(0) lc := int32(0) fc := int32(0) flc := int32(0) go func() { for { tmp := count ftmp := fc time.Sleep(1 * time.Second) fmt.Printf("tps:%d/%d\n", (tmp - lc), (ftmp - flc)) lc = tmp flc = ftmp } }() wg := &sync.WaitGroup{} stop := false clients := make([]*client.KiteQClient, 0, *k) for j := 0; j < *k; j++ { kiteClient := client.NewKiteQClient(*zkhost, "pb-mts-test", "123456", &defualtListener{}) kiteClient.SetTopics([]string{"trade"}) kiteClient.Start() clients = append(clients, kiteClient) time.Sleep(3 * time.Second) fmt.Printf("Open Client %d\n", j) for i := 0; i < *c; i++ { go func(kite *client.KiteQClient) { wg.Add(1) for !stop { if *tx { msg := buildBytesMessage(false) err := kite.SendTxBytesMessage(msg, doTranscation) if nil != err { fmt.Printf("SEND TxMESSAGE |FAIL|%s\n", err) atomic.AddInt32(&fc, 1) } else { atomic.AddInt32(&count, 1) } } else { txmsg := buildBytesMessage(true) err := kite.SendBytesMessage(txmsg) if nil != err { // fmt.Printf("SEND MESSAGE |FAIL|%s\n", err) atomic.AddInt32(&fc, 1) } else { atomic.AddInt32(&count, 1) } } } wg.Done() }(kiteClient) } time.Sleep(10 * time.Second) } var s = make(chan os.Signal, 1) signal.Notify(s, syscall.SIGKILL, syscall.SIGUSR1) //是否收到kill的命令 for { cmd := <-s if cmd == syscall.SIGKILL { break } else if cmd == syscall.SIGUSR1 { //如果为siguser1则进行dump内存 unixtime := time.Now().Unix() path := "./heapdump-producer" + fmt.Sprintf("%d", unixtime) f, err := os.Create(path) if nil != err { continue } else { debug.WriteHeapDump(f.Fd()) } } } wg.Wait() for _, k := range clients { k.Destory() } }
func TestRemotingServer(t *testing.T) { //初始化存储 var kiteClient *client.KiteQClient var kiteQServer *KiteQServer var c int32 = 0 var lc int32 = 0 rc := turbo.NewRemotingConfig( "remoting-localhost:13800", 2000, 16*1024, 16*1024, 10000, 10000, 10*time.Second, 160000) kc := NewKiteQConfig("kiteq-localhost:13800", "localhost:13800", "localhost:2181", true, 1*time.Second, 10, 1*time.Minute, []string{"trade"}, "memory://", rc) kiteQServer = NewKiteQServer(kc) kiteQServer.Start() log.Println("KiteQServer START....") kiteClient = client.NewKiteQClient("localhost:2181", "s-trade-a", "123456", &defualtListener{}) kiteClient.SetTopics([]string{"trade"}) kiteClient.SetBindings([]*binding.Binding{ binding.Bind_Direct("s-trade-a", "trade", "pay-succ", 1000, true), }) kiteClient.Start() go func() { for { time.Sleep(1 * time.Second) log.Printf("%d\n", (c - lc)) lc = c } }() err := kiteClient.SendStringMessage(buildStringMessage("1")) if nil != err { t.Logf("SEND MESSAGE |FAIL|%s\n", err) t.Fail() } err = kiteClient.SendStringMessage(buildStringMessage("2")) if nil != err { t.Logf("SEND MESSAGE |FAIL|%s\n", err) t.Fail() } err = kiteClient.SendStringMessage(buildStringMessage("3")) if nil != err { t.Logf("SEND MESSAGE |FAIL|%s\n", err) t.Fail() } msg := buildStringMessage("4") msg.GetHeader().Commit = proto.Bool(false) err = kiteClient.SendStringMessage(msg) if nil != err { t.Logf("SEND MESSAGE |FAIL|%s\n", err) t.Fail() } time.Sleep(10 * time.Second) kiteClient.Destory() kiteQServer.Shutdown() }