Skip to content
Snippets Groups Projects
Commit 55dca71a authored by william feng's avatar william feng
Browse files

update the comments for TPS

parent 9e0a04d1
No related branches found
No related tags found
No related merge requests found
......@@ -39,8 +39,8 @@ func init() {
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, creator)
}
// FixedWindowTpsLimitStrategyImpl implements the TPS limit strategy base on requests count during the interval
/**
* FixedWindowTpsLimitStrategyImpl
* 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
......@@ -65,7 +65,8 @@ type FixedWindowTpsLimitStrategyImpl struct {
timestamp int64
}
// IsAllowable ...
// IsAllowable determines if the requests over the TPS limit within the interval.
// It is not thread-safe.
func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
current := time.Now().UnixNano()
......@@ -82,6 +83,7 @@ func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
type fixedWindowStrategyCreator struct{}
// Create returns a FixedWindowTpsLimitStrategyImpl instance with pre-configured limit rate and interval
func (creator *fixedWindowStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
return &FixedWindowTpsLimitStrategyImpl{
rate: int32(rate),
......
......@@ -32,8 +32,8 @@ func init() {
extension.SetTpsLimitStrategy("slidingWindow", &slidingWindowStrategyCreator{})
}
// SlidingWindowTpsLimitStrategyImpl implements a thread-safe TPS limit strategy base on requests count.
/**
* SlidingWindowTpsLimitStrategyImpl
* it's thread-safe.
* "UserProvider":
* registry: "hangzhouzk"
......@@ -54,7 +54,8 @@ type SlidingWindowTpsLimitStrategyImpl struct {
queue *list.List
}
// IsAllowable ...
// IsAllowable determins whether the number of requests within the time window overs the threshold
// It is thread-safe.
func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool {
impl.mutex.Lock()
defer impl.mutex.Unlock()
......@@ -84,6 +85,7 @@ func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool {
type slidingWindowStrategyCreator struct{}
// Create returns SlidingWindowTpsLimitStrategyImpl instance with configured limit rate and interval
func (creator *slidingWindowStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
return &SlidingWindowTpsLimitStrategyImpl{
rate: rate,
......
......@@ -32,10 +32,9 @@ func init() {
})
}
// ThreadSafeFixedWindowTpsLimitStrategyImpl is the thread-safe implementation.
// It's also a thread-safe decorator of FixedWindowTpsLimitStrategyImpl
/**
* ThreadSafeFixedWindowTpsLimitStrategyImpl
* it's the thread-safe implementation.
* Also, it's a thread-safe decorator of FixedWindowTpsLimitStrategyImpl
* "UserProvider":
* registry: "hangzhouzk"
* protocol : "dubbo"
......@@ -53,7 +52,7 @@ type ThreadSafeFixedWindowTpsLimitStrategyImpl struct {
fixedWindow *FixedWindowTpsLimitStrategyImpl
}
// IsAllowable ...
// IsAllowable implements thread-safe then run the FixedWindowTpsLimitStrategy
func (impl *ThreadSafeFixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
impl.mutex.Lock()
defer impl.mutex.Unlock()
......@@ -64,6 +63,7 @@ type threadSafeFixedWindowStrategyCreator struct {
fixedWindowStrategyCreator *fixedWindowStrategyCreator
}
// Create returns ThreadSafeFixedWindowTpsLimitStrategyImpl instance
func (creator *threadSafeFixedWindowStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
fixedWindowStrategy := creator.fixedWindowStrategyCreator.Create(rate, interval).(*FixedWindowTpsLimitStrategyImpl)
return &ThreadSafeFixedWindowTpsLimitStrategyImpl{
......
......@@ -44,9 +44,8 @@ func init() {
extension.SetTpsLimiter(name, GetMethodServiceTpsLimiter)
}
// MethodServiceTpsLimiterImpl allows developer to config both method-level and service-level tps limiter.
/**
* MethodServiceTpsLimiterImpl
* This implementation allows developer to config both method-level and service-level tps limiter.
* for example:
* "UserProvider":
* registry: "hangzhouzk"
......
......@@ -39,8 +39,8 @@ func init() {
extension.SetFilter(TpsLimitFilterKey, GetTpsLimitFilter)
}
// TpsLimitFilter filters the requests by TPS
/**
* TpsLimitFilter
* if you wish to use the TpsLimiter, please add the configuration into your service provider configuration:
* for example:
* "UserProvider":
......@@ -56,7 +56,7 @@ func init() {
type TpsLimitFilter struct {
}
// Invoke ...
// Invoke gets the configured limter to impose TPS limiting
func (t TpsLimitFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
url := invoker.GetUrl()
tpsLimiter := url.GetParam(constant.TPS_LIMITER_KEY, "")
......@@ -72,13 +72,13 @@ func (t TpsLimitFilter) Invoke(ctx context.Context, invoker protocol.Invoker, in
return invoker.Invoke(ctx, invocation)
}
// OnResponse ...
// OnResponse dummy process, return the result directly
func (t TpsLimitFilter) OnResponse(_ context.Context, result protocol.Result, _ protocol.Invoker,
_ protocol.Invocation) protocol.Result {
return result
}
// GetTpsLimitFilter ...
// GetTpsLimitFilter returns an TpsLimitFilter instance.
func GetTpsLimitFilter() filter.Filter {
return &TpsLimitFilter{}
}
......@@ -17,7 +17,7 @@
package filter
// TpsLimitStrategy ...
// TpsLimitStrategy defines how to do the TPS limiting in method level.
/*
* please register your implementation by invoking SetTpsLimitStrategy
* "UserProvider":
......@@ -37,7 +37,7 @@ type TpsLimitStrategy interface {
IsAllowable() bool
}
// TpsLimitStrategyCreator, the creator abstraction for TpsLimitStrategy
// TpsLimitStrategyCreator is the creator abstraction for TpsLimitStrategy
type TpsLimitStrategyCreator interface {
// Create will create an instance of TpsLimitStrategy
// It will be a little hard to understand this method.
......
......@@ -22,8 +22,8 @@ import (
"github.com/apache/dubbo-go/protocol"
)
// TpsLimiter defines the Limiter that judge if the TPS overs the threshold
/*
* TpsLimiter
* please register your implementation by invoking SetTpsLimiter
* The usage, for example:
* "UserProvider":
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment