Skip to content

Commit

Permalink
Merge pull request #4 from CheyiLin/master
Browse files Browse the repository at this point in the history
chore: Support go 1.19 and correct the module path
  • Loading branch information
mingchouliao committed Apr 19, 2023
2 parents 03d4f0d + 75ac181 commit 246a9e6
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 1,102 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Distributed rate limiters for Golang
[![Build Status](https://github.com/mennanov/limiters/actions/workflows/tests.yml/badge.svg)](https://github.com/mennanov/limiters/actions/workflows/tests.yml)
# Distributed rate limiters for Golang
[![Build Status](https://github.com/mingchouliao/limiters/actions/workflows/tests.yml/badge.svg)](https://github.com/mingchouliao/limiters/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/mennanov/limiters/branch/master/graph/badge.svg?token=LZULu4i7B6)](https://codecov.io/gh/mennanov/limiters)
[![Go Report Card](https://goreportcard.com/badge/github.com/mennanov/limiters)](https://goreportcard.com/report/github.com/mennanov/limiters)
[![GoDoc](https://godoc.org/github.com/mennanov/limiters?status.svg)](https://godoc.org/github.com/mennanov/limiters)
[![Go Report Card](https://goreportcard.com/badge/github.com/mingchouliao/limiters)](https://goreportcard.com/report/github.com/mingchouliao/limiters)
[![GoDoc](https://godoc.org/github.com/mingchouliao/limiters?status.svg)](https://godoc.org/github.com/mingchouliao/limiters)

Rate limiters for distributed applications in Golang with configurable back-ends and distributed locks.
Any types of back-ends and locks can be used that implement certain minimalistic interfaces.
Most common implementations are already provided.
Rate limiters for distributed applications in Golang with configurable back-ends and distributed locks.
Any types of back-ends and locks can be used that implement certain minimalistic interfaces.
Most common implementations are already provided.

- [`Token bucket`](https://en.wikipedia.org/wiki/Token_bucket)
- in-memory (local)
- redis
- etcd
- dynamodb

Allows requests at a certain input rate with possible bursts configured by the capacity parameter.
The output rate equals to the input rate.
Allows requests at a certain input rate with possible bursts configured by the capacity parameter.
The output rate equals to the input rate.
Precise (no over or under-limiting), but requires a lock (provided).

- [`Leaky bucket`](https://en.wikipedia.org/wiki/Leaky_bucket#As_a_queue)
Expand All @@ -24,34 +24,34 @@ Most common implementations are already provided.
- etcd
- dynamodb

Puts requests in a FIFO queue to be processed at a constant rate.
There are no restrictions on the input rate except for the capacity of the queue.
Puts requests in a FIFO queue to be processed at a constant rate.
There are no restrictions on the input rate except for the capacity of the queue.
Requires a lock (provided).

- [`Fixed window counter`](https://konghq.com/blog/how-to-design-a-scalable-rate-limiting-algorithm/)
- in-memory (local)
- redis
- dynamodb

Simple and resources efficient algorithm that does not need a lock.
Precision may be adjusted by the size of the window.
Simple and resources efficient algorithm that does not need a lock.
Precision may be adjusted by the size of the window.
May be lenient when there are many requests around the boundary between 2 adjacent windows.

- [`Sliding window counter`](https://konghq.com/blog/how-to-design-a-scalable-rate-limiting-algorithm/)
- in-memory (local)
- redis
- dynamodb

Smoothes out the bursts around the boundary between 2 adjacent windows.
Needs as twice more memory as the `Fixed Window` algorithm (2 windows instead of 1 at a time).
Smoothes out the bursts around the boundary between 2 adjacent windows.
Needs as twice more memory as the `Fixed Window` algorithm (2 windows instead of 1 at a time).
It will disallow _all_ the requests in case when a client is flooding the service with requests.
It's the client's responsibility to handle a disallowed request properly: wait before making a new one again.

- `Concurrent buffer`
- in-memory (local)
- redis
Allows concurrent requests up to the given capacity.

Allows concurrent requests up to the given capacity.
Requires a lock (provided).

## gRPC example
Expand Down Expand Up @@ -86,7 +86,7 @@ s := grpc.NewServer(grpc.UnaryInterceptor(
}))
```

For something close to a real world example see the IP address based gRPC global rate limiter in the
For something close to a real world example see the IP address based gRPC global rate limiter in the
[examples](examples/example_grpc_ip_limiter_test.go) directory.

## DynamoDB
Expand All @@ -113,8 +113,8 @@ All DynamoDB backends accept a `DynamoDBTableProperties` struct as a paramater.

## Distributed locks

Some algorithms require a distributed lock to guarantee consistency during concurrent requests.
In case there is only 1 running application instance then no distributed lock is needed
Some algorithms require a distributed lock to guarantee consistency during concurrent requests.
In case there is only 1 running application instance then no distributed lock is needed
as all the algorithms are thread-safe (use `LockNoop`).

Supported backends:
Expand All @@ -128,7 +128,7 @@ Supported backends:
Run tests locally:
```bash
docker-compose up -d # start etcd, Redis, zookeeper, consul, and localstack
ETCD_ENDPOINTS="127.0.0.1:2379" REDIS_ADDR="127.0.0.1:6379" ZOOKEEPER_ENDPOINTS="127.0.0.1" CONSUL_ADDR="127.0.0.1:8500" AWS_ADDR="127.0.0.1:8000" go test -race -v
ETCD_ENDPOINTS="127.0.0.1:2379" REDIS_ADDR="127.0.0.1:6379" ZOOKEEPER_ENDPOINTS="127.0.0.1" CONSUL_ADDR="127.0.0.1:8500" AWS_ADDR="127.0.0.1:8000" go test -race -v
```

Run [Drone](https://drone.io) CI tests locally:
Expand Down
2 changes: 1 addition & 1 deletion concurrent_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/google/uuid"

l "github.com/mennanov/limiters"
l "github.com/mingchouliao/limiters"
)

func (s *LimitersTestSuite) concurrentBuffers(capacity int64, ttl time.Duration, clock l.Clock) []*l.ConcurrentBuffer {
Expand Down
3 changes: 1 addition & 2 deletions dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/mennanov/limiters"
"github.com/mingchouliao/limiters"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -80,7 +80,6 @@ func DeleteTestDynamoDBTable(ctx context.Context, client *dynamodb.Client) error
_, err := client.DeleteTable(ctx, &dynamodb.DeleteTableInput{
TableName: aws.String(testDynamoDBTableName),
})

if err != nil {
return errors.Wrap(err, "delete test dynamodb table failed")
}
Expand Down
4 changes: 2 additions & 2 deletions examples/example_grpc_ip_limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"

"github.com/mennanov/limiters"
pb "github.com/mennanov/limiters/examples/helloworld"
"github.com/mingchouliao/limiters"
pb "github.com/mingchouliao/limiters/examples/helloworld"
)

func Example_ipGRPCLimiter() {
Expand Down
4 changes: 2 additions & 2 deletions examples/example_grpc_simple_limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/mennanov/limiters"
pb "github.com/mennanov/limiters/examples/helloworld"
"github.com/mingchouliao/limiters"
pb "github.com/mingchouliao/limiters/examples/helloworld"
)

func Example_simpleGRPCLimiter() {
Expand Down
3 changes: 2 additions & 1 deletion examples/gprc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package examples

import (
"context"
pb "github.com/mennanov/limiters/examples/helloworld"

pb "github.com/mingchouliao/limiters/examples/helloworld"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions examples/helloworld/helloworld.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";

package helloworld;
option go_package = "github.com/mennanov/limiters/examples/helloworld";
option go_package = "github.com/mingchouliao/limiters/examples/helloworld";

// The greeting service definition.
service Greeter {
Expand All @@ -26,4 +26,4 @@ message GoodbyeRequest {

message GoodbyeReply {
string message = 1;
}
}
2 changes: 1 addition & 1 deletion fixedwindow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/google/uuid"

l "github.com/mennanov/limiters"
l "github.com/mingchouliao/limiters"
)

// fixedWindows returns all the possible FixedWindow combinations.
Expand Down
25 changes: 10 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module github.com/mennanov/limiters
module github.com/mingchouliao/limiters

go 1.17
go 1.19

require (
github.com/aws/aws-sdk-go-v2 v1.17.6
github.com/aws/aws-sdk-go-v2/config v1.18.17
github.com/aws/aws-sdk-go-v2/credentials v1.13.17
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.18
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.1
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redsync/redsync/v4 v4.8.1
github.com/google/uuid v1.3.0
Expand All @@ -19,26 +21,20 @@ require (
google.golang.org/protobuf v1.28.1
)

require (
github.com/aws/aws-sdk-go-v2 v1.17.6
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.24 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.1
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.24 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
)

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.24 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.31 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.14.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.24 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.24 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.6 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
Expand All @@ -47,16 +43,15 @@ require (
github.com/fatih/color v1.14.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand Down
Loading

0 comments on commit 246a9e6

Please sign in to comment.