You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/05 06:50:20 UTC

[GitHub] [dubbo-getty] pantianying commented on a change in pull request #56: Ftr: delete session.handleLoop

pantianying commented on a change in pull request #56:
URL: https://github.com/apache/dubbo-getty/pull/56#discussion_r663665395



##########
File path: benchmark/client/main.go
##########
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+	"encoding/binary"
+	"errors"
+	"flag"
+	"fmt"
+	"log"
+	"net"
+	"sync"
+	"sync/atomic"
+	"time"
+)
+
+import (
+	"github.com/apache/dubbo-getty"
+	"github.com/dubbogo/gost/sync"
+	"github.com/montanaflynn/stats"
+)
+
+var (
+	concurrency = flag.Int("c", 1, "concurrency")
+	total       = flag.Int("n", 1, "total requests for all clients")
+	ip          = flag.String("ip", "127.0.0.1:8090", "server IP")
+	connections = flag.Int("conn", 1, "number of tcp connections")
+
+	taskPoolMode = flag.Bool("taskPool", false, "task pool mode")
+	taskPoolSize = flag.Int("task_pool_size", 2000, "task poll size")
+	pprofPort    = flag.Int("pprof_port", 65431, "pprof http port")
+)
+
+var taskPool gxsync.GenericTaskPool
+
+const (
+	CronPeriod      = 20e9
+	WritePkgTimeout = 1e8
+)
+
+func main() {
+	flag.Parse()
+
+	n := *concurrency
+	m := *total / n
+
+	log.Printf("Servers: %+v\n\n", *ip)
+	log.Printf("concurrency: %d\nrequests per client: %d\n\n", n, m)
+
+	var wg sync.WaitGroup
+	wg.Add(n * m)
+
+	d := make([][]int64, n, n)
+	var trans uint64
+	var transOK uint64
+
+	totalT := time.Now().UnixNano()
+	for i := 0; i < n; i++ {
+		dt := make([]int64, 0, m)
+		d = append(d, dt)
+
+		go func(ii int) {
+			client := getty.NewTCPClient(
+				getty.WithServerAddress(*ip),
+				getty.WithConnectionNumber(*connections),
+				getty.WithClientTaskPool(taskPool),
+			)
+
+			var tmpSession getty.Session
+			NewHelloClientSession := func(session getty.Session) (err error) {
+				pkgHandler := &PackageHandler{}
+				EventListener := &MessageHandler{}
+
+				EventListener.SessionOnOpen = func(session getty.Session) {
+					tmpSession = session
+				}
+
+				tcpConn, ok := session.Conn().(*net.TCPConn)
+				if !ok {
+					panic(fmt.Sprintf("newSession: %s, session.conn{%#v} is not tcp connection", session.Stat(), session.Conn()))
+				}
+
+				if err = tcpConn.SetNoDelay(true); err != nil {
+					return err
+				}
+				if err = tcpConn.SetKeepAlive(true); err != nil {
+					return err
+				}
+				if err = tcpConn.SetKeepAlivePeriod(10 * time.Second); err != nil {
+					return err
+				}
+				if err = tcpConn.SetReadBuffer(262144); err != nil {
+					return err
+				}
+				if err = tcpConn.SetWriteBuffer(524288); err != nil {
+					return err
+				}
+
+				session.SetName("hello")
+				session.SetMaxMsgLen(128 * 1024) // max message package length is 128k
+				session.SetReadTimeout(time.Second)
+				session.SetWriteTimeout(5 * time.Second)
+				session.SetCronPeriod(int(CronPeriod / 1e6))
+				session.SetWaitTime(time.Second)
+
+				session.SetPkgHandler(pkgHandler)
+				session.SetEventListener(EventListener)
+				return nil
+			}
+
+			client.RunEventLoop(NewHelloClientSession)
+
+			for j := 0; j < m; j++ {
+				atomic.AddUint64(&trans, 1)
+
+				t := time.Now().UnixNano()
+				msg := buildSendMsg()
+				_, _, err := tmpSession.WritePkg(msg, WritePkgTimeout)
+				if err != nil {
+					log.Printf("Err:session.WritePkg(session{%s}, error{%v}", tmpSession.Stat(), err)
+				}
+
+				atomic.AddUint64(&transOK, 1)

Review comment:
       atomic.AddUint64(&transOK, 1) should on err==nil




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org