Documentation ¶
Overview ¶
Package filter is a generated GoMock package.
Package filter is a generated GoMock package.
Index ¶
- Constants
- func GetMethodServiceTpsLimiter() filter.TpsLimiter
- type FixedWindowTpsLimitStrategyImpl
- type MethodServiceTpsLimiterImpl
- type MockTpsLimitStrategy
- type MockTpsLimitStrategyMockRecorder
- type MockTpsLimiter
- type MockTpsLimiterMockRecorder
- type SlidingWindowTpsLimitStrategyImpl
- type ThreadSafeFixedWindowTpsLimitStrategyImpl
Constants ¶
const (
// FixedWindowKey defines tps limit algorithm
FixedWindowKey = "fixedWindow"
)
Variables ¶
This section is empty.
Functions ¶
func GetMethodServiceTpsLimiter ¶
func GetMethodServiceTpsLimiter() filter.TpsLimiter
GetMethodServiceTpsLimiter will return an MethodServiceTpsLimiterImpl instance.
Types ¶
type FixedWindowTpsLimitStrategyImpl ¶
type FixedWindowTpsLimitStrategyImpl struct {
// contains filtered or unexported fields
}
FixedWindowTpsLimitStrategyImpl implements the TPS limit strategy base on requests count during the interval *
- It's the same as default implementation in Java
- It's not a thread-safe implementation.
- It you want to use the thread-safe implementation, please use ThreadSafeFixedWindowTpsLimitStrategyImpl
- This is the default implementation. *
- "UserProvider":
- registry: "hangzhouzk"
- protocol : "dubbo"
- interface : "com.ikurento.user.UserProvider"
- ... # other configuration
- tps.limiter: "method-service" # the name of limiter
- tps.limit.strategy: "default" or "fixedWindow" # service-level
- methods:
- - name: "GetUser"
- tps.interval: 3000
- tps.limit.strategy: "default" or "fixedWindow" # method-level
func (*FixedWindowTpsLimitStrategyImpl) IsAllowable ¶
func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool
IsAllowable determines if the requests over the TPS limit within the interval. It is not thread-safe.
type MethodServiceTpsLimiterImpl ¶
type MethodServiceTpsLimiterImpl struct {
// contains filtered or unexported fields
}
MethodServiceTpsLimiterImpl 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 MethodServiceTpsLimiterImpl. 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 MethodServiceTpsLimiterImpl. 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 MethodServiceTpsLimiterImpl. 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 MethodServiceTpsLimiterImpl. 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 (MethodServiceTpsLimiterImpl) IsAllowable ¶
func (limiter MethodServiceTpsLimiterImpl) 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 MockTpsLimitStrategy ¶
type MockTpsLimitStrategy struct {
// contains filtered or unexported fields
}
MockTpsLimitStrategy is a mock of TpsLimitStrategy interface
func NewMockTpsLimitStrategy ¶
func NewMockTpsLimitStrategy(ctrl *gomock.Controller) *MockTpsLimitStrategy
NewMockTpsLimitStrategy creates a new mock instance
func (*MockTpsLimitStrategy) EXPECT ¶
func (m *MockTpsLimitStrategy) EXPECT() *MockTpsLimitStrategyMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockTpsLimitStrategy) IsAllowable ¶
func (m *MockTpsLimitStrategy) IsAllowable() bool
IsAllowable mocks base method
type MockTpsLimitStrategyMockRecorder ¶
type MockTpsLimitStrategyMockRecorder struct {
// contains filtered or unexported fields
}
MockTpsLimitStrategyMockRecorder is the mock recorder for MockTpsLimitStrategy
func (*MockTpsLimitStrategyMockRecorder) IsAllowable ¶
func (mr *MockTpsLimitStrategyMockRecorder) IsAllowable() *gomock.Call
IsAllowable indicates an expected call of IsAllowable
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 ¶
func (m *MockTpsLimiter) EXPECT() *MockTpsLimiterMockRecorder
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
type SlidingWindowTpsLimitStrategyImpl ¶
type SlidingWindowTpsLimitStrategyImpl struct {
// contains filtered or unexported fields
}
SlidingWindowTpsLimitStrategyImpl implements a thread-safe TPS limit strategy base on requests count. *
- it's thread-safe.
- "UserProvider":
- registry: "hangzhouzk"
- protocol : "dubbo"
- interface : "com.ikurento.user.UserProvider"
- ... # other configuration
- tps.limiter: "method-service" # the name of limiter
- tps.limit.strategy: "slidingWindow" # service-level
- methods:
- - name: "GetUser"
- tps.interval: 3000
- tps.limit.strategy: "slidingWindow" # method-level
func (*SlidingWindowTpsLimitStrategyImpl) IsAllowable ¶
func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool
IsAllowable determines whether the number of requests within the time window overs the threshold It is thread-safe.
type ThreadSafeFixedWindowTpsLimitStrategyImpl ¶
type ThreadSafeFixedWindowTpsLimitStrategyImpl struct {
// contains filtered or unexported fields
}
ThreadSafeFixedWindowTpsLimitStrategyImpl is the thread-safe implementation. It's also a thread-safe decorator of FixedWindowTpsLimitStrategyImpl *
- "UserProvider":
- registry: "hangzhouzk"
- protocol : "dubbo"
- interface : "com.ikurento.user.UserProvider"
- ... # other configuration
- tps.limiter: "method-service" # the name of limiter
- tps.limit.strategy: "threadSafeFixedWindow" # service-level
- methods:
- - name: "GetUser"
- tps.interval: 3000
- tps.limit.strategy: "threadSafeFixedWindow" # method-level
func (*ThreadSafeFixedWindowTpsLimitStrategyImpl) IsAllowable ¶
func (impl *ThreadSafeFixedWindowTpsLimitStrategyImpl) IsAllowable() bool
IsAllowable implements thread-safe then run the FixedWindowTpsLimitStrategy