dubbo.apache.org/dubbo-go/v3@v3.1.1/filter/tps_strategy.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  // Package filter defines the functions of a filter.
    19  /*
    20   * please register your implementation by invoking SetTpsLimitStrategy
    21   * "UserProvider":
    22   *   registry: "hangzhouzk"
    23   *   protocol : "dubbo"
    24   *   interface : "com.ikurento.user.UserProvider"
    25   *   ... # other configuration
    26   *   tps.limiter: "method-service" # the name of limiter
    27   *   tps.limit.strategy: "name of implementation" # service-level
    28   *   methods:
    29   *    - name: "GetUser"
    30   *      tps.interval: 3000
    31   *      tps.limit.strategy: "name of implementation" # method-level
    32   */
    33  package filter
    34  
    35  // TpsLimitStrategy is the interface which defines how to do the TPS limiting in method level.
    36  //
    37  // IsAllowable will return true if this invocation is not over limitation.
    38  type TpsLimitStrategy interface {
    39  	IsAllowable() bool
    40  }
    41  
    42  // TpsLimitStrategyCreator is the interface which creates TpsLimitStrategy.
    43  type TpsLimitStrategyCreator interface {
    44  	// Create will create an instance of TpsLimitStrategy
    45  	// It will be a little hard to understand this method.
    46  	// The unit of interval is ms
    47  	// for example, if the limit = 100, interval = 1000
    48  	// which means that the limiter limitation is 100 times per 1000ms (100/1000ms)
    49  	Create(limit int, interval int) TpsLimitStrategy
    50  }