limiter

package
v3.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package filter is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMethodServiceTpsLimiter

func GetMethodServiceTpsLimiter() filter.TpsLimiter

GetMethodServiceTpsLimiter will return an MethodServiceTpsLimiter instance.

Types

type MethodServiceTpsLimiter

type MethodServiceTpsLimiter struct {
	// contains filtered or unexported fields
}

MethodServiceTpsLimiter allows developer to config both method-level and service-level tps limiter. *

  • for example:
  • "UserProvider":
  • registry: "hangzhouzk"
  • protocol : "dubbo"
  • interface : "com.ikurento.user.UserProvider"
  • ... # other configuration
  • tps.limiter: "method-service" or "default" # the name of MethodServiceTpsLimiter. It's the default limiter too.
  • tps.limit.interval: 5000 # interval, the time unit is ms
  • tps.limit.rate: 300 # the max value in the interval. <0 means that the service will not be limited.
  • methods:
  • - name: "GetUser"
  • tps.interval: 3000
  • tps.limit.rate: 20, # in this case, this configuration in service-level will be ignored.
  • - name: "UpdateUser"
  • tps.limit.rate: -1, # If the rate<0, the method will be ignored * *
  • More examples:
  • case1:
  • "UserProvider":
  • registry: "hangzhouzk"
  • protocol : "dubbo"
  • interface : "com.ikurento.user.UserProvider"
  • ... # other configuration
  • tps.limiter: "method-service" or "default" # the name of MethodServiceTpsLimiter. It's the default limiter too.
  • tps.limit.interval: 5000 # interval, the time unit is ms
  • tps.limit.rate: 300 # the max value in the interval. <0 means that the service will not be limited.
  • methods:
  • - name: "GetUser"
  • - name: "UpdateUser"
  • tps.limit.rate: -1,
  • in this case, the method UpdateUser will be ignored,
  • which means that only GetUser will be limited by service-level configuration. *
  • case2:
  • "UserProvider":
  • registry: "hangzhouzk"
  • protocol : "dubbo"
  • interface : "com.ikurento.user.UserProvider"
  • ... # other configuration
  • tps.limiter: "method-service" or "default" # the name of MethodServiceTpsLimiter. It's the default limiter too.
  • tps.limit.interval: 5000 # interval, the time unit is ms
  • tps.limit.rate: 300 # the max value in the interval. <0 means that the service will not be limited.
  • methods:
  • - name: "GetUser"
  • - name: "UpdateUser"
  • tps.limit.rate: 30,
  • In this case, the GetUser will be limited by service-level configuration(300 times in 5000ms),
  • but UpdateUser will be limited by its configuration (30 times in 60000ms) *
  • case3:
  • "UserProvider":
  • registry: "hangzhouzk"
  • protocol : "dubbo"
  • interface : "com.ikurento.user.UserProvider"
  • ... # other configuration
  • tps.limiter: "method-service" or "default" # the name of MethodServiceTpsLimiter. It's the default limiter too.
  • methods:
  • - name: "GetUser"
  • - name: "UpdateUser"
  • tps.limit.rate: 70,
  • tps.limit.interval: 40000
  • In this case, only UpdateUser will be limited by its configuration (70 times in 40000ms)

func (MethodServiceTpsLimiter) IsAllowable

func (limiter MethodServiceTpsLimiter) IsAllowable(url *common.URL, invocation protocol.Invocation) bool

IsAllowable based on method-level and service-level. The method-level has high priority which means that if there is any rate limit configuration for the method, the service-level rate limit strategy will be ignored. The key point is how to keep thread-safe This implementation use concurrent map + loadOrStore to make implementation thread-safe You can image that even multiple threads create limiter, but only one could store the limiter into tpsState

type MockTpsLimiter

type MockTpsLimiter struct {
	// contains filtered or unexported fields
}

MockTpsLimiter is a mock of TpsLimiter interface

func NewMockTpsLimiter

func NewMockTpsLimiter(ctrl *gomock.Controller) *MockTpsLimiter

NewMockTpsLimiter creates a new mock instance

func (*MockTpsLimiter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockTpsLimiter) IsAllowable

func (m *MockTpsLimiter) IsAllowable(arg0 *common.URL, arg1 protocol.Invocation) bool

IsAllowable mocks base method

type MockTpsLimiterMockRecorder

type MockTpsLimiterMockRecorder struct {
	// contains filtered or unexported fields
}

MockTpsLimiterMockRecorder is the mock recorder for MockTpsLimiter

func (*MockTpsLimiterMockRecorder) IsAllowable

func (mr *MockTpsLimiterMockRecorder) IsAllowable(arg0, arg1 interface{}) *gomock.Call

IsAllowable indicates an expected call of IsAllowable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL