marsevilspirit commented on code in PR #3086:
URL: https://github.com/apache/dubbo-go/pull/3086#discussion_r2570660655
##########
protocol/triple/client.go:
##########
@@ -304,19 +336,21 @@ func newClientManager(url *common.URL) (*clientManager,
error) {
serviceType := reflect.TypeOf(service)
for i := range serviceType.NumMethod() {
- methodName := serviceType.Method(i).Name
Review Comment:
Keep methodName. Don‘t change.
##########
protocol/triple/client_pool.go:
##########
@@ -0,0 +1,281 @@
+/*
+ * 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 triple
+
+import (
+ "errors"
+ "sync"
+ "time"
+)
+
+import (
+ tri "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
+)
+
+type ClientPool interface {
+ Get(timeout time.Duration) (*tri.Client, error)
+ Put(client *tri.Client)
+ Close()
+
+ MaxSize() int
+ Closed() bool
+}
+
+var (
+ ErrTriClientPoolClosed = errors.New("tri client pool is closed")
+ ErrTriClientPoolTimeout = errors.New("tri client pool get
timeout")
+ ErrTriClientPoolCloseWhenEmpty = errors.New("empty tri client pool
close")
+)
+
+const (
+ autoScalerPeriod = 700 * time.Millisecond // autoScaler interval
+ maxExpandPerCycle = 16 // maximum number of
clients to expand per cycle
+ lowIdleThresholdDivisor = 5 // consider clients
insufficient if idle < curSize/5
+ highIdleStreakLimit = 10 // consecutive high
idle count to trigger shrinking
+)
+
+type TriClientPool struct {
+ clients chan *tri.Client
+ factory func() *tri.Client
+ mu sync.Mutex
+ maxSize int
+ curSize int
+ closed bool
+ getTimeouts int // recent timeout count, used to trigger expansion
+
+ fallback *tri.Client
+}
+
+func NewTriClientPool(maxSize int, factory func() *tri.Client) *TriClientPool {
+ pool := &TriClientPool{
+ clients: make(chan *tri.Client, maxSize),
+ factory: factory,
+ maxSize: maxSize,
+ }
+ go pool.autoScaler()
Review Comment:
Don’t create a new go routine. Check the idle client when get. If it‘s not
enough, expand the capacity.
##########
protocol/triple/client.go:
##########
@@ -282,16 +312,18 @@ func newClientManager(url *common.URL) (*clientManager,
error) {
baseTriURL = httpPrefix + baseTriURL
}
- triClients := make(map[string]*tri.Client)
+ triPools := make(map[string]*TriClientPool)
Review Comment:
change to clientPool or triClientPool
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]