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/06/19 08:50:47 UTC

[GitHub] [dubbo-getty] wongoo commented on a change in pull request #61: Improve/delte handle loop

wongoo commented on a change in pull request #61:
URL: https://github.com/apache/dubbo-getty/pull/61#discussion_r654769070



##########
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
+var Session getty.Session

Review comment:
       session object should not be global,one session for a client instead

##########
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
+var Session getty.Session
+
+const CronPeriod = 20e9
+const 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),
+			)
+
+			client.RunEventLoop(NewHelloClientSession)
+
+			for j := 0; j < m; j++ {
+				atomic.AddUint64(&trans, 1)
+
+				t := time.Now().UnixNano()
+				msg := buildSendMsg()
+				_, _, err := Session.WritePkg(msg, WritePkgTimeout)
+				if err != nil {
+					log.Printf("Err:session.WritePkg(session{%s}, error{%v}", Session.Stat(), err)
+					Session.Close()

Review comment:
       should it create new session if error happens?

##########
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
+var Session getty.Session
+
+const CronPeriod = 20e9
+const 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),
+			)
+
+			client.RunEventLoop(NewHelloClientSession)
+
+			for j := 0; j < m; j++ {
+				atomic.AddUint64(&trans, 1)
+
+				t := time.Now().UnixNano()
+				msg := buildSendMsg()
+				_, _, err := Session.WritePkg(msg, WritePkgTimeout)
+				if err != nil {
+					log.Printf("Err:session.WritePkg(session{%s}, error{%v}", Session.Stat(), err)
+					Session.Close()
+				}
+
+				atomic.AddUint64(&transOK, 1)
+
+				t = time.Now().UnixNano() - t
+				d[ii] = append(d[ii], t)
+
+				wg.Done()
+			}
+
+			client.Close()
+		}(i)
+	}
+
+	wg.Wait()
+
+	totalT = time.Now().UnixNano() - totalT
+	totalT = totalT / 1000000
+	log.Printf("took %d ms for %d requests", totalT, n*m)
+
+	totalD := make([]int64, 0, n*m)
+	for _, k := range d {
+		totalD = append(totalD, k...)
+	}

Review comment:
       can get totalD2 directly from d




-- 
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.

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