Documentation
¶
Index ¶
- type ConcurrentLimiter
- func (l *ConcurrentLimiter) Acquire(ctx context.Context) (err error)
- func (l *ConcurrentLimiter) ConcurrentRequests() int
- func (l *ConcurrentLimiter) Handler(ctx context.Context, request []byte, next core.NextIOHandler) (response []byte, err error)
- func (l *ConcurrentLimiter) MaxConcurrentRequests() int
- func (l *ConcurrentLimiter) Release()
- func (l *ConcurrentLimiter) Timeout() time.Duration
- type Option
- type RateLimiter
- func (l *RateLimiter) Acquire(ctx context.Context, tokens int) (err error)
- func (l *RateLimiter) IOHandler(ctx context.Context, request []byte, next core.NextIOHandler) (response []byte, err error)
- func (l *RateLimiter) InvokeHandler(ctx context.Context, name string, args []interface{}, ...) (result []interface{}, err error)
- func (l *RateLimiter) MaxPermits() float64
- func (l *RateLimiter) PermitsPerSecond() int64
- func (l *RateLimiter) Timeout() time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentLimiter ¶
type ConcurrentLimiter struct {
// contains filtered or unexported fields
}
ConcurrentLimiter plugin for hprose.
func NewConcurrentLimiter ¶
func NewConcurrentLimiter(maxConcurrentRequests int, timeout ...time.Duration) *ConcurrentLimiter
NewConcurrentLimiter returns a ConcurrentLimiter instance.
func (*ConcurrentLimiter) Acquire ¶
func (l *ConcurrentLimiter) Acquire(ctx context.Context) (err error)
Acquire returns immediately when the concurrentRequests is less than or equal to maxConcurrentRequests, otherwise it will block until timeout or any request are completed.
func (*ConcurrentLimiter) ConcurrentRequests ¶
func (l *ConcurrentLimiter) ConcurrentRequests() int
ConcurrentRequests property of ConcurrentLimiter.
func (*ConcurrentLimiter) Handler ¶
func (l *ConcurrentLimiter) Handler(ctx context.Context, request []byte, next core.NextIOHandler) (response []byte, err error)
Handler for ConcurrentLimiter.
func (*ConcurrentLimiter) MaxConcurrentRequests ¶
func (l *ConcurrentLimiter) MaxConcurrentRequests() int
MaxConcurrentRequests property of ConcurrentLimiter.
func (*ConcurrentLimiter) Release ¶
func (l *ConcurrentLimiter) Release()
Release reqeust task queue.
func (*ConcurrentLimiter) Timeout ¶
func (l *ConcurrentLimiter) Timeout() time.Duration
Timeout property of ConcurrentLimiter.
type Option ¶
type Option func(*RateLimiter)
Option for RateLimiter.
func WithMaxPermits ¶
WithMaxPermits returns a maxPermits Option for RateLimiter.
func WithTimeout ¶
WithTimeout returns a timeout Option for RateLimiter.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter plugin for hprose.
func NewRateLimiter ¶
func NewRateLimiter(permitsPerSecond int64, options ...Option) *RateLimiter
NewRateLimiter returns a RateLimiter instance.
func (*RateLimiter) Acquire ¶
func (l *RateLimiter) Acquire(ctx context.Context, tokens int) (err error)
Acquire is the core algorithm of RateLimiter.
func (*RateLimiter) IOHandler ¶
func (l *RateLimiter) IOHandler(ctx context.Context, request []byte, next core.NextIOHandler) (response []byte, err error)
IOHandler for RateLimiter.
func (*RateLimiter) InvokeHandler ¶
func (l *RateLimiter) InvokeHandler(ctx context.Context, name string, args []interface{}, next core.NextInvokeHandler) (result []interface{}, err error)
InvokeHandler for RateLimiter.
func (*RateLimiter) MaxPermits ¶
func (l *RateLimiter) MaxPermits() float64
MaxPermits property of RateLimiter.
func (*RateLimiter) PermitsPerSecond ¶
func (l *RateLimiter) PermitsPerSecond() int64
PermitsPerSecond property of RateLimiter.
func (*RateLimiter) Timeout ¶
func (l *RateLimiter) Timeout() time.Duration
Timeout property of RateLimiter.