Alanxtl commented on code in PR #3086: URL: https://github.com/apache/dubbo-go/pull/3086#discussion_r2587276447
########## protocol/triple/client_pool.go: ########## @@ -0,0 +1,296 @@ +/* + * 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 // minimum period that autoScaler expand or shrink + maxExpandPerCycle = 16 // maximum number of clients to expand per cycle + highIdleStreakLimit = 10 // consecutive high idle count to trigger shrinking + lowIdleThreshold = 0.2 // treat pool as busy if idle clients < 20% of total + idleShrinkThreshold = 0.6 // shrink counter increases when idle ratio > 60% + shrinkRatio = 0.125 // shrink by 12.5% of current size when threshold is reached +) Review Comment: same ########## protocol/triple/client.go: ########## @@ -51,6 +51,10 @@ import ( const ( httpPrefix string = "http://" httpsPrefix string = "https://" + // triClientPoolMaxSize is the maximum number of tri.Client instances per method in the pool. + triClientPoolMaxSize = 32 + // defaultClientGetTimeout is the timeout for getting a tri.Client from the TriClientPool. + defaultClientGetTimeout = 50 * time.Millisecond Review Comment: put these in `common/constant` and import here -- 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]
